Merge branch 'MDL-19670-master' of git://github.com/gurgus/moodle
This commit is contained in:
@@ -174,6 +174,13 @@ class mod_forum_post_form extends moodleform {
|
||||
|
||||
$contextcheck = has_capability('mod/forum:movediscussions', $modulecontext) && empty($post->parent) && $groupcount > 1;
|
||||
if ($contextcheck) {
|
||||
if (has_capability('mod/forum:canposttomygroups', $modulecontext)
|
||||
&& !isset($post->edit)) {
|
||||
$mform->addElement('checkbox', 'posttomygroups', get_string('posttomygroups', 'forum'));
|
||||
$mform->addHelpButton('posttomygroups', 'posttomygroups', 'forum');
|
||||
$mform->disabledIf('groupinfo', 'posttomygroups', 'checked');
|
||||
}
|
||||
|
||||
foreach ($groupdata as $grouptemp) {
|
||||
$groupinfo[$grouptemp->id] = $grouptemp->name;
|
||||
}
|
||||
@@ -196,6 +203,7 @@ class mod_forum_post_form extends moodleform {
|
||||
} else {
|
||||
$submit_string = get_string('posttoforum', 'forum');
|
||||
}
|
||||
|
||||
$this->add_action_buttons(true, $submit_string);
|
||||
|
||||
$mform->addElement('hidden', 'course');
|
||||
|
||||
@@ -345,5 +345,15 @@ $capabilities = array(
|
||||
'frontpage' => CAP_ALLOW
|
||||
)
|
||||
),
|
||||
'mod/forum:canposttomygroups' => array(
|
||||
|
||||
'captype' => 'write',
|
||||
'contextlevel' => CONTEXT_MODULE,
|
||||
'archetypes' => array(
|
||||
'teacher' => CAP_ALLOW,
|
||||
'editingteacher' => CAP_ALLOW,
|
||||
'manager' => CAP_ALLOW
|
||||
)
|
||||
),
|
||||
);
|
||||
|
||||
|
||||
@@ -217,6 +217,7 @@ $string['forum:allowforcesubscribe'] = 'Allow force subscribe';
|
||||
$string['forumauthorhidden'] = 'Author (hidden)';
|
||||
$string['forumblockingalmosttoomanyposts'] = 'You are approaching the posting threshold. You have posted {$a->numposts} times in the last {$a->blockperiod} and the limit is {$a->blockafter} posts.';
|
||||
$string['forumbodyhidden'] = 'This post cannot be viewed by you, probably because you have not posted in the discussion, the maximum editing time hasn\'t passed yet, the discussion has not started or the discussion has expired.';
|
||||
$string['forum:canposttomygroups'] = 'Can post to all groups you have access to';
|
||||
$string['forum:createattachment'] = 'Create attachments';
|
||||
$string['forum:deleteanypost'] = 'Delete any posts (anytime)';
|
||||
$string['forum:deleteownpost'] = 'Delete own posts (within deadline)';
|
||||
@@ -373,6 +374,8 @@ $string['page-mod-forum-view'] = 'Forum module main page';
|
||||
$string['page-mod-forum-discuss'] = 'Forum module discussion thread page';
|
||||
$string['parent'] = 'Show parent';
|
||||
$string['parentofthispost'] = 'Parent of this post';
|
||||
$string['posttomygroups'] = 'Post a copy to all groups';
|
||||
$string['posttomygroups_help'] = 'Posts a copy of this message to all groups you have access to. Participants in groups you do not have access to will not see this post';
|
||||
$string['prevdiscussiona'] = 'Previous discussion: {$a}';
|
||||
$string['pluginadministration'] = 'Forum administration';
|
||||
$string['pluginname'] = 'Forum';
|
||||
|
||||
+67
-55
@@ -849,24 +849,10 @@ if ($mform_post->is_cancelled()) {
|
||||
exit;
|
||||
|
||||
} else { // Adding a new discussion.
|
||||
// Before we add this we must check that the user will not exceed the blocking threshold.
|
||||
forum_check_blocking_threshold($thresholdwarning);
|
||||
|
||||
if (!forum_user_can_post_discussion($forum, $fromform->groupid, -1, $cm, $modcontext)) {
|
||||
print_error('cannotcreatediscussion', 'forum');
|
||||
}
|
||||
// If the user has access all groups capability let them choose the group.
|
||||
if ($contextcheck) {
|
||||
$fromform->groupid = $fromform->groupinfo;
|
||||
}
|
||||
if (empty($fromform->groupid)) {
|
||||
$fromform->groupid = -1;
|
||||
}
|
||||
|
||||
$fromform->mailnow = empty($fromform->mailnow) ? 0 : 1;
|
||||
|
||||
$discussion = $fromform;
|
||||
$discussion->name = $fromform->subject;
|
||||
$discussion->name = $fromform->subject;
|
||||
|
||||
$newstopic = false;
|
||||
if ($forum->type == 'news' && !$fromform->parent) {
|
||||
@@ -875,50 +861,76 @@ if ($mform_post->is_cancelled()) {
|
||||
$discussion->timestart = $fromform->timestart;
|
||||
$discussion->timeend = $fromform->timeend;
|
||||
|
||||
$message = '';
|
||||
if ($discussion->id = forum_add_discussion($discussion, $mform_post, $message)) {
|
||||
|
||||
$params = array(
|
||||
'context' => $modcontext,
|
||||
'objectid' => $discussion->id,
|
||||
'other' => array(
|
||||
'forumid' => $forum->id,
|
||||
)
|
||||
);
|
||||
$event = \mod_forum\event\discussion_created::create($params);
|
||||
$event->add_record_snapshot('forum_discussions', $discussion);
|
||||
$event->trigger();
|
||||
|
||||
$timemessage = 2;
|
||||
if (!empty($message)) { // if we're printing stuff about the file upload
|
||||
$timemessage = 4;
|
||||
}
|
||||
|
||||
if ($fromform->mailnow) {
|
||||
$message .= get_string("postmailnow", "forum");
|
||||
$timemessage = 4;
|
||||
} else {
|
||||
$message .= '<p>'.get_string("postaddedsuccess", "forum") . '</p>';
|
||||
$message .= '<p>'.get_string("postaddedtimeleft", "forum", format_time($CFG->maxeditingtime)) . '</p>';
|
||||
}
|
||||
|
||||
if ($subscribemessage = forum_post_subscription($fromform, $forum, $discussion)) {
|
||||
$timemessage = 6;
|
||||
}
|
||||
|
||||
// Update completion status
|
||||
$completion=new completion_info($course);
|
||||
if($completion->is_enabled($cm) &&
|
||||
($forum->completiondiscussions || $forum->completionposts)) {
|
||||
$completion->update_state($cm,COMPLETION_COMPLETE);
|
||||
}
|
||||
|
||||
redirect(forum_go_back_to("view.php?f=$fromform->forum"), $message.$subscribemessage, $timemessage);
|
||||
$allowedgroups = array();
|
||||
$groupstopostto = array();
|
||||
|
||||
// If we are posting a copy to all groups the user has access to.
|
||||
if (isset($fromform->posttomygroups)) {
|
||||
$allowedgroups = groups_get_activity_allowed_groups($cm);
|
||||
$groupstopostto = array_keys($allowedgroups);
|
||||
} else {
|
||||
print_error("couldnotadd", "forum", $errordestination);
|
||||
if ($contextcheck) {
|
||||
$fromform->groupid = $fromform->groupinfo;
|
||||
}
|
||||
if (empty($fromform->groupid)) {
|
||||
$fromform->groupid = -1;
|
||||
}
|
||||
$groupstopostto = array($fromform->groupid);
|
||||
}
|
||||
|
||||
// Before we post this we must check that the user will not exceed the blocking threshold.
|
||||
forum_check_blocking_threshold($thresholdwarning);
|
||||
|
||||
foreach ($groupstopostto as $group) {
|
||||
if (!forum_user_can_post_discussion($forum, $group, -1, $cm, $modcontext)) {
|
||||
print_error('cannotcreatediscussion', 'forum');
|
||||
}
|
||||
|
||||
$discussion->groupid = $group;
|
||||
$message = '';
|
||||
if ($discussion->id = forum_add_discussion($discussion, $mform_post, $message)) {
|
||||
|
||||
$params = array(
|
||||
'context' => $modcontext,
|
||||
'objectid' => $discussion->id,
|
||||
'other' => array(
|
||||
'forumid' => $forum->id,
|
||||
)
|
||||
);
|
||||
$event = \mod_forum\event\discussion_created::create($params);
|
||||
$event->add_record_snapshot('forum_discussions', $discussion);
|
||||
$event->trigger();
|
||||
|
||||
$timemessage = 2;
|
||||
if (!empty($message)) { // If we're printing stuff about the file upload.
|
||||
$timemessage = 4;
|
||||
}
|
||||
|
||||
if ($fromform->mailnow) {
|
||||
$message .= get_string("postmailnow", "forum");
|
||||
$timemessage = 4;
|
||||
} else {
|
||||
$message .= '<p>'.get_string("postaddedsuccess", "forum") . '</p>';
|
||||
$message .= '<p>'.get_string("postaddedtimeleft", "forum", format_time($CFG->maxeditingtime)) . '</p>';
|
||||
}
|
||||
|
||||
if ($subscribemessage = forum_post_subscription($fromform, $forum, $discussion)) {
|
||||
$timemessage = 6;
|
||||
}
|
||||
} else {
|
||||
print_error("couldnotadd", "forum", $errordestination);
|
||||
}
|
||||
}
|
||||
|
||||
// Update completion status.
|
||||
$completion = new completion_info($course);
|
||||
if ($completion->is_enabled($cm) &&
|
||||
($forum->completiondiscussions || $forum->completionposts)) {
|
||||
$completion->update_state($cm, COMPLETION_COMPLETE);
|
||||
}
|
||||
|
||||
redirect(forum_go_back_to("view.php?f=$fromform->forum"), $message.$subscribemessage, $timemessage);
|
||||
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,161 @@
|
||||
@mod @mod_forum
|
||||
Feature: A user with access to multiple groups should be able to post a copy of a message to all the groups they have access to
|
||||
In order to post to all groups a user has access to
|
||||
As a user
|
||||
I need to have the option to post a copy of a message to all groups
|
||||
|
||||
Background:
|
||||
Given the following "users" exist:
|
||||
| username | firstname | lastname | email |
|
||||
| teacher1 | Teacher | 1 | teacher1@asd.com |
|
||||
| student1 | Student | 1 | student1@asd.com |
|
||||
| student2 | Student | 2 | student2@asd.com |
|
||||
| student3 | Student | 3 | student3@asd.com |
|
||||
And the following "courses" exist:
|
||||
| fullname | shortname | category |
|
||||
| Course 1 | C1 | 0 |
|
||||
| Course 2 | C2 | 0 |
|
||||
And the following "course enrolments" exist:
|
||||
| user | course | role |
|
||||
| teacher1 | C1 | editingteacher |
|
||||
| teacher1 | C2 | editingteacher |
|
||||
| student1 | C1 | student |
|
||||
| student1 | C2 | student |
|
||||
| student2 | C1 | student |
|
||||
| student2 | C2 | student |
|
||||
| student3 | C1 | student |
|
||||
| student3 | C2 | student |
|
||||
And the following "groups" exist:
|
||||
| name | course | idnumber |
|
||||
| Group A | C1 | C1G1 |
|
||||
| Group B | C1 | C1G2 |
|
||||
| Group C | C1 | C1G3 |
|
||||
| Group A | C2 | C2G1 |
|
||||
| Group B | C2 | C2G2 |
|
||||
| Group C | C2 | C2G3 |
|
||||
And the following "groupings" exist:
|
||||
| name | course | idnumber |
|
||||
| G1 | C2 | G1 |
|
||||
And the following "group members" exist:
|
||||
| user | group |
|
||||
| teacher1 | C1G1 |
|
||||
| teacher1 | C1G2 |
|
||||
| teacher1 | C1G3 |
|
||||
| teacher1 | C2G1 |
|
||||
| teacher1 | C2G1 |
|
||||
| student1 | C1G1 |
|
||||
| student1 | C2G1 |
|
||||
| student1 | C2G2 |
|
||||
| student2 | C1G1 |
|
||||
| student2 | C1G2 |
|
||||
| student3 | C1G1 |
|
||||
| student3 | C1G2 |
|
||||
| student3 | C1G3 |
|
||||
And the following "grouping groups" exist:
|
||||
| grouping | group |
|
||||
| G1 | C2G1 |
|
||||
| G1 | C2G2 |
|
||||
And I log in as "teacher1"
|
||||
And I follow "Course 1"
|
||||
And I turn editing mode on
|
||||
And I add a "Forum" to section "1" and I fill the form with:
|
||||
| Forum name | Separate group forum |
|
||||
| Forum type | Standard forum for general use |
|
||||
| Description | Standard forum description |
|
||||
| Group mode | Separate groups |
|
||||
And I add a "Forum" to section "2" and I fill the form with:
|
||||
| Forum name | Visible group forum |
|
||||
| Forum type | Standard forum for general use |
|
||||
| Description | Standard forum description |
|
||||
| Group mode | Visible groups |
|
||||
And I add a "Forum" to section "3" and I fill the form with:
|
||||
| Forum name | No group forum |
|
||||
| Forum type | Standard forum for general use |
|
||||
| Description | Standard forum description |
|
||||
| Group mode | No groups |
|
||||
And I log out
|
||||
And I log in as "teacher1"
|
||||
And I follow "Course 2"
|
||||
And I turn editing mode on
|
||||
And I add a "Forum" to section "1" and I fill the form with:
|
||||
| Forum name | Groupings forum |
|
||||
| Forum type | Standard forum for general use |
|
||||
| Description | Standard forum description |
|
||||
| Group mode | Separate groups |
|
||||
| Grouping | G1 |
|
||||
And I log out
|
||||
|
||||
@javascript
|
||||
Scenario: Teacher is able to post a copy of a message to all groups in a separate group forum
|
||||
Given I log in as "teacher1"
|
||||
And I follow "Course 1"
|
||||
And I add a new discussion to "Separate group forum" forum with:
|
||||
| Subject | Discussion 1 |
|
||||
| Message | test |
|
||||
| Post a copy to all groups | 1 |
|
||||
And I log out
|
||||
And I log in as "student1"
|
||||
And I follow "Course 1"
|
||||
When I follow "Separate group forum"
|
||||
Then I should see "Discussion 1"
|
||||
And I log out
|
||||
And I log in as "student2"
|
||||
And I follow "Course 1"
|
||||
And I follow "Separate group forum"
|
||||
And I should see "Discussion 1"
|
||||
And I log out
|
||||
And I log in as "student3"
|
||||
And I follow "Course 1"
|
||||
And I follow "Separate group forum"
|
||||
And I should see "Discussion 1"
|
||||
|
||||
@javascript
|
||||
Scenario: Teacher is able to post a copy of a message to all groups in a visible group forum
|
||||
Given I log in as "teacher1"
|
||||
And I follow "Course 1"
|
||||
And I add a new discussion to "Visible group forum" forum with:
|
||||
| Subject | Discussion 1 |
|
||||
| Message | test |
|
||||
| Post a copy to all groups | 1 |
|
||||
And I log out
|
||||
And I log in as "student1"
|
||||
And I follow "Course 1"
|
||||
When I follow "Visible group forum"
|
||||
Then I should see "Discussion 1"
|
||||
And I log out
|
||||
And I log in as "student2"
|
||||
And I follow "Course 1"
|
||||
And I follow "Visible group forum"
|
||||
And I should see "Discussion 1"
|
||||
And I log out
|
||||
And I log in as "student3"
|
||||
And I follow "Course 1"
|
||||
And I follow "Visible group forum"
|
||||
And I should see "Discussion 1"
|
||||
|
||||
@javascript
|
||||
Scenario: Teacher is unable to post a copy of a message to all groups in a no group forum
|
||||
Given I log in as "teacher1"
|
||||
And I follow "Course 1"
|
||||
And I follow "No group forum"
|
||||
And I press "Add a new discussion topic"
|
||||
Then I should not see "Post a copy to all groups"
|
||||
|
||||
@javascript
|
||||
Scenario: Posts to all groups that have groupings should only display within the grouping and not to other groups
|
||||
Given I log in as "teacher1"
|
||||
And I follow "Course 2"
|
||||
And I add a new discussion to "Groupings forum" forum with:
|
||||
| Subject | Discussion 1 |
|
||||
| Message | test |
|
||||
| Post a copy to all groups | 1 |
|
||||
And I log out
|
||||
And I log in as "student1"
|
||||
And I follow "Course 2"
|
||||
When I follow "Groupings forum"
|
||||
Then I should see "Discussion 1"
|
||||
And I log out
|
||||
And I log in as "student2"
|
||||
And I follow "Course 2"
|
||||
And I follow "Groupings forum"
|
||||
And I should not see "Discussion 1"
|
||||
@@ -54,6 +54,7 @@ Feature: Posting to all groups in a separate group discussion is restricted to u
|
||||
Then the "Group" select box should contain "All participants"
|
||||
And the "Group" select box should contain "Group A"
|
||||
And the "Group" select box should contain "Group B"
|
||||
And I should see "Post a copy to all groups"
|
||||
|
||||
@javascript
|
||||
Scenario: Teacher in all groups but without accessallgroups can only post in their groups
|
||||
@@ -68,6 +69,7 @@ Feature: Posting to all groups in a separate group discussion is restricted to u
|
||||
Then the "Group" select box should not contain "All participants"
|
||||
And the "Group" select box should contain "Group A"
|
||||
And the "Group" select box should contain "Group B"
|
||||
And I should see "Post a copy to all groups"
|
||||
|
||||
@javascript
|
||||
Scenario: Teacher in some groups and without accessallgroups can only post in their groups
|
||||
@@ -82,3 +84,4 @@ Feature: Posting to all groups in a separate group discussion is restricted to u
|
||||
Then the "Group" select box should not contain "All participants"
|
||||
And the "Group" select box should contain "Group A"
|
||||
And the "Group" select box should contain "Group B"
|
||||
And I should see "Post a copy to all groups"
|
||||
|
||||
@@ -63,6 +63,7 @@ Feature: Posting to groups in a separate group discussion when restricted to gro
|
||||
And I click on "Add a new discussion topic" "button"
|
||||
And the "Group" select box should contain "All participants"
|
||||
And the "Group" select box should contain "G2G1"
|
||||
And I should see "Post a copy to all groups"
|
||||
|
||||
@javascript
|
||||
Scenario: Teacher in all groups but without accessallgroups can post in either group but not to All Participants
|
||||
|
||||
@@ -24,6 +24,6 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$plugin->version = 2014111000; // The current module version (Date: YYYYMMDDXX)
|
||||
$plugin->version = 2015031200; // The current module version (Date: YYYYMMDDXX)
|
||||
$plugin->requires = 2014110400; // Requires this Moodle version
|
||||
$plugin->component = 'mod_forum'; // Full name of the plugin (used for diagnostics)
|
||||
|
||||
Reference in New Issue
Block a user