Skip to content

Commit

Permalink
Add option to add users to gitlab using API
Browse files Browse the repository at this point in the history
  • Loading branch information
harshithpabbati committed Mar 28, 2021
1 parent 50f5c74 commit ce49cba
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
28 changes: 28 additions & 0 deletions framework/api/mutation.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,33 @@ def mutate(self, info, username, github=None, gitlab=None, telegram=None, cloudf
code='ONLY_SUPERUSER_HAS_ACCESS')


class AddToPlatform(graphene.Mutation):
class Arguments:
usernames = graphene.List(graphene.String)
platform = graphene.String()

Output = statusObj

def mutate(self, info, usernames, platform):
if info.context.user.is_superuser:
for username in usernames:
profile = Profile.objects.get(user__username=username)
if platform is not None:
if platform == "gitlab":
GitLab(profile.gitlabUsername).addUser()
elif platform == "github":
GitHub(profile.githubUsername).addUser()
elif platform == "telegram":
Telegram(profile.telegram_id).addUser()
else:
raise APIException('Platform is required to perform this action',
code='PLATFORM_IS_REQUIRED')
return statusObj(status=True)
else:
raise APIException('Only Superusers have access',
code='ONLY_SUPERUSER_HAS_ACCESS')


class Mutation(object):
change_user_platform = ChangeUserPlatform.Field()
addToPlatform = AddToPlatform.Field()
2 changes: 1 addition & 1 deletion framework/platforms/gitlab.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def addUser(self):
gl.auth()
group = gl.groups.get('amfoss')
userID = gl.users.list(username=self.username)[0].id
group.members.create({'user_id': userID, 'access_level': gitlab.GUEST_ACCESS})
group.members.create({'user_id': userID, 'access_level': gitlab.REPORTER_ACCESS})

def checkIfUserExists(self):
GITLAB_TOKEN = Token.objects.values().get(key='GITLAB_TOKEN')['value']
Expand Down
1 change: 1 addition & 0 deletions framework/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ class userResponseObj(graphene.ObjectType):
class userStatusObj(graphene.ObjectType):
status = graphene.String()


class ApproveUsers(graphene.Mutation):
class Arguments:
usernames = graphene.List(graphene.String)
Expand Down

0 comments on commit ce49cba

Please sign in to comment.