function testRoleFromArgs() { $args = array('role' => 'admin'); $role = Input::role(compact('args')); $this->assertEquals('admin', $role); }
/** * Get or set team members * * ## OPTIONS * * <list|add-member|remove-member|change-role> * : i.e. add or remove * * [--site=<site>] * : Site to check * * [--member=<email>] * : Email of the member to add. Member will receive an invite * * [--role=<role>] * : Role for the new member to act as * * @subcommand team */ public function team($args, $assoc_args) { $action = 'list'; if (!empty($args)) { $action = array_shift($args); } $site = $this->sites->get(Input::sitename($assoc_args)); $data = array(); $team = $site->user_memberships; switch ($action) { case 'add-member': if ((bool) $site->getFeature('change_management')) { $role = Input::role($assoc_args); } else { $role = 'team_member'; } $workflow = $team->addMember($assoc_args['member'], $role); $this->workflowOutput($workflow); break; case 'remove-member': $user = $team->get($assoc_args['member']); if ($user != null) { $workflow = $user->removeMember($assoc_args['member']); $this->workflowOutput($workflow); } else { $this->failure('"{member}" is not a valid member.', array('member' => $assoc_args['member'])); } break; case 'change-role': if ((bool) $site->getFeature('change_management')) { $role = Input::role($assoc_args); $user = $team->get($assoc_args['member']); if ($user != null) { $workflow = $user->setRole($role); $this->workflowOutput($workflow); } else { $this->failure('"{member}" is not a valid member.', array('member' => $assoc_args['member'])); } } else { $this->failure('This site does not have the authority to conduct this operation.'); } break; case 'list': default: $user_memberships = $team->all(); foreach ($user_memberships as $uuid => $user_membership) { $user = $user_membership->get('user'); $data[] = array('First' => $user->profile->firstname, 'Last' => $user->profile->lastname, 'Email' => $user->email, 'UUID' => $user->id); } ksort($data); break; } if (!empty($data)) { $this->output()->outputRecordList($data); } }
/** * Get or set team members * * ## OPTIONS * * <list|add-member|remove-member|change-role> * : i.e. add or remove * * [--site=<site>] * : Site to check * * [--member=<email>] * : Email of the member to add. Member will receive an invite * * [--role=<role>] * : Role for the new member to act as * * @subcommand team */ public function team($args, $assoc_args) { $action = array_shift($args) ?: 'list'; $site = SiteFactory::instance(Input::sitename($assoc_args)); $data = array(); $team = $site->getSiteUserMemberships(); switch ($action) { case 'add-member': if ((bool) $site->getFeature('change_management')) { $role = Input::role($assoc_args); } else { $role = 'team_member'; } $workflow = $team->add($assoc_args['member'], $role); $this->workflowOutput($workflow); break; case 'remove-member': $user = $team->findByEmail($assoc_args['member']); $workflow = $user->remove($assoc_args['member']); $this->workflowOutput($workflow); break; case 'change-role': if ((bool) $site->getFeature('change_management')) { $role = Input::role($assoc_args); $user = $team->findByEmail($assoc_args['member']); $workflow = $user->setRole($role); $this->workflowOutput($workflow); } else { Logger::redline('This site does not have the authority to conduct this operation.'); } break; case 'list': default: $user_memberships = $team->all(); foreach ($user_memberships as $uuid => $user_membership) { $user = $user_membership->getUser(); $data[] = array('First' => $user->profile->firstname, 'Last' => $user->profile->lastname, 'Email' => $user->email, 'UUID' => $user->id); } ksort($data); break; } if (!empty($data)) { $this->handleDisplay($data); } }