Beispiel #1
0
 /**
  *
  * @SWG\Api(
  *   path="/team/{uuid}/invite",
  *   description="API for team actions",
  * @SWG\Operation(
  *    method="POST",
  *    type="Response",
  *    summary="Invite a user to a team.  You can only invite people who are not already on your team.",
  * @SWG\Parameter(
  *     name="uuid",
  *     description="UUID of the team",
  *     paramType="path",
  *     required=true,
  *     type="string"
  *     ),
  * @SWG\Parameter(
  *     name="email",
  *     description="The email address of the user you would like to invite",
  *     paramType="form",
  *     required=true,
  *     type="string"
  *     )
  *   )
  * )
  *
  * Invites a user to a team
  * @param string $uuid
  */
 private function team_invite($uuid = '')
 {
     $this->load->library('form_validation');
     $this->load->helper('notification');
     /* Only the team owner can invite people */
     $team = validate_team_uuid($uuid, true);
     validate_team_read($team->id);
     /* Validate that they are the team owner */
     validate_team_owner($team->id, get_user_id());
     /* Validate that they have a valid subscription and can add a team */
     validate_user_add(get_user_id());
     $this->form_validation->set_rules('email', 'Email', 'required|trim|xss_clean|valid_email');
     if ($this->form_validation->run() == FALSE) {
         json_error('There was a problem with your submission: ' . validation_errors(' ', ' '));
     } else {
         $email = $this->post('email', TRUE);
         /* Look to see if there is an existing invite and resend it */
         $invite = $this->Team_Invite->get_for_email_team($email, $team->id);
         $invite_id = 0;
         if ($invite && !$invite->user_id) {
             $invite_id = $invite->id;
             $key = $invite->key;
         } else {
             $key = random_string('unique');
             $invite_id = $this->Team_Invite->add(array('email' => $email, 'team_id' => $team->id, 'key' => $key));
         }
         notify_team_invite($invite_id, get_user_id());
         json_success("User invited successfully", array('invite_id' => $invite_id, 'email' => $email, 'key' => $key));
     }
 }
Beispiel #2
0
 /**
  *
  * @SWG\Api(
  *   path="/project/{uuid}/invite",
  *   description="API for project actions",
  * @SWG\Operation(
  *    method="POST",
  *    type="ProjectInvite",
  *    summary="Invite a user to a project.  You can either invite a member of your team by passing their uuid or by sending them an external email",
  * @SWG\Parameter(
  *     name="uuid",
  *     description="UUID of the project",
  *     paramType="path",
  *     required=true,
  *     type="string"
  *     ),
  * @SWG\Parameter(
  *     name="user_uuid",
  *     description="The uuid of the user you would like to invite (optional)",
  *     paramType="form",
  *     required=false,
  *     type="string"
  *     ),
  * @SWG\Parameter(
  *     name="email",
  *     description="The email address of the external user you would like to invite (optional)",
  *     paramType="form",
  *     required=false,
  *     type="string"
  *     ),
  *   )
  * )
  *
  * Invites a user to a project
  * @param string $uuid
  */
 private function project_invite($uuid = '')
 {
     $this->load->helper('notification');
     $project = validate_project_uuid($uuid);
     /* Validate that the team owner has a valid subscription or free trial */
     validate_team_read($project->team_id);
     /* Validate that they are the team owner */
     validate_team_owner($project->team_id, get_user_id());
     $user_uuid = $this->post('user_uuid', TRUE);
     $email = $this->post('email', TRUE);
     /* Validate that they have a valid subscription and can add a project */
     validate_user_add(get_user_id(), $user_uuid);
     if ($email) {
         /** Look to see if there is an existing invite and resend it */
         $invite = $this->Project_Invite->get_for_email_project($email, $project->id);
         $invite_id = 0;
         if ($invite && !$invite->user_id) {
             $invite_id = $invite->id;
             $key = $invite->key;
         } else {
             $key = random_string('unique');
             $invite_id = $this->Project_Invite->add(array('email' => $email, 'project_id' => $project->id, 'key' => $key));
         }
         notify_project_invite_new_user($invite_id, get_user_id());
         json_success("User invited successfully", array('invite_id' => $invite_id, 'email' => $email, 'key' => $key));
         exit;
     } else {
         if ($user_uuid) {
             $user = validate_user_uuid($user_uuid);
             /* Validate that the user is on the project */
             if (!$this->User->is_on_team(get_team_id(), $user->id)) {
                 json_error('The user you are inviting is not on your team.  Please invite them to your team first.');
                 exit;
             }
             $invite = $this->Project_Invite->get_for_user_id_project($user->id, $project->id);
             if ($invite) {
                 $invite_id = $invite->id;
                 $key = $invite->key;
             } else {
                 $key = random_string('unique');
                 $invite_id = $this->Project_Invite->add(array('project_id' => $project->id, 'user_id' => $user->id, 'email' => $user->email, 'key' => $key));
             }
             notify_project_invite_new_user($invite_id, get_user_id());
             json_success("User invited successfully", array('invite_id' => $invite_id, 'email' => $email, 'key' => $key));
             exit;
         }
     }
     json_error("You must provide either a user id or an email address to invite to this project.");
 }
Beispiel #3
0
 private function validate_invite($user = '')
 {
     $this->load->model(array('Team', 'Project'));
     $invite = null;
     $user_uuid = '';
     $user_id = '';
     if ($user) {
         $user_uuid = $user->uuid;
         $user_id = $user->id;
     }
     $invite_key = $this->post('invite_key', TRUE);
     $invite_type = $this->post('invite_type', TRUE);
     if ($invite_key && $invite_type) {
         /* Team Invite */
         if ($invite_type == INVITE_TYPE_TEAM) {
             $invite = $this->Team_Invite->load_by_key($invite_key);
             validate_invite($invite);
             /* Validate that there is room to join the team */
             $team = $this->Team->load_fields($invite->team_id, 'owner_id');
             validate_user_add($team->owner_id);
         } else {
             $invite = $this->Project_Invite->load_by_key($invite_key);
             validate_invite($invite, $user_id);
             /* Validate that there is room to join the team */
             $project = $this->Project->load($invite->project_id);
             $team = $this->Team->load_fields($project->team_id, 'owner_id');
             validate_user_add($team->owner_id, $user_uuid);
         }
     }
     return $invite;
 }