# This patch file was generated by NetBeans IDE
# This patch can be applied using context Tools: Apply Diff Patch action on respective folder.
# It uses platform neutral UTF-8 encoding.
# Above lines and this line are ignored by the patching process.
Index: moodle/lang/en_utf8/assignment.php
--- moodle/lang/en_utf8/assignment.php Base (1.14.2.11)
+++ moodle/lang/en_utf8/assignment.php Locally Modified (Based On 1.14.2.11)
@@ -135,6 +135,7 @@
 $string['uploadnofilefound'] = 'No file was found - are you sure you selected one to upload?';
 $string['uploadnotregistered'] = '\'$a\' was uploaded OK but submission did not register!';
 $string['uploadsuccess'] = 'Uploaded \'$a\' successfully';
+$string['usernosubmit'] = 'Sorry, you are not allowed to submit an assignment.';
 $string['viewfeedback'] = 'View assignment grades and feedback';
 $string['viewsubmissions'] = 'View $a submitted assignments';
 $string['yoursubmission'] = 'Your submission';
Index: moodle/mod/assignment/lib.php
--- moodle/mod/assignment/lib.php Base (1.277.2.58)
+++ moodle/mod/assignment/lib.php Locally Modified (Based On 1.277.2.58)
@@ -209,15 +209,20 @@
         global $USER, $CFG;
         require_once($CFG->libdir.'/gradelib.php');
 
-        if (!has_capability('mod/assignment:submit', $this->context, $USER->id, false)) {
+        if (!$submission) { /// Get submission for this assignment
+            $submission = $this->get_submission($USER->id, false);
+        }
+
+        // Check the user can submit
+        $cansubmit = has_capability('mod/assignment:submit', $this->context, $USER->id, false);
+        // If not then check if ther user still has the view cap and has a previous submission
+        $cansubmit = $cansubmit || (!empty($submission) && has_capability('mod/assignment:view', $this->context, $USER->id, false));
+
+        if (!$cansubmit) {
             // can not submit assignments -> no feedback
             return;
         }
 
-        if (!$submission) { /// Get submission for this assignment
-            $submission = $this->get_submission($USER->id);
-        }
-
         $grading_info = grade_get_grades($this->course->id, 'mod', 'assignment', $this->assignment->id, $USER->id);
         $item = $grading_info->items[0];
         $grade = $item->grades[$USER->id];
@@ -809,16 +814,18 @@
         /// Get all ppl that can submit assignments
 
         $currentgroup = groups_get_activity_group($cm);
-        if ($users = get_users_by_capability($context, 'mod/assignment:submit', 'u.id', '', '', '', $currentgroup, '', false)) {
-            $users = array_keys($users);
-        }
 
+        $gradebookroles = explode(",", $CFG->gradebookroles);
+        $users = get_role_users($gradebookroles, $context, true);
+        if ($users) {
+            $users = array_keys($users);
         // if groupmembersonly used, remove users who are not in any group
-        if ($users and !empty($CFG->enablegroupings) and $cm->groupmembersonly) {
+            if (!empty($CFG->enablegroupings) and $cm->groupmembersonly) {
             if ($groupingusers = groups_get_grouping_members($cm->groupingid, 'u.id', 'u.id')) {
                 $users = array_intersect($users, array_keys($groupingusers));
             }
         }
+        }
 
         $nextid = 0;
 
@@ -1067,17 +1074,17 @@
         $currentgroup = groups_get_activity_group($cm, true);
         groups_print_activity_menu($cm, $CFG->wwwroot . '/mod/assignment/submissions.php?id=' . $this->cm->id);
 
-        /// Get all ppl that are allowed to submit assignments
-        if ($users = get_users_by_capability($context, 'mod/assignment:submit', 'u.id', '', '', '', $currentgroup, '', false)) {
+        $gradebookroles = explode(",", $CFG->gradebookroles);
+        $users = get_role_users($gradebookroles, $context, true);
+        if ($users) {
             $users = array_keys($users);
-        }
-
-        // if groupmembersonly used, remove users who are not in any group
-        if ($users and !empty($CFG->enablegroupings) and $cm->groupmembersonly) {
-            if ($groupingusers = groups_get_grouping_members($cm->groupingid, 'u.id', 'u.id')) {
+            if (!empty($CFG->enablegroupings) and $cm->groupmembersonly) {
+                $groupingusers = groups_get_grouping_members($cm->groupingid, 'u.id', 'u.id');
+                if ($groupingusers) {
                 $users = array_intersect($users, array_keys($groupingusers));
             }
         }
+        }
 
         $tablecolumns = array('picture', 'fullname', 'grade', 'submissioncomment', 'timemodified', 'timemarked', 'status', 'finalgrade');
         if ($uses_outcomes) {
@@ -2776,17 +2783,18 @@
 
     $context = get_context_instance(CONTEXT_MODULE, $cm->id);
 
-    // this is all the users with this capability set, in this context or higher
-    if ($users = get_users_by_capability($context, 'mod/assignment:submit', 'u.id', '', '', '', $groupid, '', false)) {
+    $gradebookroles = explode(",", $CFG->gradebookroles);
+    $users = get_role_users($gradebookroles, $context, true);
+    if ($users) {
         $users = array_keys($users);
-    }
-
     // if groupmembersonly used, remove users who are not in any group
-    if ($users and !empty($CFG->enablegroupings) and $cm->groupmembersonly) {
-        if ($groupingusers = groups_get_grouping_members($cm->groupingid, 'u.id', 'u.id')) {
+        if (!empty($CFG->enablegroupings) and $cm->groupmembersonly) {
+            $groupingusers = groups_get_grouping_members($cm->groupingid, 'u.id', 'u.id');
+            if ($groupingusers) {
             $users = array_intersect($users, array_keys($groupingusers));
         }
     }
+    }
 
     if (empty($users)) {
         return 0;
@@ -3005,7 +3013,9 @@
 
             // count how many people can submit
             $submissions = 0; // init
-            if ($students = get_users_by_capability($context, 'mod/assignment:submit', 'u.id', '', '', '', 0, '', false)) {
+            $gradebookroles = explode(",", $CFG->gradebookroles);
+            $students = get_role_users($gradebookroles, $context, true);
+            if ($students) {
                 foreach($students as $student){
                     if(isset($unmarkedsubmissions[$assignment->id][$student->id])){
                         $submissions++;
Index: moodle/mod/assignment/type/online/assignment.class.php
--- moodle/mod/assignment/type/online/assignment.class.php Base (1.46.2.9)
+++ moodle/mod/assignment/type/online/assignment.class.php Locally Modified (Based On 1.46.2.9)
@@ -84,7 +84,7 @@
         if ($editmode) {
             $this->view_header(get_string('editmysubmission', 'assignment'));
         } else {
-            $this->view_header();
+            $this->view_header(get_string('viewsubmissions', 'assignment'));
         }
 
         $this->view_intro();
@@ -95,28 +95,30 @@
             notify(get_string('submissionsaved', 'assignment'), 'notifysuccess');
         }
 
-        if (has_capability('mod/assignment:submit', $context)) {
             if ($editmode) {
                 print_box_start('generalbox', 'online');
                 $mform->display();
+            print_box_end();
             } else {
                 print_box_start('generalbox boxwidthwide boxaligncenter', 'online');
                 if ($submission) {
                     echo format_text($submission->data1, $submission->data2);
                 } else if (!has_capability('mod/assignment:submit', $context)) { //fix for #4604
+                if (isguest()) {
                     echo '<div style="text-align:center">'. get_string('guestnosubmit', 'assignment').'</div>';
+                } else {
+                    echo '<div style="text-align:center">'. get_string('usernosubmit', 'assignment').'</div>';
+                }
                 } else if ($this->isopen()){    //fix for #4206
                     echo '<div style="text-align:center">'.get_string('emptysubmission', 'assignment').'</div>';
                 }
-            }
             print_box_end();
-            if (!$editmode && $editable) {
+            if ($editable) {
                 echo "<div style='text-align:center'>";
                 print_single_button('view.php', array('id'=>$this->cm->id,'edit'=>'1'),
                         get_string('editmysubmission', 'assignment'));
                 echo "</div>";
             }
-
         }
 
         $this->view_feedback();
Index: moodle/mod/assignment/type/upload/assignment.class.php
--- moodle/mod/assignment/type/upload/assignment.class.php Base (1.32.2.17)
+++ moodle/mod/assignment/type/upload/assignment.class.php Locally Modified (Based On 1.32.2.17)
@@ -36,7 +36,6 @@
 
         $this->view_dates();
 
-        if (has_capability('mod/assignment:submit', $this->context)) {
             $filecount = $this->count_user_files($USER->id);
             $submission = $this->get_submission($USER->id);
 
@@ -58,7 +57,9 @@
                 }
             }
 
+        if (has_capability('mod/assignment:submit', $this->context)) {
             $this->view_upload_form();
+        }
 
             if ($this->notes_allowed()) {
                 print_heading(get_string('notes', 'assignment'), '', 3);
@@ -66,7 +67,6 @@
             }
 
             $this->view_final_submission();
-        }
         $this->view_footer();
     }
 
