public function postCreate()
 {
     // create a single model
     //
     $projectInvitation = new ProjectInvitation(array('project_uid' => Input::get('project_uid'), 'invitation_key' => GUID::create(), 'inviter_uid' => Input::get('inviter_uid'), 'invitee_name' => Input::get('invitee_name'), 'email' => Input::get('email')));
     $user = User::getByEmail(Input::get('email'));
     if ($user) {
         if (ProjectMembership::where('user_uid', '=', $user->user_uid)->where('project_uid', '=', Input::get('project_uid'))->where('delete_date', '=', null)->first()) {
             return Response::json(array('error' => array('message' => Input::get('invitee_name') . ' is already a member')), 409);
         }
     }
     $invite = ProjectInvitation::where('project_uid', '=', Input::get('project_uid'))->where('email', '=', Input::get('email'))->where('accept_date', '=', null)->where('decline_date', '=', null)->first();
     if ($invite) {
         return Response::json(array('error' => array('message' => Input::get('invitee_name') . ' already has a pending invitation')), 409);
     }
     // Model valid?
     //
     if ($projectInvitation->isValid()) {
         $projectInvitation->save();
         $projectInvitation->send(Input::get('confirm_route'), Input::get('register_route'));
         return $projectInvitation;
     } else {
         $errors = $projectInvitation->errors();
         return Response::make($errors->toJson(), 409);
     }
 }
示例#2
0
 public function getMemberships()
 {
     return ProjectMembership::where('project_uid', '=', $this->project_uid)->get();
 }
 public function deleteMembership($projectUid, $userUid)
 {
     $projectMembership = ProjectMembership::where('project_uid', '=', $projectUid)->where('user_uid', '=', $userUid)->first();
     $projectMembership->delete();
     return $projectMembership;
 }
 public function getProjectMemberships($userUid)
 {
     $projectMemberships = ProjectMembership::where('user_uid', '=', $userUid)->get();
     return $projectMemberships;
 }
示例#5
0
 public function isProjectAdmin($uid)
 {
     // check project membership for this user
     //
     $projectMemberships = ProjectMembership::where('user_uid', '=', $this->user_uid)->get();
     foreach ($projectMemberships as $projectMembership) {
         if ($projectMembership->project_uid == $uid && $projectMembership->admin_flag == 1) {
             if (!$projectMembership->delete_date) {
                 return true;
             }
         }
     }
     return false;
 }
 public function deleteMembership($projectUid, $userUid)
 {
     $projectMembership = ProjectMembership::where('project_uid', '=', $projectUid)->where('user_uid', '=', $userUid)->first();
     return ProjectMembershipsController::deleteIndex($projectMembership->membership_uid);
 }
示例#7
0
 public function getParasoftPermissionStatus($package, $project, $user)
 {
     // No project provided
     //
     if (!$project) {
         return Response::json(array('status' => 'no_project'), 404);
     }
     // Current user is the project owner
     //
     if ($user->user_uid === $project->owner['user_uid']) {
         $permission_code = $this->getParasoftPermissionCode();
         // check for parasoft c test permission
         //
         $up = UserPermission::where('user_uid', '=', $user->user_uid)->where('permission_code', '=', $permission_code)->first();
         // user has permission
         //
         if ($up && $up->status === 'granted') {
             // user parasoft permission is bound to this project
             //
             if (UserPermissionProject::where('user_permission_uid', '=', $up->user_permission_uid)->where('project_uid', '=', $project->project_uid)->first()) {
                 $permission = Permission::where('permission_code', '=', $permission_code)->first();
                 if (UserPolicy::where('user_uid', '=', $user->user_uid)->where('policy_code', '=', $permission->policy_code)->where('accept_flag', '=', 1)->first()) {
                     return Response::json(array('status' => 'granted', 'user_permission_uid' => $up->user_permission_uid), 200);
                 } else {
                     return Response::json(array('status' => 'no_user_policy', 'policy' => $permission->policy, 'policy_code' => $permission->policy_code), 404);
                 }
             } else {
                 // not bound, trigger user prompt on front end
                 //
                 return Response::json(array('status' => 'project_unbound', 'user_permission_uid' => $up->user_permission_uid), 404);
             }
             // user does not have permission
             //
         } else {
             return Response::json(array('status' => 'no_permission'), 401);
         }
         // current user is not the project owner
         //
     } else {
         // check that current user is a project member
         //
         $pm = ProjectMembership::where('user_uid', '=', $user->user_uid)->where('project_uid', '=', $project->project_uid)->first();
         if (!$pm) {
             return Response::json(array('status' => 'no_project_membership'), 401);
         }
         // c test
         //
         $permission_code = $this->getParasoftPermissionCode();
         // check for parasoft c test permission
         //
         $op = UserPermission::where('user_uid', '=', $project->owner['user_uid'])->where('permission_code', '=', $permission_code)->first();
         // owner has permission
         //
         if ($op && $op->status === 'granted') {
             // user parasoft permission is bound to this project
             //
             if (UserPermissionProject::where('user_permission_uid', '=', $op->user_permission_uid)->where('project_uid', '=', $project->project_uid)->first()) {
                 $permission = Permission::where('permission_code', '=', $permission_code)->first();
                 if (UserPolicy::where('user_uid', '=', $user->user_uid)->where('policy_code', '=', $permission->policy_code)->where('accept_flag', '=', 1)->first()) {
                     return Response::json(array('status' => 'granted', 'user_permission_uid' => $op->user_permission_uid), 200);
                 } else {
                     return Response::json(array('status' => 'no_user_policy', 'policy' => $permission->policy, 'policy_code' => $permission->policy_code), 404);
                 }
             } else {
                 // not bound, trigger user prompt on front end
                 //
                 return Response::json(array('status' => 'member_project_unbound'), 404);
             }
             // owner does not have permission
             //
         } else {
             return Response::json(array('status' => 'owner_no_permission'), 401);
         }
     }
 }