This is an automated email from the ASF dual-hosted git repository.

ofuks pushed a commit to branch DLAB-1590
in repository https://gitbox.apache.org/repos/asf/incubator-dlab.git


The following commit(s) were added to refs/heads/DLAB-1590 by this push:
     new 555a485  Admin per project
555a485 is described below

commit 555a485c934810173e0435396010e6169c8fae11
Author: Oleh Fuks <[email protected]>
AuthorDate: Wed Mar 25 14:37:23 2020 +0200

    Admin per project
---
 .../service/impl/EnvironmentServiceImpl.java       | 28 +++++++++++++++-------
 .../src/main/resources/mongo/aws/mongo_roles.json  | 17 +++++++++++++
 .../main/resources/mongo/azure/mongo_roles.json    | 17 +++++++++++++
 .../src/main/resources/mongo/gcp/mongo_roles.json  |  1 +
 4 files changed, 54 insertions(+), 9 deletions(-)

diff --git 
a/services/self-service/src/main/java/com/epam/dlab/backendapi/service/impl/EnvironmentServiceImpl.java
 
b/services/self-service/src/main/java/com/epam/dlab/backendapi/service/impl/EnvironmentServiceImpl.java
index 15607d3..0bab2d6 100644
--- 
a/services/self-service/src/main/java/com/epam/dlab/backendapi/service/impl/EnvironmentServiceImpl.java
+++ 
b/services/self-service/src/main/java/com/epam/dlab/backendapi/service/impl/EnvironmentServiceImpl.java
@@ -20,6 +20,9 @@
 package com.epam.dlab.backendapi.service.impl;
 
 import com.epam.dlab.auth.UserInfo;
+import com.epam.dlab.backendapi.annotation.Project;
+import com.epam.dlab.backendapi.annotation.ProjectAdmin;
+import com.epam.dlab.backendapi.annotation.User;
 import com.epam.dlab.backendapi.dao.EnvDAO;
 import com.epam.dlab.backendapi.dao.ExploratoryDAO;
 import com.epam.dlab.backendapi.dao.UserSettingsDAO;
@@ -90,7 +93,7 @@ public class EnvironmentServiceImpl implements 
EnvironmentService {
        public List<UserResourceInfo> getAllEnv(UserInfo user) {
                log.debug("Getting all user's environment...");
                List<UserInstanceDTO> expList = exploratoryDAO.getInstances();
-               return projectService.getProjects(user)
+               return projectService.getProjects()
                                .stream()
                                .map(projectDTO -> getProjectEnv(projectDTO, 
expList))
                                .flatMap(Collection::stream)
@@ -135,24 +138,30 @@ public class EnvironmentServiceImpl implements 
EnvironmentService {
                                                endpoint.getName(), project));
        }
 
+       @ProjectAdmin
        @Override
-       public void stopExploratory(UserInfo userInfo, String user, String 
project, String exploratoryName) {
+       public void stopExploratory(@User UserInfo userInfo, String user, 
@Project String project, String exploratoryName) {
                exploratoryService.stop(new UserInfo(user, 
userInfo.getAccessToken()), project, exploratoryName);
        }
 
+       @ProjectAdmin
        @Override
-       public void stopComputational(UserInfo userInfo, String user, String 
project, String exploratoryName, String computationalName) {
+       public void stopComputational(@User UserInfo userInfo, String user, 
@Project String project, String exploratoryName,
+                                                                 String 
computationalName) {
                computationalService.stopSparkCluster(new UserInfo(user, 
userInfo.getAccessToken()), project, exploratoryName,
                                computationalName);
        }
 
+       @ProjectAdmin
        @Override
-       public void terminateExploratory(UserInfo userInfo, String user, String 
project, String exploratoryName) {
+       public void terminateExploratory(@User UserInfo userInfo, String user, 
@Project String project, String exploratoryName) {
                exploratoryService.terminate(new UserInfo(user, 
userInfo.getAccessToken()), project, exploratoryName);
        }
 
+       @ProjectAdmin
        @Override
-       public void terminateComputational(UserInfo userInfo, String user, 
String project, String exploratoryName, String computationalName) {
+       public void terminateComputational(@User UserInfo userInfo, String 
user, @Project String project,
+                                                                          
String exploratoryName, String computationalName) {
                computationalService.terminateComputational(new UserInfo(user, 
userInfo.getAccessToken()), project, exploratoryName,
                                computationalName);
        }
@@ -180,8 +189,10 @@ public class EnvironmentServiceImpl implements 
EnvironmentService {
        }
 
        private List<UserResourceInfo> getProjectEnv(ProjectDTO projectDTO, 
List<UserInstanceDTO> allInstances) {
-               final Stream<UserResourceInfo> userResources = 
allInstances.stream()
-                               .filter(instance -> 
instance.getProject().equals(projectDTO.getName())).map(this::toUserResourceInfo);
+               final Stream<UserResourceInfo> userResources = allInstances
+                               .stream()
+                               .filter(instance -> 
instance.getProject().equals(projectDTO.getName()))
+                               .map(this::toUserResourceInfo);
                if (projectDTO.getEndpoints() != null) {
                        final Stream<UserResourceInfo> edges = 
projectDTO.getEndpoints()
                                        .stream()
@@ -189,8 +200,7 @@ public class EnvironmentServiceImpl implements 
EnvironmentService {
                                                        
.withResourceStatus(e.getStatus().toString())
                                                        
.withProject(projectDTO.getName())
                                                        .withIp(e.getEdgeInfo() 
!= null ? e.getEdgeInfo().getPublicIp() : null));
-                       return Stream.concat(edges, userResources)
-                                       .collect(toList());
+                       return Stream.concat(edges, 
userResources).collect(toList());
                } else {
                        return userResources.collect(toList());
                }
diff --git 
a/services/self-service/src/main/resources/mongo/aws/mongo_roles.json 
b/services/self-service/src/main/resources/mongo/aws/mongo_roles.json
index 9998d84..e7649e6 100644
--- a/services/self-service/src/main/resources/mongo/aws/mongo_roles.json
+++ b/services/self-service/src/main/resources/mongo/aws/mongo_roles.json
@@ -324,6 +324,23 @@
     ]
   },
   {
+    "_id": "projectAdmin",
+    "description": "Allow to execute administration operation per project",
+    "type": "ADMINISTRATION",
+    "cloud": "AWS",
+    "pages": [
+      "environment/*",
+      "/roleManagement",
+      "/api/settings",
+      "/user/settings",
+      "/api/project",
+      "/api/endpoint"
+    ],
+    "groups": [
+      "$anyuser"
+    ]
+  },
+  {
     "_id": "admin",
     "description": "Allow to execute administration operation",
     "type": "ADMINISTRATION",
diff --git 
a/services/self-service/src/main/resources/mongo/azure/mongo_roles.json 
b/services/self-service/src/main/resources/mongo/azure/mongo_roles.json
index 113a705..bb0c7d1 100644
--- a/services/self-service/src/main/resources/mongo/azure/mongo_roles.json
+++ b/services/self-service/src/main/resources/mongo/azure/mongo_roles.json
@@ -264,6 +264,23 @@
     ]
   },
   {
+    "_id": "projectAdmin",
+    "description": "Allow to execute administration operation per project",
+    "type": "ADMINISTRATION",
+    "cloud": "AZURE",
+    "pages": [
+      "environment/*",
+      "/roleManagement",
+      "/api/settings",
+      "/user/settings",
+      "/api/project",
+      "/api/endpoint"
+    ],
+    "groups": [
+      "$anyuser"
+    ]
+  },
+  {
     "_id": "admin",
     "description": "Allow to execute administration operation",
     "type": "ADMINISTRATION",
diff --git 
a/services/self-service/src/main/resources/mongo/gcp/mongo_roles.json 
b/services/self-service/src/main/resources/mongo/gcp/mongo_roles.json
index 8f4ec0b..3f7327e 100644
--- a/services/self-service/src/main/resources/mongo/gcp/mongo_roles.json
+++ b/services/self-service/src/main/resources/mongo/gcp/mongo_roles.json
@@ -303,6 +303,7 @@
     "_id": "projectAdmin",
     "description": "Allow to execute administration operation per project",
     "type": "ADMINISTRATION",
+    "cloud": "GCP",
     "pages": [
       "environment/*",
       "/roleManagement",


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to