Alex Aragón 5 years ago
parent
commit
4a64e70f1f

+ 1 - 1
main/admin/questions.php

@@ -51,7 +51,7 @@ if ($formSent) {
     }
 
     if (!empty($description)) {
-        $criteria->orWhere($criteria->expr()->contains('description', $description));
+        $criteria->orWhere($criteria->expr()->contains('description', $description."\r"));
     }
 
     if (!empty($title)) {

+ 2 - 2
main/group/group_creation.php

@@ -134,7 +134,7 @@ if (isset($_POST['number_of_groups'])) {
     <?php
         }
         $group_categories = GroupManager::get_categories();
-        $group_id = GroupManager:: get_number_of_groups() + 1;
+        $group_id = GroupManager::get_number_of_groups() + 1;
         $cat_options = [];
         foreach ($group_categories as $index => $category) {
             $cat_options[$category['id']] = $category['title'];
@@ -233,7 +233,7 @@ EOT;
             $form->addGroup($group_el, 'group_'.$group_number, null, '</td><td>', false);
         }
         $defaults['action'] = 'create_groups';
-        $defaults['number_of_groups'] = intval($_POST['number_of_groups']);
+        $defaults['number_of_groups'] = (int) $_POST['number_of_groups'];
         $form->setDefaults($defaults);
         $form->addButtonCreate(get_lang('CreateGroup'), 'submit');
         $form->display();

+ 38 - 7
main/group/settings.php

@@ -21,12 +21,16 @@ api_protect_course_script(true);
 $group_id = api_get_group_id();
 $current_group = GroupManager::get_group_properties($group_id);
 
+if (empty($current_group)) {
+    api_not_allowed(true);
+}
+
 $nameTools = get_lang('EditGroup');
 $interbreadcrumb[] = ['url' => 'group.php?'.api_get_cidreq(), 'name' => get_lang('Groups')];
 $interbreadcrumb[] = ['url' => 'group_space.php?'.api_get_cidreq(), 'name' => $current_group['name']];
-$is_group_member = GroupManager::is_tutor_of_group(api_get_user_id(), $current_group);
+$groupMember = GroupManager::is_tutor_of_group(api_get_user_id(), $current_group);
 
-if (!api_is_allowed_to_edit(false, true) && !$is_group_member) {
+if (!$groupMember && !api_is_allowed_to_edit(false, true)) {
     api_not_allowed(true);
 }
 
@@ -67,8 +71,21 @@ $form->addElement('html', '<div class="col-md-6">');
 
 // Members per group
 $group = [
-    $form->createElement('radio', 'max_member_no_limit', get_lang('GroupLimit'), get_lang('NoLimit'), GroupManager::MEMBER_PER_GROUP_NO_LIMIT),
-    $form->createElement('radio', 'max_member_no_limit', null, get_lang('MaximumOfParticipants'), 1, ['id' => 'max_member_selected']),
+    $form->createElement(
+        'radio',
+        'max_member_no_limit',
+        get_lang('GroupLimit'),
+        get_lang('NoLimit'),
+        GroupManager::MEMBER_PER_GROUP_NO_LIMIT
+    ),
+    $form->createElement(
+        'radio',
+        'max_member_no_limit',
+        null,
+        get_lang('MaximumOfParticipants'),
+        1,
+        ['id' => 'max_member_selected']
+    ),
     $form->createElement('text', 'max_member', null, ['class' => 'span1', 'id' => 'max_member']),
     $form->createElement('static', null, null, ' '.get_lang('GroupPlacesThis')),
 ];
@@ -81,13 +98,26 @@ $form->addElement('html', '<div class="col-md-6">');
 
 // Self registration
 $group = [
-    $form->createElement('checkbox', 'self_registration_allowed', get_lang('GroupSelfRegistration'), get_lang('GroupAllowStudentRegistration'), 1),
-    $form->createElement('checkbox', 'self_unregistration_allowed', null, get_lang('GroupAllowStudentUnregistration'), 1),
+    $form->createElement(
+        'checkbox',
+        'self_registration_allowed',
+        get_lang('GroupSelfRegistration'),
+        get_lang('GroupAllowStudentRegistration'),
+        1
+    ),
+    $form->createElement(
+        'checkbox',
+        'self_unregistration_allowed',
+        null,
+        get_lang('GroupAllowStudentUnregistration'),
+        1
+    ),
 ];
 $form->addGroup(
     $group,
     '',
-    Display::return_icon('user.png', get_lang('GroupSelfRegistration')).'<span>'.get_lang('GroupSelfRegistration').'</span>',
+    Display::return_icon('user.png', get_lang('GroupSelfRegistration')).
+    '<span>'.get_lang('GroupSelfRegistration').'</span>',
     null,
     false
 );
@@ -217,6 +247,7 @@ $group = [
     $form->createElement('radio', 'announcements_state', get_lang('GroupAnnouncements'), get_lang('NotAvailable'), GroupManager::TOOL_NOT_AVAILABLE),
     $form->createElement('radio', 'announcements_state', null, get_lang('Public'), GroupManager::TOOL_PUBLIC),
     $form->createElement('radio', 'announcements_state', null, get_lang('Private'), GroupManager::TOOL_PRIVATE),
+    //$form->createElement('radio', 'announcements_state', null, get_lang('PrivateBetweenUsers'), GroupManager::TOOL_PRIVATE_BETWEEN_USERS),
 ];
 
 $form->addGroup(

+ 7 - 1
main/inc/ajax/announcement.ajax.php

@@ -10,6 +10,7 @@ $action = isset($_REQUEST['a']) ? $_REQUEST['a'] : null;
 
 $isAllowedToEdit = api_is_allowed_to_edit();
 $courseInfo = api_get_course_info();
+$courseId = api_get_course_int_id();
 $groupId = api_get_group_id();
 $sessionId = api_get_session_id();
 
@@ -35,12 +36,17 @@ switch ($action) {
         }
 
         if ($allowToEdit === false && !empty($groupId)) {
-            $groupProperties = GroupManager:: get_group_properties($groupId);
+            $groupProperties = GroupManager::get_group_properties($groupId);
             // Check if user is tutor group
             $isTutor = GroupManager::is_tutor_of_group(api_get_user_id(), $groupProperties, $courseId);
             if ($isTutor) {
                 $allowToEdit = true;
             }
+
+            // Last chance ... students can send announcements.
+            /*if ($groupProperties['announcements_state'] == GroupManager::TOOL_PRIVATE_BETWEEN_USERS) {
+                $allowToEdit = true;
+            }*/
         }
 
         if ($allowToEdit === false) {

+ 9 - 3
main/inc/lib/api.lib.php

@@ -8982,11 +8982,17 @@ function api_mail_html(
  */
 function api_protect_course_group($tool, $showHeader = true)
 {
-    $userId = api_get_user_id();
     $groupId = api_get_group_id();
-    $groupInfo = GroupManager::get_group_properties($groupId);
+    if (!empty($groupId)) {
+        $userId = api_get_user_id();
+        $groupInfo = GroupManager::get_group_properties($groupId);
+
+        // Group doesn't exists
+        if (empty($groupInfo)) {
+            api_not_allowed($showHeader);
+        }
 
-    if (!empty($groupInfo)) {
+        // Check group access
         $allow = GroupManager::user_has_access(
             $userId,
             $groupInfo['iid'],

+ 13 - 5
main/inc/lib/groupmanager.lib.php

@@ -45,6 +45,8 @@ class GroupManager
     const TOOL_NOT_AVAILABLE = 0;
     const TOOL_PUBLIC = 1;
     const TOOL_PRIVATE = 2;
+    const TOOL_PRIVATE_BETWEEN_USERS = 3;
+
     /**
      * Constants for the available group tools.
      */
@@ -2135,6 +2137,13 @@ class GroupManager
                     return true;
                 }
                 break;
+            case self::TOOL_PRIVATE_BETWEEN_USERS:
+                // Only works for announcements for now
+                $userIsInGroup = self::is_user_in_group($user_id, $groupInfo);
+                if ($userIsInGroup && $tool == self::GROUP_TOOL_ANNOUNCEMENT) {
+                    return true;
+                }
+                break;
         }
 
         return false;
@@ -2853,17 +2862,16 @@ class GroupManager
         echo '
             <ul class="toolbar-groups nav nav-tabs">
                 <li class="'.$activeSettings.'">
-                    <a href="'.sprintf($url, 'settings.php').'">
+                    <a id="group_settings_tab" href="'.sprintf($url, 'settings.php').'">
                     '.Display::return_icon('settings.png').' '.get_lang('Settings').'
                     </a>
                 </li>
                 <li class="'.$activeMember.'">
-                    <a href="'.sprintf($url, 'member_settings.php').'">
-                    '.Display::return_icon('user.png').' '.get_lang('GroupMembers').'
-                    </a>
+                    <a id="group_members_tab" href="'.sprintf($url, 'member_settings.php').'">
+                    '.Display::return_icon('user.png').' '.get_lang('GroupMembers').'</a>
                 </li>
                 <li class="'.$activeTutor.'">
-                    <a href="'.sprintf($url, 'tutor_settings.php').'">
+                    <a id="group_tutors_tab" href="'.sprintf($url, 'tutor_settings.php').'">
                     '.Display::return_icon('teacher.png').' '.get_lang('GroupTutors').'
                     </a>
                 </li>

+ 24 - 0
tests/behat/features/bootstrap/FeatureContext.php

@@ -499,6 +499,30 @@ class FeatureContext extends MinkContext
         return false;
     }
 
+
+    /**
+     * @Then /^I save current URL with name "([^"]*)"$/
+     */
+    public function saveUrlWithName($name)
+    {
+
+        $url = $this->getSession()->getCurrentUrl();
+        $this->getSession()->setCookie($name, $url);
+    }
+
+    /**
+     * @Then /^I visit URL saved with name "([^"]*)"$/
+     */
+    public function visitSavedUrlWithName($name)
+    {
+        $url = $this->getSession()->getCookie($name);
+        echo $url;
+        if (empty($url)) {
+            throw new Exception("Url with name: $name not found");
+        }
+        $this->visit($url);
+    }
+
     /**
      * Example: Then I should see the table "#category_results":
      *               | Categories    | Absolute score | Relative score |

+ 7 - 1
tests/behat/features/course_user_registration.feature

@@ -20,4 +20,10 @@ Feature: Subscribe users to the course
     Given I am on "/main/user/subscribe_user.php?keyword=acostea&type=5&cidReq=TEMP"
     Then I should see "Andrea"
     Then I follow "Register"
-    Then I should see "User Andrea Costea (acostea) has been registered to course TEMP"
+    Then I should see "User Andrea Costea (acostea) has been registered to course TEMP"
+
+  Scenario: Subscribe "fapple" as student to the course "TEMP" (leave it subscribed for further tests)
+    Given I am on "/main/user/subscribe_user.php?keyword=fapple&type=5&cidReq=TEMP"
+    Then I should see "Fiona"
+    Then I follow "Register"
+    Then I should see "User Fiona Apple Maggart (fapple) has been registered to course TEMP"

+ 213 - 3
tests/behat/features/toolGroup.feature

@@ -13,17 +13,38 @@ Feature: Group tool
     And I press "group_category_submit"
     Then I should see "Category created"
 
-  Scenario: Create a group
+  Scenario: Create 4 groups
     Given I am on "/main/group/group_creation.php?cidReq=TEMP&id_session=0"
     When I fill in the following:
-      | number_of_groups | 1 |
+      | number_of_groups | 4 |
     And I press "submit"
     Then I should see "New groups creation"
     When I fill in the following:
       | group_0_places | 1 |
+      | group_1_places | 1 |
+      | group_2_places | 1 |
+      | group_3_places | 1 |
     And I press "submit"
     Then I should see "group(s) has (have) been added"
 
+  Scenario: Change Group 0003 settings to make announcements private
+    Given I am on "/main/group/group.php?cidReq=TEMP&id_session=0"
+    And I follow "Group 0003"
+    Then I should see "Group 0003"
+    Then I follow "Edit this group"
+    Then I check the "announcements_state" radio button with "2" value
+    Then I press "Save settings"
+    Then I should see "Group settings modified"
+
+  Scenario: Change Group 0004 settings to make it private
+    Given I am on "/main/group/group.php?cidReq=TEMP&id_session=0"
+    And I follow "Group 0004"
+    Then I should see "Group 0004"
+    Then I follow "Edit this group"
+    Then I check the "announcements_state" radio button with "2" value
+    Then I press "Save settings"
+    Then I should see "Group settings modified"
+
   Scenario: Create document folder in group
     Given I am on "/main/group/group.php?cidReq=TEMP&id_session=0"
     And I follow "Group 0001"
@@ -88,4 +109,193 @@ Feature: Group tool
     Then I follow "Delete"
     Then wait for the page to be loaded
     Then I should see "Are you sure to delete"
-    Then I follow "delete_item"
+    Then I follow "delete_item"
+
+  Scenario: Add fapple to the Group 0001
+    Given I am on "/main/group/group.php?cidReq=TEMP&id_session=0"
+    And I follow "Group 0001"
+    Then I should see "Group 0001"
+    Then I follow "Edit this group"
+    Then I should see "Group members"
+    Then wait for the page to be loaded
+    Then I follow "group_members_tab"
+    Then I select "Fiona Apple Maggart (fapple)" from "group_members"
+    Then I press "group_members_rightSelected"
+    Then I press "Save settings"
+    And wait for the page to be loaded
+    Then I should see "Group settings modified"
+    Then I follow "Group 0001"
+    Then I should see "Fiona"
+
+  Scenario: Add fapple to the Group 0003
+    Given I am on "/main/group/group.php?cidReq=TEMP&id_session=0"
+    And I follow "Group 0003"
+    Then I should see "Group 0003"
+    Then I follow "Edit this group"
+    Then I should see "Group members"
+    Then wait for the page to be loaded
+    Then I follow "group_members_tab"
+    Then I select "Fiona Apple Maggart (fapple)" from "group_members"
+    Then I press "group_members_rightSelected"
+    Then I press "Save settings"
+    And wait for the page to be loaded
+    Then I should see "Group settings modified"
+    Then I follow "Group 0003"
+    Then I should see "Fiona"
+
+  Scenario: Add acostea to the Group 0002
+    Given I am on "/main/group/group.php?cidReq=TEMP&id_session=0"
+    And I follow "Group 0002"
+    Then I should see "Group 0002"
+    Then I follow "Edit this group"
+    Then I should see "Group members"
+    Then wait for the page to be loaded
+    Then I follow "group_members_tab"
+    Then I select "Andrea Costea (acostea)" from "group_members"
+    Then I press "group_members_rightSelected"
+    Then I press "Save settings"
+    And wait for the page to be loaded
+    Then I should see "Group settings modified"
+    Then I follow "Group 0002"
+    Then I should see "Andrea"
+
+  Scenario: Create an announcement for everybody inside Group 0001
+    Given I am on "/main/group/group.php?cidReq=TEMP&id_session=0"
+    And I follow "Group 0001"
+    Then I should see "Group 0001"
+    And I follow "Announcements"
+    Then I should see "Announcements"
+    Then I follow "Add an announcement"
+    Then I should see "Add an announcement"
+    Then wait for the page to be loaded
+    Then I fill in the following:
+      | title | Announcement for all users inside Group 0001 |
+    And I fill in ckeditor field "content" with "Announcement description in Group 0001"
+    Then I follow "announcement_preview"
+    And wait for the page to be loaded
+    Then I should see "Announcement will be sent to"
+    Then I press "submit"
+    Then I should see "Announcement has been added"
+
+  Scenario: Create an announcement for fapple inside Group 0001
+    Given I am on "/main/group/group.php?cidReq=TEMP&id_session=0"
+    And I follow "Group 0001"
+    Then I should see "Group 0001"
+    And I follow "Announcements"
+    Then I should see "Announcements"
+    Then I follow "Add an announcement"
+    Then I should see "Add an announcement"
+    Then wait for the page to be loaded
+    Then I press "choose_recipients"
+    Then I select "Fiona Apple" from "users"
+    Then I press "users_rightSelected"
+    Then I fill in the following:
+      | title | Announcement for user fapple inside Group 0001 |
+    And I fill in ckeditor field "content" with "Announcement description for user fapple inside Group 0001"
+    Then I follow "announcement_preview"
+    And wait for the page to be loaded
+    Then I should see "Announcement will be sent to"
+    Then I press "submit"
+    Then I should see "Announcement has been added"
+
+  Scenario: Create an announcement for everybody inside Group 0003 (private)
+    Given I am on "/main/group/group.php?cidReq=TEMP&id_session=0"
+    And I follow "Group 0003"
+    Then I should see "Group 0003"
+    And I follow "Announcements"
+    Then I should see "Announcements"
+    Then I follow "Add an announcement"
+    Then I should see "Add an announcement"
+    Then wait for the page to be loaded
+    Then I fill in the following:
+      | title | Announcement for all users inside Group 0003 |
+    And I fill in ckeditor field "content" with "Announcement description in Group 0003"
+    Then I follow "announcement_preview"
+    And wait for the page to be loaded
+    Then I should see "Announcement will be sent to"
+    Then I press "submit"
+    Then I should see "Announcement has been added"
+
+  Scenario: Create an announcement for fapple inside Group 0003
+    Given I am on "/main/group/group.php?cidReq=TEMP&id_session=0"
+    And I follow "Group 0003"
+    Then I should see "Group 0003"
+    And I follow "Announcements"
+    Then I should see "Announcements"
+    Then I follow "Add an announcement"
+    Then I should see "Add an announcement"
+    Then wait for the page to be loaded
+    Then I press "choose_recipients"
+    Then I select "Fiona Apple" from "users"
+    Then I press "users_rightSelected"
+    Then I fill in the following:
+      | title | Announcement for user fapple inside Group 0003 |
+    And I fill in ckeditor field "content" with "Announcement description for user fapple inside Group 0003"
+    Then I follow "announcement_preview"
+    And wait for the page to be loaded
+    Then I should see "Announcement will be sent to"
+    Then I press "submit"
+    Then I should see "Announcement has been added"
+
+  Scenario: Check fapple access of announcements Group 0001 (fapple group)
+    Given I am logged as "fapple"
+    And I am on course "TEMP" homepage
+    And I am on "/main/group/group.php?cidReq=TEMP&id_session=0"
+    And I follow "Group 0001"
+    Then I should see "Group 0001"
+    Then I follow "Announcements"
+    And wait for the page to be loaded
+    Then I should see "Announcement for all users inside Group 0001"
+    Then I should see "Announcement for user fapple inside Group 0001"
+    Then I follow "Announcement for user fapple inside Group 0001 Group"
+    Then I should see "Announcement description for user fapple inside Group 0001"
+    Then I move backward one page
+    Then wait for the page to be loaded
+    Then I should see "Announcement for all users inside Group 0001"
+    Then I follow "Announcement for all users inside Group 0001"
+    Then I should see "Announcement description in Group 0001"
+
+  Scenario: Check fapple/acostea access of announcements
+    Given I am logged as "fapple"
+    And I am on course "TEMP" homepage
+    And I am on "/main/group/group.php?cidReq=TEMP&id_session=0"
+    And I follow "Group 0003"
+    Then I should see "Group 0003"
+    Then I follow "Announcements"
+    And wait for the page to be loaded
+    Then I should see "Announcement for all users inside Group 0003"
+    Then I should see "Announcement for user fapple inside Group 0003"
+    Then I follow "Announcement for user fapple inside Group 0003 Group"
+    Then I should see "Announcement description for user fapple inside Group 0003"
+    Then I save current URL with name "announcement_for_user_fapple_group_0003_private"
+    Then I move backward one page
+    Then wait for the page to be loaded
+    Then I should see "Announcement for all users inside Group 0003"
+    Then I follow "Announcement for all users inside Group 0003"
+    Then I should see "Announcement description in Group 0003"
+    Then I save current URL with name "announcement_for_all_users_group_0003_private"
+    ## Finish tests with fapple now check access with acostea ##
+    Given I am logged as "acostea"
+    And I am on course "TEMP" homepage
+    Given I am on "/main/group/group.php?cidReq=TEMP&id_session=0"
+    Then I should see "Group 0001"
+    And I should see "Group 0002"
+    And I should see "Group 0003"
+    And I should see "Group 0004"
+    And I follow "Group 0001"
+    Then I should see "Group 0001"
+    Then I follow "Announcements"
+    And wait for the page to be loaded
+    Then I should see "Announcement for all users inside Group 0001"
+    Then I should not see "Announcement for user fapple inside Group 0001"
+    Then I follow "Announcement for all users inside Group 0001"
+    Then I should see "Announcement description in Group 0001"
+    Given I am on "/main/group/group.php?cidReq=TEMP&id_session=0"
+    And I should see "Group 0003"
+    And I follow "Group 0003"
+    Then I should see "Group 0003"
+    Then I should not see "Announcements"
+    Then I visit URL saved with name "announcement_for_user_fapple_group_0003_private"
+    Then I should see "Sorry, you are not allowed to access this page"
+    Then I visit URL saved with name "announcement_for_all_users_group_0003_private"
+    Then I should see "Sorry, you are not allowed to access this page"