The "addtogroup" action for groups does not function properly - Fix included
|Reported by:||jade22||Owned by:|
|Severity:||minor||Keywords:||group invite, join group|
When a user 'requests membership' to a group, the group_join_request(GJR) metadata is added to that users entity.
A user can request to be added to more than one group, giving that user multiple GJR metadata. So a user can have either 1 GJR metadata, or several GJR metadata.
The "add to group" action found at: /mod/groups/actions/addtogroup.php does a good job of looping through multiple GJR metadata in order to find the one that equals the current group the group owner is attempting to add the user to. But it does not function as it should if the user has only one GJR metadata. The function is expecting an array to loop through, if $requests is not an array, the user is not added to the group and instead receives an "invite" invitation.
The other problem is when a user does have multiple GJR metadata, the foreach loop should break as soon as the appropriate metadata is found. This ensures a proper system_message display. Otherwise whatever outcome the last element in the loop has will determine the system_message.