mirror of
https://github.com/pierre42100/ComunicAPI
synced 2024-12-25 13:08:58 +00:00
Can update group membership level.
This commit is contained in:
parent
a90cde6268
commit
564a06bd1c
@ -382,6 +382,50 @@ class GroupsController {
|
||||
return array("success" => "The membership has been successfully deleted!");
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a membership level
|
||||
*
|
||||
* @url POST /groups/update_membership_level
|
||||
*/
|
||||
public function updateMembershipLevel() : array {
|
||||
|
||||
user_login_required();
|
||||
|
||||
//Get the ID of the target group
|
||||
$groupID = getPostGroupIdWithAccess("groupID", GroupInfo::ADMIN_ACCESS);
|
||||
|
||||
//Get target user ID
|
||||
$userID = getPostUserID("userID");
|
||||
|
||||
if($userID == userID)
|
||||
Rest_fatal_error(400, "You can not update your own membership!");
|
||||
|
||||
//Get current user membership
|
||||
$level = components()->groups->getMembershipLevel($userID, $groupID);
|
||||
|
||||
//Check if the user is at least a member of the group
|
||||
if($level > GroupMember::MEMBER)
|
||||
Rest_fatal_error(401, "This user is not a member of the group!");
|
||||
|
||||
//Get the new membership level of the user
|
||||
$levels = array_flip(self::GROUPS_MEMBERSHIP_LEVELS);
|
||||
|
||||
$new_level_str = postString("level");
|
||||
if(!isset($levels[$new_level_str]))
|
||||
Rest_fatal_error(401, "Specified membership level not found!");
|
||||
$newLevel = $levels[$new_level_str];
|
||||
|
||||
if($newLevel > GroupMember::MEMBER)
|
||||
Rest_fatal_error(401, "You can not assign this visibility level to a group member!");
|
||||
|
||||
//Try to update the membership of the user
|
||||
if(!components()->groups->updateMembershipLevel($userID, $groupID, $newLevel))
|
||||
Rest_fatal_error(500, "Could not update membership level!");
|
||||
|
||||
//Success
|
||||
return array("success" => "User membership has been updated!");
|
||||
}
|
||||
|
||||
/**
|
||||
* Respond to a membership request
|
||||
*
|
||||
|
@ -224,7 +224,7 @@ class GroupsComponent {
|
||||
* @param int $level The target level
|
||||
* @return bool TRUE for a success / FALSE else
|
||||
*/
|
||||
private function updateMembershipLevel(int $userID, int $groupID, int $level) : bool {
|
||||
public function updateMembershipLevel(int $userID, int $groupID, int $level) : bool {
|
||||
return db()->updateDB(
|
||||
self::GROUPS_MEMBERS_TABLE,
|
||||
"user_id = ? AND groups_id = ?",
|
||||
|
Loading…
Reference in New Issue
Block a user