Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

List possible values when inviting a team within an environment #158

8 changes: 7 additions & 1 deletion backend/dataall/api/Objects/Group/queries.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from ... import gql
from .resolvers import get_group, list_datasets_owned_by_env_group, list_data_items_shared_with_env_group
from .resolvers import get_group, list_datasets_owned_by_env_group, list_data_items_shared_with_env_group, list_cognito_groups

getGroup = gql.QueryField(
name='getGroup',
Expand Down Expand Up @@ -33,3 +33,9 @@
type=gql.Ref('EnvironmentPublishedItemSearchResults'),
test_scope='Dataset',
)

listCognitoGroups = gql.QueryField(
name='listCognitoGroups',
type=gql.ArrayType(gql.Ref('CognitoGroup')),
resolver=list_cognito_groups
)
20 changes: 20 additions & 0 deletions backend/dataall/api/Objects/Group/resolvers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import os
from .... import db
from ....db import exceptions
from ....db.models import Group
from ...constants import *
from ....aws.handlers.parameter_store import ParameterStoreManager
from ....aws.handlers.sts import SessionHelper
from ....aws.handlers.cognito import Cognito


def resolve_group_environment_permissions(context, source, environmentUri):
Expand Down Expand Up @@ -70,3 +74,19 @@ def list_data_items_shared_with_env_group(
data=filter,
check_perm=True,
)


def list_cognito_groups(context, source):
current_account = SessionHelper.get_account()
current_region = os.getenv('AWS_REGION', 'eu-west-1')
envname = os.getenv('envname', 'local')
if envname in ['local', 'dkrcompose']:
return [{"groupName": 'DAAdministrators'}, {"groupName": 'Engineers'}, {"groupName": 'Scientists'}]
parameter_path = f'/dataall/{envname}/cognito/userpool'
user_pool_id = ParameterStoreManager.get_parameter_value(current_account, current_region, parameter_path)
groups = Cognito.list_cognito_groups(current_account, current_region, user_pool_id)
res = []
for group in groups:
res.append({"groupName": group['GroupName']})

return res
7 changes: 7 additions & 0 deletions backend/dataall/api/Objects/Group/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,10 @@
gql.Field(name='nodes', type=gql.ArrayType(Group)),
],
)

CognitoGroup = gql.ObjectType(
name='CognitoGroup',
fields=[
gql.Field(name='groupName', type=gql.String),
],
)
25 changes: 25 additions & 0 deletions backend/dataall/aws/handlers/cognito.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import logging

from .sts import SessionHelper


log = logging.getLogger(__name__)


class Cognito:
@staticmethod
def client(account_id: str, region_name: str, client_type: str):
session = SessionHelper.remote_session(account_id)
return session.client(client_type, region_name=region_name)

@staticmethod
def list_cognito_groups(account_id: str, region: str, user_pool_id: str):
try:
cognitoCli = Cognito.client(account_id, region, "cognito-idp")
response = cognitoCli.list_groups(UsePoolId=user_pool_id)
except Exception as e:
log.error(
f'Failed to list groups of user pool {user_pool_id} due to {e}'
)
else:
return response['Groups']
13 changes: 13 additions & 0 deletions frontend/src/api/Groups/listCognitoGroups.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { gql } from 'apollo-boost';

const listCognitoGroups = () => ({
query: gql`
query listCognitoGroups {
listCognitoGroups{
groupName
}
}
`
});

export default listCognitoGroups;
15 changes: 7 additions & 8 deletions frontend/src/views/Environments/EnvironmentTeamInviteForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import useClient from '../../hooks/useClient';
import listEnvironmentGroupInvitationPermissions from '../../api/Environment/listEnvironmentPermissions';
import inviteGroupOnEnvironment from '../../api/Environment/inviteGroup';
import listEnvironmentNotInvitedGroups from '../../api/Environment/listNotInvitedGroups';
import listCognitoGroups from '../../api/Groups/listCognitoGroups';

const EnvironmentTeamInviteForm = (props) => {
const { environment, onClose, open, reloadTeams, ...other } = props;
Expand All @@ -44,17 +45,15 @@ const EnvironmentTeamInviteForm = (props) => {
const fetchGroups = useCallback(async () => {
try {
setLoadingGroups(true);
const response = await client.query(
listEnvironmentNotInvitedGroups({
environmentUri: environment.environmentUri
})
);
console.log("fetchgroups")
LEUNGUU marked this conversation as resolved.
Show resolved Hide resolved
const response = await client.query(listCognitoGroups());
console.log(response)
LEUNGUU marked this conversation as resolved.
Show resolved Hide resolved
if (!response.errors) {
setGroupOptions(
response.data.listEnvironmentNotInvitedGroups.nodes.map((g) => ({
response.data.listCognitoGroups.map((g) => ({
...g,
value: g.groupUri,
label: g.groupUri
value: g.groupName,
label: g.groupName
}))
);
} else {
Expand Down