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!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; }