diff --git a/app/controllers/ExperimentController.php b/app/controllers/ExperimentController.php index 499327d33..3a3dcdacf 100755 --- a/app/controllers/ExperimentController.php +++ b/app/controllers/ExperimentController.php @@ -73,9 +73,10 @@ public function createSubmit() "allowedFileSize" => $allowedFileSize ); - $users = SharingUtilities::getAllUserProfiles($_POST['project'], ResourceType::PROJECT); + $users = SharingUtilities::getProfilesForSharedUsers($_POST['project'], ResourceType::PROJECT); + $owner = array(); - return View::make("experiment/create-complete", array("expInputs" => $experimentInputs, "users" => json_encode($users))); + return View::make("experiment/create-complete", array("expInputs" => $experimentInputs, "users" => json_encode($users), "owner" => json_encode($owner))); } else if (isset($_POST['save']) || isset($_POST['launch'])) { $expId = ExperimentUtilities::create_experiment(); @@ -90,7 +91,7 @@ public function createSubmit() go directly to experiment summary page.

'); }*/ - $users = SharingUtilities::getAllUserProfiles($expId, ResourceType::EXPERIMENT); + $users = SharingUtilities::getProfilesForSharedUsers($expId, ResourceType::EXPERIMENT); return Redirect::to('experiment/summary?expId=' . $expId); } else return Redirect::to("home")->with("message", "Something went wrong here. Please file a bug report using the link in the Help menu."); @@ -135,6 +136,12 @@ public function summary() $users = SharingUtilities::getProfilesForSharedUsers(Input::get("expId"), ResourceType::EXPERIMENT); + $owner = array(); + if (strcmp(Session::get("username"), $experiment->userName) !== 0) { + $owner[$experiment->userName] = $users[$experiment->userName]; + $users = array_diff_key($users, $owner); + } + $data = array( "expId" => Input::get("expId"), "experiment" => $experiment, @@ -142,7 +149,9 @@ public function summary() "jobDetails" => $jobDetails, "expVal" => $expVal, "autoRefresh"=> $autoRefresh, - "users" => json_encode($users) + "users" => json_encode($users), + "owner" => json_encode($owner), + "can_write" => SharingUtilities::userCanWrite(Session::get("username"), $experiment->experimentId, ResourceType::EXPERIMENT) ); if( Input::has("dashboard")) { @@ -199,47 +208,58 @@ public function expChange() public function editView() { - $queueDefaults = array("queueName" => Config::get('pga_config.airavata')["queue-name"], - "nodeCount" => Config::get('pga_config.airavata')["node-count"], - "cpuCount" => Config::get('pga_config.airavata')["total-cpu-count"], - "wallTimeLimit" => Config::get('pga_config.airavata')["wall-time-limit"] - ); + if (SharingUtilities::userCanWrite(Session::get("username"), $_GET['expId'], ResourceType::EXPERIMENT) === true) { + $queueDefaults = array("queueName" => Config::get('pga_config.airavata')["queue-name"], + "nodeCount" => Config::get('pga_config.airavata')["node-count"], + "cpuCount" => Config::get('pga_config.airavata')["total-cpu-count"], + "wallTimeLimit" => Config::get('pga_config.airavata')["wall-time-limit"] + ); - $experiment = ExperimentUtilities::get_experiment($_GET['expId']); - $expVal = ExperimentUtilities::get_experiment_values($experiment); - $expVal["jobState"] = ExperimentUtilities::get_job_status($experiment); + $experiment = ExperimentUtilities::get_experiment($_GET['expId']); + $expVal = ExperimentUtilities::get_experiment_values($experiment); + $expVal["jobState"] = ExperimentUtilities::get_job_status($experiment); - $computeResources = CRUtilities::create_compute_resources_select($experiment->executionId, $expVal['scheduling']->resourceHostId); - - $clonedExp = false; $savedExp = false; - if( Input::has("clonedExp")) - $clonedExp = true; - if( Input::has("savedExp")) - $savedExp = true; - - $experimentInputs = array( - "clonedExp" => $clonedExp, - "savedExp" => $savedExp, - "disabled" => ' ', - "experimentName" => $experiment->experimentName, - "experimentDescription" => $experiment->description, - "application" => $experiment->executionId, - "autoSchedule" => $experiment->userConfigurationData->airavataAutoSchedule, - "userDN" => $experiment->userConfigurationData->userDN, - "allowedFileSize" => Config::get('pga_config.airavata')["server-allowed-file-size"], - 'experiment' => $experiment, - "queueDefaults" => $queueDefaults, - 'computeResources' => $computeResources, - "resourceHostId" => $expVal['scheduling']->resourceHostId, - 'project' => $experiment->projectId, - 'expVal' => $expVal, - 'cloning' => true, - 'advancedOptions' => Config::get('pga_config.airavata')["advanced-experiment-options"] - ); + $computeResources = CRUtilities::create_compute_resources_select($experiment->executionId, $expVal['scheduling']->resourceHostId); + + $clonedExp = false; $savedExp = false; + if( Input::has("clonedExp")) + $clonedExp = true; + if( Input::has("savedExp")) + $savedExp = true; + + $experimentInputs = array( + "clonedExp" => $clonedExp, + "savedExp" => $savedExp, + "disabled" => ' ', + "experimentName" => $experiment->experimentName, + "experimentDescription" => $experiment->description, + "application" => $experiment->executionId, + "autoSchedule" => $experiment->userConfigurationData->airavataAutoSchedule, + "userDN" => $experiment->userConfigurationData->userDN, + "allowedFileSize" => Config::get('pga_config.airavata')["server-allowed-file-size"], + 'experiment' => $experiment, + "queueDefaults" => $queueDefaults, + 'computeResources' => $computeResources, + "resourceHostId" => $expVal['scheduling']->resourceHostId, + 'project' => $experiment->projectId, + 'expVal' => $expVal, + 'cloning' => true, + 'advancedOptions' => Config::get('pga_config.airavata')["advanced-experiment-options"] + ); + + $users = SharingUtilities::getProfilesForSharedUsers($_GET['expId'], ResourceType::EXPERIMENT); - $users = SharingUtilities::getAllUserProfiles($_GET['expId'], ResourceType::EXPERIMENT); + $owner = array(); + if (strcmp(Session::get("username"), $experiment->userName) !== 0) { + $owner[$experiment->userName] = $users[$experiment->userName]; + $users = array_diff_key($users, $owner); + } - return View::make("experiment/edit", array("expInputs" => $experimentInputs, "users" => json_encode($users))); + return View::make("experiment/edit", array("expInputs" => $experimentInputs, "users" => json_encode($users), "owner" => json_encode($owner))); + } + else { + Redirect::to("experiment/summary?expId=" . $experiment->experimentId)->with("error", "You do not have permission to edit this experiment"); + } } public function cloneExperiment() @@ -258,22 +278,24 @@ public function cloneExperiment() public function editSubmit() { - if (isset($_POST['save']) || isset($_POST['launch'])) { - $experiment = ExperimentUtilities::get_experiment(Input::get('expId')); // update local experiment variable - $updatedExperiment = ExperimentUtilities::apply_changes_to_experiment($experiment, Input::all()); + if (SharingUtilities::userCanWrite(Session::get("username"), Input::get('expId'), ResourceType::EXPERIMENT)) { + if (isset($_POST['save']) || isset($_POST['launch'])) { + $experiment = ExperimentUtilities::get_experiment(Input::get('expId')); // update local experiment variable + $updatedExperiment = ExperimentUtilities::apply_changes_to_experiment($experiment, Input::all()); - ExperimentUtilities::update_experiment($experiment->experimentId, $updatedExperiment); + ExperimentUtilities::update_experiment($experiment->experimentId, $updatedExperiment); - if (isset($_POST['save'])) { - $experiment = ExperimentUtilities::get_experiment(Input::get('expId')); // update local experiment variable - } - if (isset($_POST['launch'])) { - ExperimentUtilities::launch_experiment($experiment->experimentId); - } + if (isset($_POST['save'])) { + $experiment = ExperimentUtilities::get_experiment(Input::get('expId')); // update local experiment variable + } + if (isset($_POST['launch'])) { + ExperimentUtilities::launch_experiment($experiment->experimentId); + } - return Redirect::to('experiment/summary?expId=' . $experiment->experimentId); - } else - return View::make("home"); + return Redirect::to('experiment/summary?expId=' . $experiment->experimentId); + } else + return View::make("home"); + } } public function getQueueView() @@ -305,14 +327,48 @@ public function browseView() $expContainer = ExperimentUtilities::get_expsearch_results_with_pagination(Input::all(), $this->limit, ($pageNo - 1) * $this->limit); $experimentStates = ExperimentUtilities::getExpStates(); + + $can_write = array(); + foreach ($expContainer as $experiment) { + $can_write[$experiment['experiment']->experimentId] = SharingUtilities::userCanWrite(Session::get("username"), $experiment['experiment']->experimentId, ResourceType::EXPERIMENT); + } + return View::make('experiment/browse', array( 'input' => Input::all(), 'pageNo' => $pageNo, 'limit' => $this->limit, 'expStates' => $experimentStates, - 'expContainer' => $expContainer + 'expContainer' => $expContainer, + 'can_write' => $can_write )); } + + /** + * Generate JSON containing permissions information for this project. + * + * This function retrieves the user profile and permissions for every user + * other than the client that has access to the project. In the event that + * the project does not exist, return an error message. + */ + public function sharedUsers() + { + if (Session::has("authz-token") && array_key_exists('resourceId', $_GET)) { + return Response::json(SharingUtilities::getProfilesForSharedUsers($_GET['resourceId'], ResourceType::EXPERIMENT)); + } + else { + return Response::json(array("error" => "Error: No project specified")); + } + } + + public function unsharedUsers() + { + if (Session::has("authz-token") && array_key_exists('resourceId', $_GET)) { + return Response::json(SharingUtilities::getProfilesForUnsharedUsers($_GET['resourceId'], ResourceType::EXPERIMENT)); + } + else { + return Response::json(array("error" => "Error: No experiment specified")); + } + } } ?> diff --git a/app/controllers/ProjectController.php b/app/controllers/ProjectController.php index 6b874f2f3..966f36a39 100755 --- a/app/controllers/ProjectController.php +++ b/app/controllers/ProjectController.php @@ -26,8 +26,7 @@ public function __construct() public function createView() { $users = SharingUtilities::getAllUserProfiles(); - //var_dump($users);exit; - return View::make("project/create", array("users" => json_encode($users))); + return View::make("project/create", array("users" => json_encode($users), "owner" => json_encode(array()))); } public function createSubmit() @@ -45,10 +44,36 @@ public function summary() if (Input::has("projId")) { Session::put("projId", Input::get("projId")); + $project = ProjectUtilities::get_project(Input::get('projId')); + $users = SharingUtilities::getProfilesForSharedUsers(Input::get('projId'), ResourceType::PROJECT); + $owner = array(); + if (strcmp(Session::get("username"), $project->owner) !== 0) { + $owner[$project->owner] = $users[$project->owner]; + $users = array_diff_key($users, $owner); + } + + $experiments = ProjectUtilities::get_experiments_in_project(Input::get("projId")); + + $experiment_can_write = array(); + foreach($experiments as $experiment) { + if (SharingUtilities::userCanWrite(Session::get("username"), $experiment->experimentId, ResourceType::EXPERIMENT)) { + $experiment_can_write[$experiment->experimentId] = true; + } + else { + $experiment_can_write[$experiment->experimentId] = false; + } + } + return View::make("project/summary", - array("projectId" => Input::get("projId"), "users" => json_encode($users))); + array("projectId" => Input::get("projId"), + "experiments" => $experiments, + "users" => json_encode($users), + "owner" => json_encode($owner), + "project_can_write" => SharingUtilities::userCanWrite(Session::get("username"), Input::get("projId"), ResourceType::PROJECT), + "experiment_can_write" => $experiment_can_write + )); } else return Redirect::to("home"); } @@ -56,20 +81,33 @@ public function summary() public function editView() { if (Input::has("projId")) { - $users = SharingUtilities::getAllUserProfiles(Input::get('projId'), ResourceType::PROJECT); - - return View::make("project/edit", - array("projectId" => Input::get("projId"), - "project" => ProjectUtilities::get_project($_GET['projId']), - "users" => json_encode($users) - )); + if (SharingUtilities::userCanWrite(Session::get("username"), Input::get("projId"), ResourceType::PROJECT)) { + $project = ProjectUtilities::get_project($_GET['projId']); + $users = SharingUtilities::getProfilesForSharedUsers(Input::get('projId'), ResourceType::PROJECT); + $owner = array(); + + if (strcmp(Session::get("username"), $project->owner) !== 0) { + $owner[$project->owner] = $users[$project->owner]; + $users = array_diff_key($users, $owner); + } + + return View::make("project/edit", + array("projectId" => Input::get("projId"), + "project" => $project, + "users" => json_encode($users), + "owner" => json_encode($owner) + )); + } + else { + return Redirect::to('project/summary?projId=' . Input::get("projId"))->with("error", "You do not have permission to edit this project."); + } } else return Redirect::to("home"); } public function editSubmit() { - if (isset($_POST['save'])) { + if (isset($_POST['save']) && SharingUtilities::userCanWrite(Session::get("username"), Input::get("projectId"), ResourceType::PROJECT)) { $projectDetails = array(); $projectDetails["owner"] = Session::get("username"); $projectDetails["name"] = Input::get("project-name"); @@ -104,10 +142,22 @@ public function browseView() $projects = ProjectUtilities::get_all_user_accessible_projects_with_pagination($this->limit, ($pageNo - 1) * $this->limit); } + $can_write = array(); + $user = Session::get("username"); + foreach($projects as $project) { + if (SharingUtilities::userCanWrite($user, $project->projectID, ResourceType::PROJECT)) { + $can_write[$project->projectID] = true; + } + else { + $can_write[$project->projectID] = false; + } + } + return View::make('project/browse', array( 'pageNo' => $pageNo, 'limit' => $this->limit, - 'projects' => $projects + 'projects' => $projects, + 'can_write' => $can_write )); } @@ -120,9 +170,8 @@ public function browseView() */ public function sharedUsers() { - $response = array(); - if (Input::has('projId')) { - return Response::json(SharingUtilities::getProfilesForSharedUsers()); + if (Session::has("authz-token") && array_key_exists('resourceId', $_GET)) { + return Response::json(SharingUtilities::getProfilesForSharedUsers($_GET['resourceId'], ResourceType::PROJECT)); } else { return Response::json(array("error" => "Error: No project specified")); @@ -131,8 +180,8 @@ public function sharedUsers() public function unsharedUsers() { - if (Input::has('projId')) { - return Response::json(SharingUtilities::getProfilesForUnsharedUsers); + if (Session::has("authz-token") && array_key_exists('resourceId', $_GET)) { + return Response::json(SharingUtilities::getProfilesForUnsharedUsers($_GET['resourceId'], ResourceType::PROJECT)); } else { return Response::json(array("error" => "Error: No project specified")); diff --git a/app/libraries/ExperimentUtilities.php b/app/libraries/ExperimentUtilities.php old mode 100644 new mode 100755 index e081e3b8e..9cc63a572 --- a/app/libraries/ExperimentUtilities.php +++ b/app/libraries/ExperimentUtilities.php @@ -634,11 +634,8 @@ public static function clone_experiment($expId) Airavata::updateExperiment(Session::get('authz-token'), $cloneId, $experiment); $share = SharingUtilities::getAllUserPermissions($expId, ResourceType::EXPERIMENT); - $share[Session::get("username")] = array("read" => true, "write" => true); - foreach ($share as $uid => $perms) { - $share[$uid] = (object) $perms; - } - ExperimentUtilities::share_experiment($cloneId, $share); + $share[Session::get('username')] = ["read" => true, "write" => true]; + ExperimentUtilities::share_experiment($cloneId, json_decode(json_encode($share))); return $cloneId; } catch (InvalidRequestException $ire) { @@ -824,11 +821,7 @@ public static function create_experiment() CommonUtilities::print_error_message('AiravataSystemException!

' . $ase->getMessage()); } - $share = json_decode($share); - $share->{Session::get('username')} = new stdClass(); - $share->{Session::get('username')}->read = true; - $share->{Session::get('username')}->write = true; - ExperimentUtilities::share_experiment($expId, $share); + ExperimentUtilities::share_experiment($expId, json_decode($share)); return $expId; } @@ -1132,12 +1125,14 @@ public static function get_expsearch_results_with_pagination($inputs, $limit, $o $expContainer = array(); $expNum = 0; foreach ($experiments as $experiment) { - $expValue = ExperimentUtilities::get_experiment_values($experiment, true); - $expContainer[$expNum]['experiment'] = $experiment; - if ($expValue["experimentStatusString"] == "FAILED") - $expValue["editable"] = false; - $expContainer[$expNum]['expValue'] = $expValue; - $expNum++; + if (SharingUtilities::userCanRead(Session::get('username'), $experiment->experimentId, ResourceType::EXPERIMENT)) { + $expValue = ExperimentUtilities::get_experiment_values($experiment, true); + $expContainer[$expNum]['experiment'] = $experiment; + if ($expValue["experimentStatusString"] == "FAILED") + $expValue["editable"] = false; + $expContainer[$expNum]['expValue'] = $expValue; + $expNum++; + } } return $expContainer; @@ -1331,6 +1326,10 @@ public static function create_application_select($id = null, $editable = true) */ private static function share_experiment($expId, $users) { $experiment = ExperimentUtilities::get_experiment($expId); + $users->{$experiment->userName} = new stdClass(); + $users->{$experiment->userName}->read = true; + $users->{$experiment->userName}->write = true; + $wadd = array(); $wrevoke = array(); $radd = array(); diff --git a/app/libraries/ProjectUtilities.php b/app/libraries/ProjectUtilities.php old mode 100644 new mode 100755 index c75867fdc..ca8081e25 --- a/app/libraries/ProjectUtilities.php +++ b/app/libraries/ProjectUtilities.php @@ -127,11 +127,7 @@ public static function create_project() CommonUtilities::print_error_message('AiravataSystemException!

' . $ase->getMessage()); } - $share = json_decode($share); - $share->{Session::get('username')} = new stdClass(); - $share->{Session::get('username')}->read = true; - $share->{Session::get('username')}->write = true; - ProjectUtilities::share_project($projectId, $share); + ProjectUtilities::share_project($projectId, json_decode($share)); return $projectId; } @@ -150,6 +146,12 @@ public static function create_default_project($username) try { $projectId = Airavata::createProject(Session::get('authz-token'), Config::get('pga_config.airavata')['gateway-id'], $project); + $share = new stdClass(); + $share->{$username} = new stdClass(); + $share->{$username}->read = true; + $share->{$username}->write = true; + ProjectUtilities::share_project($projectId, $share); + } catch (InvalidRequestException $ire) { CommonUtilities::print_error_message('InvalidRequestException!

' . $ire->getMessage()); } catch (AiravataClientException $ace) { @@ -184,6 +186,12 @@ public static function get_experiments_in_project($projectId) CommonUtilities::print_error_message('TTransportException!

' . $tte->getMessage()); } + for($i = 0; $i < count($experiments); $i++) { + if (!SharingUtilities::userCanRead(Session::get("username"), $experiments[$i]->experimentId, ResourceType::EXPERIMENT)) { + array_splice($experiments, $i, 1); + } + } + return $experiments; } @@ -288,6 +296,11 @@ public static function get_proj_search_results_with_pagination($searchKey, $sear * @param $users A map of username => {read_permission, write_permission} */ private static function share_project($projectId, $users) { + $project = Airavata::getProject(Session::get("authz-token"), $projectId); + $users->{$project->owner} = new stdClass(); + $users->{$project->owner}->read = true; + $users->{$project->owner}->write = true; + $wadd = array(); $wrevoke = array(); $ewrevoke = array(); diff --git a/app/libraries/SharingUtilities.php b/app/libraries/SharingUtilities.php old mode 100644 new mode 100755 index 7b98f97d0..477cec5d4 --- a/app/libraries/SharingUtilities.php +++ b/app/libraries/SharingUtilities.php @@ -25,13 +25,31 @@ public static function resourceIsShared($resourceId, $dataResourceType) { * @return True if the user has read permission, false otherwise. */ public static function userCanRead($uid, $resourceId, $dataResourceType) { - if (WSIS::usernameExists($uid)) { - $read = GrouperUtilities::getAllAccessibleUsers($resourceId, $dataResourceType, ResourcePermissionType::READ); - return (array_key_exists($uid, $read) ? true : false); + $read = GrouperUtilities::getAllAccessibleUsers($resourceId, $dataResourceType, ResourcePermissionType::READ); + foreach($read as $user) { + if (strcmp($uid, $user) === 0) { + return true; + } } - else { - return false; + return false; + } + + /** + * Determine if the user has write privileges on the resource. + * + * @param $uid The user to check + * @param $resourceId Experiment or Project ID + * @param $dataResourceType e.g Airavata\Model\Group\ResourceType:PROJECT,Airavata\Model\Group\ResourceType:EXPERIMENT + * @return True if the user has write permission, false otherwise. + */ + public static function userCanWrite($uid, $resourceId, $dataResourceType) { + $write = GrouperUtilities::getAllAccessibleUsers($resourceId, $dataResourceType, ResourcePermissionType::WRITE); + foreach($write as $user) { + if (strcmp($uid, $user) === 0) { + return true; + } } + return false; } /** diff --git a/app/routes.php b/app/routes.php old mode 100644 new mode 100755 index f9b95a59d..6008c1555 --- a/app/routes.php +++ b/app/routes.php @@ -71,6 +71,10 @@ Route::post("project/browse", "ProjectController@browseView"); +Route::get("project/shared-users", "ProjectController@sharedUsers"); + +Route::get("project/unshared-users", "ProjectController@unsharedUsers"); + /* * Experiment Routes */ @@ -97,6 +101,10 @@ Route::post("experiment/browse", "ExperimentController@browseView"); +Route::get("experiment/shared-users", "ExperimentController@sharedUsers"); + +Route::get("experiment/unshared-users", "ExperimentController@unsharedUsers"); + Route::get("download", function(){ if(Input::has("path") && (0 == strpos(Input::get("path"), Session::get('username')) || 0 == strpos(Input::get("path"), "/" . Session::get('username')))){ diff --git a/app/views/experiment/create-complete.blade.php b/app/views/experiment/create-complete.blade.php old mode 100644 new mode 100755 index c3976bbe7..7ae755a81 --- a/app/views/experiment/create-complete.blade.php +++ b/app/views/experiment/create-complete.blade.php @@ -46,6 +46,8 @@ @parent {{ HTML::script('js/sharing/sharing_utils.js') }} {{ HTML::script('js/sharing/share.js') }} diff --git a/app/views/experiment/edit.blade.php b/app/views/experiment/edit.blade.php index a991bd1a2..a4abe0ea8 100755 --- a/app/views/experiment/edit.blade.php +++ b/app/views/experiment/edit.blade.php @@ -54,6 +54,8 @@ @parent {{ HTML::script('js/sharing/sharing_utils.js') }} {{ HTML::script('js/sharing/share.js') }} diff --git a/app/views/partials/experiment-container.blade.php b/app/views/partials/experiment-container.blade.php index 4ecf3de1c..561063e6a 100644 --- a/app/views/partials/experiment-container.blade.php +++ b/app/views/partials/experiment-container.blade.php @@ -24,11 +24,11 @@ @foreach($expContainer as $experiment) - + - {{ $experiment['experiment']->name }} + {{ $experiment['experiment']->name }} - @if( $experiment['expValue']['editable']) + @if( $experiment['expValue']['editable'] and $can_write[$experiment['experiment']->experimentId] === true) @endif @@ -41,7 +41,7 @@ @endif - @if( !empty( explode("_", $experiment['experiment']->resourceHostId)[0] ) ) + @if( !empty( explode("_", $experiment['experiment']->resourceHostId)[0] ) ) {{ explode("_", $experiment['experiment']->resourceHostId)[0] }} @endif @@ -53,18 +53,18 @@ {{$experiment['expValue']['experimentStatusString'] }} - @if( isset( $dashboard)) + @if( isset( $dashboard)) @endif - + @endforeach - + @endif -@endif \ No newline at end of file +@endif diff --git a/app/views/partials/experiment-info.blade.php b/app/views/partials/experiment-info.blade.php index fa6a60527..3ca3340eb 100644 --- a/app/views/partials/experiment-info.blade.php +++ b/app/views/partials/experiment-info.blade.php @@ -192,7 +192,11 @@
+ @if($can_write === true) + @include('partials/sharing-display-body', array("form" => true)) + @else @include('partials/sharing-display-body', array("form" => false)) + @endif
@if( !isset( $dashboard)) @@ -225,6 +229,7 @@ class="btn btn-primary" Clone + @if($can_write === true) Edit + @endif @endif @@ -318,11 +324,17 @@ class="btn btn-default" @endif +@if($can_write === true) +@include('partials/sharing-form-modal') +@endif + @section('scripts') @parent {{ HTML::script('js/time-conversion.js')}} {{ HTML::script('js/sharing/sharing_utils.js') }} {{ HTML::script('js/sharing/share.js') }} diff --git a/app/views/partials/sharing-form-modal.blade.php b/app/views/partials/sharing-form-modal.blade.php index b66a66670..dee2036bf 100644 --- a/app/views/partials/sharing-form-modal.blade.php +++ b/app/views/partials/sharing-form-modal.blade.php @@ -10,7 +10,7 @@ @include('partials/sharing-form-body') diff --git a/app/views/project/browse.blade.php b/app/views/project/browse.blade.php index 4e68ddc4e..3b6e34843 100755 --- a/app/views/project/browse.blade.php +++ b/app/views/project/browse.blade.php @@ -107,9 +107,11 @@ class="glyphicon glyphicon-search"> Search name; ?> + @if($can_write[$project->projectID] === true) + @endif {{$project->owner}} @@ -143,4 +145,4 @@ class="glyphicon glyphicon-search"> Search @section('scripts') @parent {{ HTML::script('js/time-conversion.js')}} - @stop \ No newline at end of file + @stop diff --git a/app/views/project/edit.blade.php b/app/views/project/edit.blade.php index 6b3e49398..edd8ac980 100755 --- a/app/views/project/edit.blade.php +++ b/app/views/project/edit.blade.php @@ -62,7 +62,10 @@ class="form-control" @parent {{ HTML::script('js/sharing/sharing_utils.js') }} {{ HTML::script('js/sharing/share.js') }} + @stop diff --git a/app/views/project/summary.blade.php b/app/views/project/summary.blade.php index 1b59d2897..a307a6380 100755 --- a/app/views/project/summary.blade.php +++ b/app/views/project/summary.blade.php @@ -10,7 +10,6 @@
projectID); ?>

Project Summary @if( !isset($dashboard)) @@ -21,9 +20,11 @@

{{ $project->name }} + @if($project_can_write === true) + @endif

{{ $project->description }}

@@ -62,7 +63,7 @@ {{ $experiment->experimentName }} - @if( $expValues['editable']) + @if( $expValues['editable'] and $experiment_can_write[$experiment->experimentId] === true) @endif @@ -107,11 +108,12 @@ @stop @section('scripts') @parent -{{ HTML::script('js/time-conversion.js')}} +{{ HTML::script('js/time-conversion.js')}} {{ HTML::script('js/sharing/sharing_utils.js') }} {{ HTML::script('js/sharing/share.js') }} + @stop diff --git a/public/js/sharing/share.js b/public/js/sharing/share.js index d8e19fc98..956cec371 100755 --- a/public/js/sharing/share.js +++ b/public/js/sharing/share.js @@ -4,6 +4,8 @@ * @author Jeff Kinnison */ +var createThumbnails; + $(function() { var comparator_map, comparator, $original_shared_list, $revoke_list; comparator_map = { @@ -16,7 +18,7 @@ $(function() { /* Share box functions */ - var createTestData = function () { + createThumbnails = function () { var $users, $share, $user, share_settings; $users = $('#share-box-users'); @@ -29,7 +31,7 @@ $(function() { var data = users[user]; var access = access_enum.NONE; if (data.hasOwnProperty("access")) { - console.log("Found access parameter"); + //console.log("Found access parameter"); if (data.access.write) { access = access_enum.WRITE; } @@ -47,7 +49,7 @@ $(function() { $users.append($user); } else { - console.log("adding shared user"); + //console.log("adding shared user"); $user.addClass('share-box-share-item sharing-updated'); share_settings[user] = data.access; $share.append($user); @@ -55,23 +57,16 @@ $(function() { } } - // for (var group in dummy_group_data) { - // if (dummy_group_data.hasOwnProperty(group)) { - // data = dummy_group_data[group]; - // $group = createThumbnail(data.username, data.firstname, data.lastname, data.email, data.access); - // $group.addClass('group-thumbnail'); - // if (data.access === access_enum.NONE) { - // $group.addClass('share-box-users-item'); - // $users.append($group); - // } - // else { - // $group.addClass('share-box-share-item'); - // $group.find('.sharing-thumbnail-access').prop("disabled", false).show(); - // $group.find('.sharing-thumbnail-unshare').show(); - // $share.append($group); - // } - // } - // } + for (var o in owner) { + if (owner.hasOwnProperty(o)) { + var odata = owner[o]; + $owner = createThumbnail(o, odata.firstname, odata.lastname, odata.email, access_enum.OWNER, false); + $owner.find(".sharing-thumbnail-unshare").detach(); + $owner.addClass("share-box-share-item owner"); + $share.prepend($owner); + } + } + if ($share.children().length === 0) { $share.append($('

This has not been shared

')).addClass('text-align-center'); } @@ -89,18 +84,52 @@ $(function() { // Create, populate, and show the share box $('body').on('click', 'button#project-share, button#experiment-share', function(e) { - var $share_list; + var $share_list, ajax_data; e.stopPropagation(); e.preventDefault(); - $share_list = $('#shared-users').children(); + if ($('#share-box-users').find('.user-thumbnail').length === 0) { + ajax_data = $(e.target).data(); + + $('#share-box-users').addClass('text-align-center').text('Loading user list'); + + $.ajax({ + url: ajax_data.url, + method: 'get', + data: {resourceId: ajax_data.resourceId}, + dataType: "json", + error: function(xhr, status, error) { + $('#shared-users').addClass('text-align-center').text("Unable to load users from Airavata server."); + }, + success: function(data, status, xhr) { + var user, $user, $users; + $users = $('#share-box-users'); + $users.removeClass('text-align-center'); + $users.text(''); + for (user in data) { + if (data.hasOwnProperty(user)) { + $user = createThumbnail(user, data[user].firstname, data[user].lastname, data[user].email, access_enum.NONE, true); + $user.find('.sharing-thumbnail-access').hide(); + + $user.addClass('user-thumbnail'); + $user.addClass('share-box-users-item'); + $users.append($user); + } + } + } + }); + } + + $share_list = $('#shared-users').children(); if ($share_list.filter('.sharing-thumbnail').length > 0) { $share_list.sort(comparator); $share_list.each(function(index, element) { var $e; $e = $(element); - $e.find('.sharing-thumbnail-access-text').hide(); + if (!$e.hasClass('owner')) { + $e.find('.sharing-thumbnail-access-text').hide(); + } $e.find('.sharing-thumbnail-access').prop('disabled', false).show(); $e.find('.sharing-thumbnail-unshare').show(); $e.detach().appendTo($('#share-box-share')); @@ -307,5 +336,5 @@ $(function() { /* Set up the sharing interface */ - createTestData(); + createThumbnails(); }); diff --git a/public/js/sharing/sharing_utils.js b/public/js/sharing/sharing_utils.js index 5191de91a..550576a78 100644 --- a/public/js/sharing/sharing_utils.js +++ b/public/js/sharing/sharing_utils.js @@ -1,13 +1,15 @@ var access_enum = { NONE: 0, READ: 1, - WRITE: 2 + WRITE: 2, + OWNER: 3 }; var access_text = [ 'Cannot access', 'Can read', - 'Can write' + 'Can write', + 'Owner' ]; var createThumbnail = function(username, firstname, lastname, email, access, share) { @@ -30,7 +32,7 @@ var createThumbnail = function(username, firstname, lastname, email, access, sha access_text_current = access_text[access]; - if (access !== access_enum.NONE) { + if (access !== access_enum.NONE && access !== access_enum.OWNER) { data.access.read = true; data.currentaccess.read = true; }