Exemple #1
0
 public function list_userAction()
 {
     if ($resp = $this->checkUserInput(['group_id'], self::GET)) {
         $resp->flush();
         return false;
     }
     if (!($group = GroupManager::getInstance()->getGroupById(ApiRequest::getParam('group_id')))) {
         (new ApiResponse(Code::FAIL_GROUP_NOT_EXISTS, null))->flush();
         return false;
     }
     $groupUserManager = GroupUserManager::getInstance();
     if (!($groupUser = $groupUserManager->getGroupUserByGidUid($group->id, $this->user->id))) {
         (new ApiResponse(Code::FAIL_GROUP_USER_NOT_EXISTS, null))->flush();
         return false;
     }
     $status = ApiRequest::getParam('status');
     $groupUserModel = new GroupUser();
     if ($group->type == Group::TYPE_CHATROOM) {
         $groupUserModel->status = GroupUser::STATUS_AGREE;
     } else {
         $groupUserModel->status = $status;
         if (!$groupUserModel->checkStatus()) {
             (new ApiResponse(Code::FAIL_GROUP_USER_STATUS, 'chatroom must set status'))->flush();
             return false;
         }
         if ($status != GroupUser::STATUS_AGREE && $groupUser->permission < GroupUser::PERMISSION_ADMIN) {
             (new ApiResponse(Code::FAIL_GROUP_USER_PERMISSION, null))->flush();
             return false;
         }
     }
     $objects = $groupUserManager->getAllGroupUser($group, $groupUserModel, $this->getOffset(), $this->getLimit());
     if (is_array($objects)) {
         $list = [];
         foreach ($objects as $o) {
             $list[] = $o->toArray();
         }
         (new ApiResponse(Code::SUCCESS, $list))->flush();
     } else {
         (new ApiResponse($groupUserManager->getLastErrorCode(), $groupUserManager->getLastErrorString()))->flush();
     }
     return false;
 }
Exemple #2
0
 public function manageUser(GroupUser $model, User $manageUser)
 {
     $checkStatus = $model->checkStatus();
     $checkPermission = $model->checkPermission();
     if (!$checkStatus && !$checkPermission) {
         return null;
     }
     if (!($dbModel = $this->getGroupUserByGidUid($model->gid, $model->uid))) {
         return new ApiResponse($this->getLastErrorCode(), $this->getLastErrorString());
     }
     $model->id = $dbModel->id;
     // nothing changed as up
     if ($checkStatus && $model->status == $dbModel->status && $checkPermission && $model->permission == $dbModel->permission) {
         return null;
     }
     $groupManager = GroupManager::getInstance();
     if (!($group = $groupManager->getGroupById($dbModel->gid))) {
         return new ApiResponse($groupManager->getLastErrorCode(), null);
     }
     if ($group->type == Group::TYPE_CHATROOM) {
         return new ApiResponse(Code::FAIL_PERMISSION_DENY, 'chatroom can not manage');
     }
     if (!($userGroupUser = $this->getGroupUserByGidUid($dbModel->gid, $manageUser->id))) {
         return new ApiResponse($this->getLastErrorCode(), $this->getLastErrorString());
     }
     if ($userGroupUser->permission != GroupUser::PERMISSION_ADMIN && $userGroupUser->permission != GroupUser::PERMISSION_ROOT) {
         return new ApiResponse(Code::FAIL_PERMISSION_DENY, 'normal user');
     }
     if ($userGroupUser->permission == GroupUser::PERMISSION_ADMIN && ($dbModel->permission == GroupUser::PERMISSION_ADMIN || $dbModel->permission == GroupUser::PERMISSION_ROOT)) {
         return new ApiResponse(Code::FAIL_PERMISSION_DENY, 'admin only can manage normal people');
     }
     if ($userGroupUser->permission == GroupUser::PERMISSION_ADMIN && $checkPermission) {
         return new ApiResponse(Code::FAIL_PERMISSION_DENY, 'admin only can not manage permission');
     }
     if ($userGroupUser->permission == GroupUser::PERMISSION_ROOT && $checkPermission && $model->permission == GroupUser::PERMISSION_ROOT) {
         return new ApiResponse(Code::FAIL_PERMISSION_DENY, 'always one root');
     }
     if ($checkStatus && $checkPermission) {
         if ($resp = $this->updateGroupUserStatusAndPermission($model)) {
             return $resp;
         }
     } else {
         if ($checkStatus) {
             if ($resp = $this->updateGroupUserStatus($model)) {
                 return $resp;
             }
         } else {
             if ($resp = $this->updateGroupUserPermission($model)) {
                 return $resp;
             }
         }
     }
     $model->gid = $dbModel->gid;
     $model->create_time = $dbModel->create_time;
     $model->uid = $dbModel->uid;
     $model->remark = $dbModel->remark;
     if ($dbModel->status != GroupUser::STATUS_AGREE && $model->status == GroupUser::STATUS_AGREE) {
         JegarnUtil::joinGroup($model->gid, $model->uid);
         JegarnUtil::sendGroupAgreeNotification($group->uid, $model->uid, $group->id, $group->name);
     } else {
         if ($dbModel->status != GroupUser::STATUS_REFUSED && $model->status == GroupUser::STATUS_REFUSED) {
             JegarnUtil::sendGroupRefusedNotification($group->uid, $model->uid, $group->id, $group->name);
         }
     }
     return null;
 }