airavata-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From scnakand...@apache.org
Subject [3/3] airavata-php-gateway git commit: AIRAVATA-2195 Use sharing API to figure out project owner
Date Tue, 29 Nov 2016 21:50:04 GMT
AIRAVATA-2195 Use sharing API to figure out project owner


Project: http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/repo
Commit: http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/commit/3a2de307
Tree: http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/tree/3a2de307
Diff: http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/diff/3a2de307

Branch: refs/heads/develop
Commit: 3a2de30726cdaa07bce260a02333f88b25b18887
Parents: 4d546cf
Author: Marcus Christie <machrist@iu.edu>
Authored: Tue Nov 29 16:02:47 2016 -0500
Committer: Marcus Christie <machrist@iu.edu>
Committed: Tue Nov 29 16:02:47 2016 -0500

----------------------------------------------------------------------
 app/controllers/ExperimentController.php | 38 ++++++++++++++-------------
 app/libraries/SharingUtilities.php       | 10 +++++++
 2 files changed, 30 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/3a2de307/app/controllers/ExperimentController.php
----------------------------------------------------------------------
diff --git a/app/controllers/ExperimentController.php b/app/controllers/ExperimentController.php
index 392383b..6d06aad 100755
--- a/app/controllers/ExperimentController.php
+++ b/app/controllers/ExperimentController.php
@@ -78,10 +78,9 @@ class ExperimentController extends BaseController
                 $owner = array();
 
                 $projectOwner = array();
-                $project = ProjectUtilities::get_project($_POST['project']);
-                // TODO: figure out the owner of the project using sharing API
-                if ($project != null && strcmp(Session::get("username"), $project->owner)
!== 0) {
-                    $projectOwner[$project->owner] = $users[$project->owner];
+                $sharedProjectOwner = SharingUtilities::getSharedResourceOwner($_POST['project'],
ResourceType::PROJECT);
+                if (strcmp(Session::get("username"), $sharedProjectOwner) !== 0) {
+                    $projectOwner[$sharedProjectOwner] = $users[$sharedProjectOwner];
                     $users = array_diff_key($users, $projectOwner);
                 }
 
@@ -170,18 +169,21 @@ class ExperimentController extends BaseController
             );
             if(Config::get('pga_config.airavata')["data-sharing-enabled"]){
                 $users = SharingUtilities::getProfilesForSharedUsers(Input::get("expId"),
ResourceType::EXPERIMENT);
+                $sharedProjectOwner = SharingUtilities::getSharedResourceOwner($experiment->projectId,
ResourceType::PROJECT);
 
                 $owner = array();
                 $projectOwner = array();
                 if (strcmp(Session::get("username"), $experiment->userName) !== 0) {
                     $owner[$experiment->userName] = $users[$experiment->userName];
-                    $users = array_diff_key($users, $owner);
                 }
-                // TODO: figure out the owner of the project using sharing API
-                if ($project != null && strcmp(Session::get("username"), $project->owner)
!== 0) {
-                    $projectOwner[$project->owner] = $users[$project->owner];
-                    $users = array_diff_key($users, $projectOwner);
+                if (strcmp(Session::get("username"), $sharedProjectOwner) !== 0) {
+                    $projectOwner[$sharedProjectOwner] = $users[$sharedProjectOwner];
                 }
+                // Subtract out the owner and project owner from list of users
+                $users = array_diff_key($users, $owner);
+                $users = array_diff_key($users, $projectOwner);
+                // If project owner is the same as owner, just show the owner, not the project
owner
+                $projectOwner = array_diff_key($projectOwner, $owner);
                 // Only allow editing sharing on the summary page if the owner
                 // and the experiment isn't editable. If the experiment is
                 // editable, the sharing can be edited on the edit page.
@@ -294,22 +296,22 @@ class ExperimentController extends BaseController
         if(Config::get('pga_config.airavata')["data-sharing-enabled"]){
             if (SharingUtilities::userCanWrite(Session::get("username"), $_GET['expId'],
ResourceType::EXPERIMENT) === true) {
                 $users = SharingUtilities::getProfilesForSharedUsers($_GET['expId'], ResourceType::EXPERIMENT);
+                $sharedProjectOwner = SharingUtilities::getSharedResourceOwner($experiment->projectId,
ResourceType::PROJECT);
 
                 $owner = array();
                 $projectOwner = array();
                 if (strcmp(Session::get("username"), $experiment->userName) !== 0) {
                     $owner[$experiment->userName] = $users[$experiment->userName];
-                    $users = array_diff_key($users, $owner);
-                }
-                // TODO: figure out the owner of the project using sharing API
-                $project = null;
-                if (SharingUtilities::userCanRead(Session::get("username"), $experiment->projectId,
ResourceType::PROJECT)) {
-                    $project = ProjectUtilities::get_project($experiment->projectId);
                 }
-                if ($project != null && strcmp(Session::get("username"), $project->owner)
!== 0) {
-                    $projectOwner[$project->owner] = $users[$project->owner];
-                    $users = array_diff_key($users, $projectOwner);
+                if (strcmp(Session::get("username"), $sharedProjectOwner) !== 0) {
+                    $projectOwner[$sharedProjectOwner] = $users[$sharedProjectOwner];
                 }
+                // Subtract out owner and project owner from list of users
+                $users = array_diff_key($users, $owner);
+                $users = array_diff_key($users, $projectOwner);
+                // If project owner is the same as owner, just show the owner, not the project
owner
+                $projectOwner = array_diff_key($projectOwner, $owner);
+
                 $canEditSharing = $this->isExperimentOwner($experiment, Session::get('username'));
 
                 return View::make("experiment/edit", array("expInputs" => $experimentInputs,

http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/3a2de307/app/libraries/SharingUtilities.php
----------------------------------------------------------------------
diff --git a/app/libraries/SharingUtilities.php b/app/libraries/SharingUtilities.php
index a0a1380..b689b24 100755
--- a/app/libraries/SharingUtilities.php
+++ b/app/libraries/SharingUtilities.php
@@ -175,6 +175,16 @@ class SharingUtilities {
 
         return $users;
     }
+
+    public static function getSharedResourceOwner($resourceId, $dataResourceType) {
+        $owners = GrouperUtilities::getAllAccessibleUsers($resourceId, $dataResourceType,
ResourcePermissionType::OWNER);
+        if (count($owners) != 1) {
+            Log::error("Got more than one shared resource owner!", array($resourceId, $dataResourceType,
$owners));
+            throw new Exception("Expected exactly 1 owner for $resourceId of type $dataResourceType!");
+        } else {
+            return $owners[0];
+        }
+    }
 }
 
 ?>


Mime
View raw message