Skip to content

Commit

Permalink
Merge pull request #10 from sophiefitzpatrick/updates
Browse files Browse the repository at this point in the history
Lots of fixes/remove commands that are limited by the api
  • Loading branch information
sophiefitzpatrick authored Feb 28, 2021
2 parents fb7e543 + 2589928 commit 9fb8052
Show file tree
Hide file tree
Showing 8 changed files with 156 additions and 218 deletions.
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ To unauth:

To invite users to your workspace:

marvelcli invite-users-to-workspace --email "janis@bigbrotherandtheholdingcompany.com" --email "stevie@fleetwoodmac.com" --email "grace@jeffersonairplane.com"
marvelcli add-collabs-to-project --project 12345 --email "janis@bigbrotherandtheholdingcompany.com" --email "stevie@fleetwoodmac.com" --email "grace@jeffersonairplane.com"

## Commands available:

Expand All @@ -48,14 +48,11 @@ You can find out how to use each command with:
delete-project Delete a project
get-billing-info Get billing information
get-personal-projects List all projects owned by you
invite-users-to-workspace Invite users to your workspace
remove-collabs-from-project Remove collaborators from a project
remove-groups-from-project Remove groups from a project
remove-members-from-group Remove members from a group
remove-users-from-workspace Remove users from your workspace
update-account-password Update your account password
update-group-name Update a group name
update-user Update your email, username and occuption

## Feature requests

Expand Down
88 changes: 52 additions & 36 deletions marvelcli/group/group_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,21 @@ def delete_groups(group_pk: list, auth: str):
if r.status_code != 200:
click.echo(json_data['data']['deleteGroups']['error']['message'])
else:
data_success = json_data['data']['deleteGroups']['succeeded']
data_failed = json_data['data']['deleteGroups']['failed']
if not group_pk:
click.echo("\nLooks like you might be missing some args, add `--help` to your command to see the options.\n")
else:
data_success = json_data['data']['deleteGroups']['succeeded']
data_failed = json_data['data']['deleteGroups']['failed']

if data_success:
click.echo("\nThe following groups were deleted from your workspace successfully: %s" % data_success)

if data_success:
click.echo("\nThe following groups were deleted from your workspace successfully: %s." % ', '.join(data_success))
if data_failed:
click.echo('\nThe following groups could not be deleted from your workspace:')
for f in data_failed:
click.echo("%s - %s" % (f.get('groupPk'), f.get('message')))

if data_failed:
click.echo('\nThe following groups could not be deleted from your workspace:')
for f in data_failed:
click.echo("%s - %s\n" % (f.get('groupPk'), f.get('message')))
click.echo("\n")

@click.option('-n', '--name', type=str, help='Name of group')
@click.option('-a', '--auth', type=str, help='Auth your request')
Expand All @@ -47,57 +52,68 @@ def create_group(name: str, auth: str):
@click.option('-e', '--email', type=str, multiple=True, help='Use this flag for each email address you want added to your group')
@click.option('-a', '--auth', type=str, help='Auth your request')
@click.command()
def add_members_to_group(group_pk: int, emails: list, auth: str):
def add_members_to_group(group_pk: int, email: list, auth: str):
"""Add members to a group"""
params = {'teamPk': group_pk,'emails': emails}
params = {'teamPk': group_pk,'emails': email}
query = group_queries.add_members_query
r, json_data = utils.make_request(auth, query, params)

if r.status_code != 200:
click.echo(json_data['data']['addMembersToTeam']['error']['message'])
if not group_pk:
click.echo("\nLooks like you might be missing some args, add `--help` to your command to see the options.\n")
else:
click.echo(json_data['data']['addMembersToTeam']['error']['message'])
else:
data_success = json_data['data']['addMembersToTeam']['succeeded']
data_failed = json_data['data']['addMembersToTeam']['failed']
if not email:
click.echo("\nLooks like you might be missing some args, add `--help` to your command to see the options.\n")
else:
data_success = json_data['data']['addMembersToTeam']['succeeded']
data_failed = json_data['data']['addMembersToTeam']['failed']
if data_success:
successful_emails = []
for s in data_success:
successful_emails.append(s.get('email'))

if data_success:
successful_emails = []
for s in data_success:
successful_emails.append(s.get('email'))
click.echo("\nThe following people were successfully added to group %s: %s" % (group_pk, ', '.join(successful_emails)))

click.echo("\n The following people were successfully added to group %s: %s" % (pk, ', '.join(successful_emails)))
if data_failed:
click.echo('\nThe following people could not be added to group %s for the following reasons:' % (group_pk))
for f in data_failed:
click.echo("%s - %s" % (f.get('email'), f.get('message')))

if data_failed:
click.echo('The following people could not be added to group %s:' % (pk))
for f in data_failed:
click.echo("%s - %s \n " % (f.get('email'), f.get('message')))
click.echo("\n")

@click.option('-g', '--group-pk', type=int, help='Pk of the group you want to remove members from')
@click.option('-e', '--email', type=str, multiple=True, help='Use this flag for each email address you want removed from your group')
@click.option('-a', '--auth', type=str, help='Auth your request')
@click.command()
def remove_members_from_group(group_pk: int, emails: list, auth: str):
def remove_members_from_group(group_pk: int, email: list, auth: str):
"""Remove members from a group"""
params = {'teamPk': group_pk,'emails': emails}
params = {'teamPk': group_pk,'emails': email}
query = group_queries.remove_members_query
r, json_data = utils.make_request(auth, query, params)

if r.status_code != 200:
click.echo(json_data['data']['removeMembersFromTeam']['error']['message'])
if not group_pk:
click.echo("\nLooks like you might be missing some args, add `--help` to your command to see the options.\n")
else:
click.echo(json_data['data']['removeMembersFromTeam']['error']['message'])
else:
data_success = json_data['data']['removeMembersFromTeam']['succeeded']
data_failed = json_data['data']['removeMembersFromTeam']['failed']
if not email:
click.echo("\nLooks like you might be missing some args, add `--help` to your command to see the options.\n")
else:
data_success = json_data['data']['removeMembersFromTeam']['succeeded']
data_failed = json_data['data']['removeMembersFromTeam']['failed']

if data_success:
successful_emails = []
for s in data_success:
successful_emails.append(s.get('email'))
if data_success:
click.echo("\nThe following people were successfully removed from group %s: %s" % (group_pk, data_success))

click.echo("The following people were successfully removed from group %s: %s" % (pk, ', '.join(successful_emails)))
if data_failed:
click.echo('\nThe following people could not be removed from group %s:' % (group_pk))
for f in data_failed:
click.echo("%s - %s" % (f.get('email'), f.get('message')))

if data_failed:
click.echo('The following people could not be removed from group %s:' % (pk))
for f in data_failed:
click.echo("%s - %s" % (f.get('email'), f.get('message')))
click.echo("\n")

@click.option('-g', '--group-pk', type=int, help='Pk of the group you want to update the name for')
@click.option('-n', '--name', type=str, help='New name for your group')
Expand Down
5 changes: 1 addition & 4 deletions marvelcli/marvelcli.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,11 @@ def marvelcli(args=None):
"""

# User
marvelcli.add_command(user_commands.update_account_password)
marvelcli.add_command(user_commands.update_user)
marvelcli.add_command(user_commands.about_user)

# Workspace
marvelcli.add_command(workspace_commands.get_billing_info)
marvelcli.add_command(workspace_commands.remove_users_from_workspace)
marvelcli.add_command(workspace_commands.invite_users_to_workspace)

# Project
marvelcli.add_command(project_commands.delete_project)
Expand All @@ -57,4 +54,4 @@ def marvelcli(args=None):
marvelcli.add_command(folder_commands.create_folder)

if __name__ == "__main__":
marvelcli()
marvelcli()
122 changes: 83 additions & 39 deletions marvelcli/project/project_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from marvelcli import utils
from marvelcli.project import project_queries
from marvelcli.workspace import workspace_queries

@click.option('-p', '--project-pk', type=str, help='Pk of the project you want to delete')
@click.option('-a', '--auth', type=str, help='Auth your request')
Expand All @@ -14,10 +15,13 @@ def delete_project(project_pk: str, auth: str):
r, json_data = utils.make_request(auth, query, params)

if r.status_code == 200:
if not json_data['data']['deleteproject']['ok']:
click.echo('\n' + json_data['data']['deleteproject']['error']['message'] + '\n')
if json_data['data']['deleteProject'] is None:
click.echo("\nProject '%s' has not been deleted for the following reason: %s\n" % (
project_pk,
json_data['errors'][0]['message']
))
else:
click.echo('\n"%s" has been successfully deleted from your Marvel account\n' % pk)
click.echo("\n'%s' has been successfully deleted from your Marvel account\n" % project_pk)
else:
click.echo("\nTry 'marvelcli delete_project --help' to make sure you are not missing any args.\n")

Expand All @@ -32,7 +36,10 @@ def add_groups_to_project(project_pk: int, group_pk: list, auth: str):
r, json_data = utils.make_request(auth, query, params)

if r.status_code != 200:
click.echo('\n' + json_data['data']['addTeamsToProject']['error']['message'] + '\n')
if not project_pk or not group_pk:
click.echo("\nLooks like you might be missing some args, add `--help` to your command to see the options.\n")
else:
click.echo('\n' + json_data['data']['addTeamsToProject']['error']['message'] + '\n')
else:
data_success = json_data['data']['addTeamsToProject']['succeeded']
data_failed = json_data['data']['addTeamsToProject']['failed']
Expand All @@ -41,12 +48,14 @@ def add_groups_to_project(project_pk: int, group_pk: list, auth: str):
successful_groups = []
for s in data_success:
successful_groups.append(s.get('pk'))
click.echo("\nThe following groups were successfully added to project %s: %s " % (project_pk, successful_groups))
click.echo("\nThe following groups were successfully added to project %s: %s \n" % (project_pk, successful_groups))

if data_failed:
click.echo('\nThe following groups could not be added to project %s:' % (project_pk))
for f in data_failed:
click.echo("%s - %s \n" % (f.get('teamPk'), f.get('message')))
click.echo("%s - %s" % (f.get('teamPk'), f.get('message')))

click.echo("\n")

@click.option('-p', '--project-pk', type=int, help='Pk of the project you want to remove groups from')
@click.option('-g', '--group_pk', type=int, multiple=True, help='Use this flag for each group you want removed from your project')
Expand All @@ -59,7 +68,10 @@ def remove_groups_from_project(project_pk: int, group_pk: list, auth: str):
r, json_data = utils.make_request(auth, query, params)

if r.status_code != 200:
click.echo('\n' + json_data['data']['removeTeamsFromProject']['error']['message'] + '\n')
if not project_pk or not group_pk:
click.echo("\nLooks like you might be missing some args, add `--help` to your command to see the options.\n")
else:
click.echo('\n' + json_data['data']['removeTeamsFromProject']['error']['message'] + '\n')
else:
data_success = json_data['data']['removeTeamsFromProject']['succeeded']
data_failed = json_data['data']['removeTeamsFromProject']['failed']
Expand All @@ -68,12 +80,14 @@ def remove_groups_from_project(project_pk: int, group_pk: list, auth: str):
successful_groups = []
for s in data_success:
successful_groups.append(s.get('pk'))
click.echo("\nThe following groups were successfully removed from project %s: %s" % (project_pk, successful_groups))
click.echo("\nThe following groups were successfully removed from project %s: %s\n" % (project_pk, successful_groups))

if data_failed:
click.echo('\nThe following groups could not be removed from project %s:' % (project_pk))
for f in data_failed:
click.echo("%s - %s \n" % (f.get('teamPk'), f.get('message')))
click.echo("%s - %s" % (f.get('teamPk'), f.get('message')))

click.echo("\n")

@click.option('-p', '--project-pk', type=int, help='Pk of the project you want to add collaborators to')
@click.option('-e', '--email', type=str, multiple=True, help='Use this flag for each email address you want added to your project')
Expand All @@ -86,21 +100,30 @@ def add_collabs_to_project(project_pk: int, email: list, auth: str):
r, json_data = utils.make_request(auth, query, params)

if r.status_code != 200:
click.echo('\n' + json_data['data']['addCollaboratorsToProject']['error']['message'] + '\n')
if not project_pk:
click.echo("\nLooks like you might be missing some args, add `--help` to your command to see the options.\n")
else:
click.echo('\n' + json_data['data']['addCollaboratorsToProject']['error']['message'] + '\n')
else:
data_success = json_data['data']['addCollaboratorsToProject']['succeeded']
data_failed = json_data['data']['addCollaboratorsToProject']['failed']
# status_code 200 without all args
if not email:
click.echo("\nLooks like you might be missing some args, add `--help` to your command to see the options.\n")
else:
data_success = json_data['data']['addCollaboratorsToProject']['succeeded']
data_failed = json_data['data']['addCollaboratorsToProject']['failed']

if data_success:
successful_emails = []
for s in data_success:
successful_emails.append(s.get('email'))
click.echo("\nThe following people were successfully added to project %s: %s" % (pk, ', '.join(successful_emails)))
if data_success:
successful_emails = []
for s in data_success:
successful_emails.append(s.get('email'))
click.echo("\nThe following people were successfully added to project %s: %s" % (project_pk, ', '.join(successful_emails)))

if data_failed:
click.echo('\nThe following people could not be added to project %s:' % (pk))
for f in data_failed:
click.echo("%s - '%s' \n" % (f.get('email'), f.get('message')))
if data_failed:
click.echo('\nThe following people could not be added to project %s for the following reasons:' % (project_pk))
for f in data_failed:
click.echo("%s - '%s'" % (f.get('email'), f.get('message')))

click.echo("\n")


@click.option('-p', '--project-pk', type=int, help='Pk of the project you want to remove collaborators from')
Expand All @@ -114,16 +137,25 @@ def remove_collabs_from_project(project_pk: int, email: list, auth: str):
r, json_data = utils.make_request(auth, query, params)

if r.status_code != 200:
click.echo('\n' + json_data['data']['removeCollaboratorsFromProject']['error']['message'] + '\n')
if not project_pk:
click.echo("\nLooks like you might be missing some args, add `--help` to your command to see the options.\n")
else:
click.echo('\n' + json_data['data']['removeCollaboratorsFromProject']['error']['message'] + '\n')
else:
if json_data['data']['removeCollaboratorsFromProject']['succeeded']:
click.echo("\nThe following people were successfully removed from project %s: %s" % (pk, ', '.join(data_success)))
if not email:
click.echo("\nLooks like you might be missing some args, add `--help` to your command to see the options.\n")
else:
data_success = json_data['data']['removeCollaboratorsFromProject']['succeeded']
if json_data['data']['removeCollaboratorsFromProject']['succeeded']:
click.echo("\nThe following people were successfully removed from project %s: %s" % (project_pk, data_success))

data_failed = json_data['data']['removeCollaboratorsFromProject']['failed']
if data_failed:
click.echo('\nThe following people could not be removed from project %s:' % (pk))
for f in data_failed:
click.echo("%s - '%s' \n" % (f.get('email'), f.get('message')))
data_failed = json_data['data']['removeCollaboratorsFromProject']['failed']
if data_failed:
click.echo('\nThe following people could not be removed from project %s for the following reasons:' % (project_pk))
for f in data_failed:
click.echo("%s - '%s'" % (f.get('email'), f.get('message')))

click.echo("\n")


@click.option('-n', '--name', type=str, help='Name of project')
Expand All @@ -132,16 +164,26 @@ def remove_collabs_from_project(project_pk: int, email: list, auth: str):
@click.command()
def create_project(name: str, password: str, auth: str):
"""Create a new project"""
params = {'name': name,'password': password}
if not password:
params['password'] = ''
query = project_queries.create_project_query
r, json_data = utils.make_request(auth, query, params)

if r.status_code != 200:
click.echo('\n' + 'A new project could not be created at this time."' + '\n')
if not name:
click.echo("\nLooks like you might be missing some args, add `--help` to your command to see the options.\n")
else:
click.echo('\n"%s" has been successfully created in your Marvel account \n' % name)
user_query = workspace_queries.get_billing_info_query
req, json_data_user = utils.make_request(auth, user_query)
plan = json_data_user['data']['user']['company']['billing']['plan']['title']
proj_used = json_data_user['data']['user']['company']['billing']['projectQuantityUsed']
if plan == 'Free' and proj_used == 1:
click.echo("\nYou have maxed out your allowances, either delete a project then run the command again or upgrade for unlimited projects: https://marvelapp.com/plans \n")
else:
params = {'name': name,'password': password}
if not password:
params['password'] = ''
query = project_queries.create_project_query
r, json_data = utils.make_request(auth, query, params)

if r.status_code != 200:
click.echo('\n' + 'A new project could not be created at this time."' + '\n')
else:
click.echo('\n"%s" has been successfully created in your Marvel account \n' % name)

@click.option('-a', '--auth', type=str, help='Auth your request')
@click.command()
Expand All @@ -160,7 +202,9 @@ def get_personal_projects(auth: str):
urls.append(url)

project_count = len(json_data['data']['user']['projects']['edges'])
click.echo('\nYou have %s project(s)' % project_count)
click.echo('\nYou have %s project(s):' % project_count)

for url in urls:
click.echo(url)

click.echo("\n")
Loading

0 comments on commit 9fb8052

Please sign in to comment.