Example #1
0
 /**
  * List an organization's sites
  *
  * ## OPTIONS
  *
  * <add|remove|list>
  * : subfunction to run
  *
  * [--org=<id|name>]
  * : Organization UUID or name
  *
  * [--tag=<tag>]
  * : Tag name to filter sites list by
  *
  * [--site=<site>]
  * : Site to add to or remove from organization
  *
  * @subcommand sites
  */
 public function sites($args, $assoc_args)
 {
     $action = array_shift($args);
     $org_id = Input::orgid($assoc_args, 'org', null, array('allow_none' => false));
     $orgs = new UserOrganizationMemberships();
     $org = $orgs->get($org_id);
     $org_info = $org->get('organization');
     $memberships = $org->site_memberships->all();
     switch ($action) {
         case 'add':
             if (isset($assoc_args['site'])) {
                 if ($this->siteIsMember($memberships, $assoc_args['site'])) {
                     $this->failure('{site} is already a member of {org}', array('site' => $assoc_args['site'], 'org' => $org_info->profile->name));
                 } else {
                     $site = $this->sites->get($assoc_args['site']);
                 }
             } else {
                 $site = $this->sites->get(Input::menu($this->getNonmemberSiteList($memberships), null, 'Choose site'));
             }
             Terminus::confirm('Are you sure you want to add %s to %s ?', array($site->get('name'), $org_info->profile->name));
             $workflow = $org->site_memberships->addMember($site);
             $workflow->wait();
             $this->workflowOutput($workflow);
             break;
         case 'remove':
             if (isset($assoc_args['site'])) {
                 if (!$this->siteIsMember($memberships, $assoc_args['site'])) {
                     $this->failure('{site} is not a member of {org}', array('site' => $assoc_args['site'], 'org' => $org_info->profile->name));
                 } else {
                     $site = $this->sites->get($assoc_args['site']);
                 }
             } else {
                 $site = $this->sites->get(Input::menu($this->getMemberSiteList($memberships), null, 'Choose site'));
             }
             $member = $org->site_memberships->get($site->get('id'));
             Terminus::confirm('Are you sure you want to remove %s from %s ?', array($site->get('name'), $org_info->profile->name));
             $workflow = $member->removeMember();
             $workflow->wait();
             $this->workflowOutput($workflow);
             break;
         case 'list':
         default:
             foreach ($memberships as $membership) {
                 if (isset($assoc_args['tag']) && !in_array($assoc_args['tag'], $membership->get('tags'))) {
                     continue;
                 }
                 $site = $membership->get('site');
                 $data_array = array('name' => null, 'id' => null, 'service_level' => null, 'framework' => null, 'created' => null, 'tags' => $membership->get('tags'));
                 foreach ($data_array as $key => $value) {
                     if ($value == null && isset($site->{$key})) {
                         $data_array[$key] = $site->{$key};
                     }
                 }
                 $data_array['created'] = date('Y-m-dTH:i:s', $data_array['created']);
                 $data[] = $data_array;
             }
             $this->output()->outputRecordList($data);
             break;
     }
 }
Example #2
0
 /**
  * List an organization's sites
  *
  * ## OPTIONS
  *
  * [--org=<id|name>]
  * : Organization UUID or name
  *
  * [--tag=<tag>]
  * : Tag name to filter sites list by
  *
  * [--add=<site>]
  * : Site to add to organization
  *
  * [--remove=<site>]
  * : Site to remove from organization
  *
  * @subcommand sites
  *
  */
 public function sites($args, $assoc_args)
 {
     $org_id = Input::orgid($assoc_args, 'org', null, array('allow_none' => false));
     $orgs = new UserOrganizationMemberships();
     $org = $orgs->get($org_id);
     $memberships = $org->site_memberships;
     if (isset($assoc_args['add'])) {
         $site = $this->sites->get(Input::sitename($assoc_args, 'add'));
         Terminus::confirm('Are you sure you want to add %s to %s ?', $assoc_args, array($site->get('name'), $org->get('name')));
         $memberships->addMember($site);
         Terminus::success('Added site!');
         return true;
     }
     if (isset($assoc_args['remove'])) {
         $site_id = $assoc_args['remove'];
         $member = $memberships->get($assoc_args['remove']);
         $site = $member->get('site');
         Terminus::confirm('Are you sure you want to remove %s from %s ?', $assoc_args, array($site->name, $org->get('name')));
         $member->removeMember();
         Terminus::success('Removed site!');
         return true;
     }
     $memberships = $org->getSites();
     foreach ($memberships as $membership) {
         if (isset($assoc_args['tag']) && !in_array($assoc_args['tag'], $membership->get('tags'))) {
             continue;
         }
         $site = $membership->get('site');
         $data_array = array('name' => null, 'id' => null, 'service_level' => null, 'framework' => null, 'created' => null, 'tags' => $membership->get('tags'));
         foreach ($data_array as $key => $value) {
             if ($value == null && isset($site->{$key})) {
                 $data_array[$key] = $site->{$key};
             }
         }
         $data_array['created'] = date('Y-m-dTH:i:s', $data_array['created']);
         $data[] = $data_array;
     }
     $this->outputter->outputRecordList($data);
 }
Example #3
0
 /**
  * Retrieves organization data for this user
  *
  * @return Organization[]
  */
 public function getOrganizations()
 {
     $organizations = $this->organizations->all();
     return $organizations;
 }
 /**
  * List an organization's team members
  *
  * ## OPTIONS
  *
  * [--org=<id|name>]
  * : Organization UUID or name
  *
  * @subcommand team
  */
 public function team($args, $assoc_args)
 {
     $org_id = Input::orgId(array('args' => $assoc_args, 'allow_none' => false));
     $orgs = new UserOrganizationMemberships();
     $org = $orgs->get($org_id);
     if (is_null($org)) {
         $message = 'The organization {org} is either invalid or you haven\'t';
         $message .= ' permission sufficient to access its data.';
         $this->failure($message, array('org' => $assoc_args['org']));
     }
     $org_info = $org->get('organization');
     $org_model = new Organization($org_info);
     $memberships = $org->user_memberships->all();
     $data = array();
     foreach ($memberships as $membership) {
         $member = $membership->get('user');
         $first_name = $last_name = null;
         if (isset($member->profile->firstname)) {
             $first_name = $member->profile->firstname;
         }
         if (isset($member->profile->lastname)) {
             $last_name = $member->profile->lastname;
         }
         $data[$member->id] = array('first' => $first_name, 'last' => $last_name, 'email' => $member->email, 'uuid' => $member->id);
     }
     $this->output()->outputRecordList($data);
     return $data;
 }
Example #5
0
 /**
  * List an organization's team members
  *
  * ## OPTIONS
  *
  * <list|add-member|remove-member|change-role>
  * : Options are list, add-member, remove-member, and change-role.
  *
  * [--org=<id|name>]
  * : Organization UUID or name
  *
  * [--member=<email>]
  * : Email of the member to add. Member will receive an invite
  *
  * [--role=<role>]
  * : Role for the new member to act as. Options are admin, team_member, and
  *   developer.
  *
  * @subcommand team
  */
 public function team($args, $assoc_args)
 {
     $action = array_pop($args);
     $org_id = $this->input()->orgId(array('args' => $assoc_args, 'allow_none' => false));
     $orgs = new UserOrganizationMemberships();
     $org = $orgs->get($org_id);
     if (is_null($org)) {
         $message = 'The organization {org} is either invalid or you haven\'t';
         $message .= ' permission sufficient to access its data.';
         $this->failure($message, array('org' => $assoc_args['org']));
     }
     $org_info = $org->get('organization');
     $org_model = new Organization($org_info);
     $role_choices = ['unprivileged', 'admin'];
     switch ($action) {
         case 'add-member':
             $email = $this->input()->string(['args' => $assoc_args, 'key' => 'member', 'message' => 'What is the email address of the user to be added?']);
             $can_change_management = $org_model->getFeature('change_management');
             var_dump($can_change_management);
             $role = $this->input()->orgRole(['args' => $assoc_args, 'can_change_management' => $can_change_management, 'return_value' => true, 'key' => 'role', 'message' => 'Select a role for your new member.']);
             $workflow = $org->user_memberships->addMember($email, $role);
             $workflow->wait();
             $this->workflowOutput($workflow);
             break;
         case 'remove-member':
             $member = $this->input()->orgMember(['args' => $assoc_args, 'autoselect_solo' => false, 'can_pick_self' => false, 'message' => 'Please select a member to remove', 'org' => $org]);
             $workflow = $member->removeMember();
             $workflow->wait();
             $this->workflowOutput($workflow);
             break;
         case 'change-role':
             $member = $this->input()->orgMember(['args' => $assoc_args, 'autoselect_solo' => false, 'message' => 'Please select a member to update', 'org' => $org]);
             if ($org_model->getFeature('change_management')) {
                 $role_choices[] = 'team_member';
                 $role_choices[] = 'developer';
             }
             $can_change_management = $org_model->getFeature('change_management');
             $role = $this->input()->orgRole(['args' => $assoc_args, 'can_change_management' => $can_change_management, 'return_value' => true, 'key' => 'role', 'message' => 'Select a role for this member.']);
             $workflow = $member->setRole($role);
             $this->workflowOutput($workflow);
             break;
         case 'list':
         default:
             $memberships = $org->user_memberships->all();
             $data = [];
             foreach ($memberships as $membership) {
                 $member = $membership->get('user');
                 $first_name = $last_name = null;
                 if (isset($member->profile->firstname)) {
                     $first_name = $member->profile->firstname;
                 }
                 if (isset($member->profile->lastname)) {
                     $last_name = $member->profile->lastname;
                 }
                 $data[$member->id] = ['first' => $first_name, 'last' => $last_name, 'email' => $member->email, 'role' => $membership->get('role'), 'uuid' => $member->id];
             }
             $this->output()->outputRecordList($data);
             return $data;
     }
 }