Exemplo n.º 1
0
 /**
  * action 의 permission 설정 반환
  *
  * @param string $instanceId instance identifier
  * @return array
  */
 public function getPerms($instanceId)
 {
     $registered = $this->get($instanceId)->getRegistered();
     $perms = [];
     foreach ($this->actions as $action) {
         $pureGrant = $registered->pure($action);
         $mode = $pureGrant === null ? "inherit" : "manual";
         $perms[] = ['mode' => $mode, 'title' => $action, 'grant' => $this->getGrant($registered, $action), 'groups' => $this->assignor->all()];
     }
     return $perms;
 }
 public function update($id, Request $request)
 {
     /** @var MemberEntityInterface $member */
     $member = $this->members->find($id, ['mails', 'groups']);
     if ($member === null) {
         $e = new InvalidArgumentHttpException();
         $e->setMessage('존재하지 않는 회원입니다.');
         throw $e;
     }
     // default validation
     $validate = Validator::make($request->all(), ['email' => 'email', 'displayName' => 'required', 'rating' => 'required', 'status' => 'required']);
     if ($validate->fails()) {
         $messages = $validate->messages();
         $message = $messages->first();
         $e = new InvalidArgumentException();
         $e->setMessage($message);
         throw $e;
     }
     // display name validation
     $displayName = trim($request->get('displayName'));
     if ($member->getDisplayName() !== $displayName) {
         $this->handler->validateDisplayName($displayName);
     }
     $memberData = $request->except('groupId', 'profileImgFile', '_token');
     // encrypt password
     if (!empty($memberData['password'])) {
         $memberData['password'] = Hash::make($memberData['password']);
     } else {
         unset($memberData['password']);
     }
     if ($profileFile = $request->file('profileImgFile')) {
         /** @var MemberImageHandler $imageHandler */
         $imageHandler = app('xe.member.image');
         $memberData['profileImageId'] = $imageHandler->updateMemberProfileImage($member, $profileFile);
     }
     $inputtedGroup = $request->get('groupId', []);
     $currentGroups = array_pluck($member->groups ?: [], 'id');
     $newGroups = array_diff($inputtedGroup, $currentGroups);
     $oldGroups = array_diff($currentGroups, $inputtedGroup);
     XeDB::beginTransaction();
     try {
         $member->fill($memberData);
         $member = $this->members->update($member);
         // join to new group
         $newGroups = $this->groups->findAll($newGroups);
         foreach ($newGroups as $group) {
             $this->groups->addMember($group, $member);
         }
         // remove from old groups
         if ($member->groups !== null) {
             foreach ($member->groups as $group) {
                 if (in_array($group->id, $oldGroups)) {
                     $this->groups->exceptMember($group, $member);
                 }
             }
         }
     } catch (Exception $e) {
         XeDB::rollBack();
         throw $e;
     }
     XeDB::commit();
     return redirect()->back()->with('alert', ['type' => 'success', 'message' => '수정되었습니다.']);
 }
 /**
  * getItemAccessPermission
  *
  * @param MenuItem $item to find permission target item object
  *
  * @return \Xpressengine\Permission\Permission
  * @throws \Xpressengine\Permission\Exceptions\WrongInstanceException
  */
 public function getItemAccessPermission(MenuItem $item)
 {
     $registered = $this->permission->findRegistered($this->permissionType, $item->getBreadCrumbsKeyString());
     $pureGrant = $registered->pure(Action::ACCESS);
     $mode = $pureGrant === null ? "inherit" : "manual";
     $menuAccessGrant = $registered->offsetGet(Action::ACCESS);
     $groups = $this->groupRepo->findAll($menuAccessGrant['group']);
     $users = $this->memberRepo->findAll($menuAccessGrant['user']);
     $excepts = $this->memberRepo->findAll($menuAccessGrant['except']);
     return ['mode' => $mode, 'rating' => $menuAccessGrant['rating'], 'group' => $groups, 'user' => $users, 'except' => $excepts];
 }
 /**
  * searchGroup
  *
  * @param GroupRepositoryInterface $groupRepo
  * @param null                     $keyword
  *
  * @return \Xpressengine\Presenter\RendererInterface
  */
 public function searchGroup(GroupRepositoryInterface $groupRepo, $keyword = null)
 {
     if ($keyword === null) {
         return Presenter::makeApi($groupRepo->all());
     }
     $matchedGroupList = $groupRepo->search(['name' => $keyword])->items();
     return Presenter::makeApi($matchedGroupList);
 }