Skip to content

Commit 9fb8052

Browse files
Merge pull request #10 from sophiefitzpatrick/updates
Lots of fixes/remove commands that are limited by the api
2 parents fb7e543 + 2589928 commit 9fb8052

File tree

8 files changed

+156
-218
lines changed

8 files changed

+156
-218
lines changed

README.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ To unauth:
2727

2828
To invite users to your workspace:
2929

30-
marvelcli invite-users-to-workspace --email "[email protected]" --email "[email protected]" --email "[email protected]"
30+
marvelcli add-collabs-to-project --project 12345 --email "[email protected]" --email "[email protected]" --email "[email protected]"
3131

3232
## Commands available:
3333

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

6057
## Feature requests
6158

marvelcli/group/group_commands.py

Lines changed: 52 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,21 @@ def delete_groups(group_pk: list, auth: str):
1515
if r.status_code != 200:
1616
click.echo(json_data['data']['deleteGroups']['error']['message'])
1717
else:
18-
data_success = json_data['data']['deleteGroups']['succeeded']
19-
data_failed = json_data['data']['deleteGroups']['failed']
18+
if not group_pk:
19+
click.echo("\nLooks like you might be missing some args, add `--help` to your command to see the options.\n")
20+
else:
21+
data_success = json_data['data']['deleteGroups']['succeeded']
22+
data_failed = json_data['data']['deleteGroups']['failed']
23+
24+
if data_success:
25+
click.echo("\nThe following groups were deleted from your workspace successfully: %s" % data_success)
2026

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

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

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

5661
if r.status_code != 200:
57-
click.echo(json_data['data']['addMembersToTeam']['error']['message'])
62+
if not group_pk:
63+
click.echo("\nLooks like you might be missing some args, add `--help` to your command to see the options.\n")
64+
else:
65+
click.echo(json_data['data']['addMembersToTeam']['error']['message'])
5866
else:
59-
data_success = json_data['data']['addMembersToTeam']['succeeded']
60-
data_failed = json_data['data']['addMembersToTeam']['failed']
67+
if not email:
68+
click.echo("\nLooks like you might be missing some args, add `--help` to your command to see the options.\n")
69+
else:
70+
data_success = json_data['data']['addMembersToTeam']['succeeded']
71+
data_failed = json_data['data']['addMembersToTeam']['failed']
72+
if data_success:
73+
successful_emails = []
74+
for s in data_success:
75+
successful_emails.append(s.get('email'))
6176

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

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

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

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

8496
if r.status_code != 200:
85-
click.echo(json_data['data']['removeMembersFromTeam']['error']['message'])
97+
if not group_pk:
98+
click.echo("\nLooks like you might be missing some args, add `--help` to your command to see the options.\n")
99+
else:
100+
click.echo(json_data['data']['removeMembersFromTeam']['error']['message'])
86101
else:
87-
data_success = json_data['data']['removeMembersFromTeam']['succeeded']
88-
data_failed = json_data['data']['removeMembersFromTeam']['failed']
102+
if not email:
103+
click.echo("\nLooks like you might be missing some args, add `--help` to your command to see the options.\n")
104+
else:
105+
data_success = json_data['data']['removeMembersFromTeam']['succeeded']
106+
data_failed = json_data['data']['removeMembersFromTeam']['failed']
89107

90-
if data_success:
91-
successful_emails = []
92-
for s in data_success:
93-
successful_emails.append(s.get('email'))
108+
if data_success:
109+
click.echo("\nThe following people were successfully removed from group %s: %s" % (group_pk, data_success))
94110

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

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

102118
@click.option('-g', '--group-pk', type=int, help='Pk of the group you want to update the name for')
103119
@click.option('-n', '--name', type=str, help='New name for your group')

marvelcli/marvelcli.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,11 @@ def marvelcli(args=None):
2828
"""
2929

3030
# User
31-
marvelcli.add_command(user_commands.update_account_password)
32-
marvelcli.add_command(user_commands.update_user)
3331
marvelcli.add_command(user_commands.about_user)
3432

3533
# Workspace
3634
marvelcli.add_command(workspace_commands.get_billing_info)
3735
marvelcli.add_command(workspace_commands.remove_users_from_workspace)
38-
marvelcli.add_command(workspace_commands.invite_users_to_workspace)
3936

4037
# Project
4138
marvelcli.add_command(project_commands.delete_project)
@@ -57,4 +54,4 @@ def marvelcli(args=None):
5754
marvelcli.add_command(folder_commands.create_folder)
5855

5956
if __name__ == "__main__":
60-
marvelcli()
57+
marvelcli()

marvelcli/project/project_commands.py

Lines changed: 83 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
from marvelcli import utils
55
from marvelcli.project import project_queries
6+
from marvelcli.workspace import workspace_queries
67

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

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

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

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

4653
if data_failed:
4754
click.echo('\nThe following groups could not be added to project %s:' % (project_pk))
4855
for f in data_failed:
49-
click.echo("%s - %s \n" % (f.get('teamPk'), f.get('message')))
56+
click.echo("%s - %s" % (f.get('teamPk'), f.get('message')))
57+
58+
click.echo("\n")
5059

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

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

7385
if data_failed:
7486
click.echo('\nThe following groups could not be removed from project %s:' % (project_pk))
7587
for f in data_failed:
76-
click.echo("%s - %s \n" % (f.get('teamPk'), f.get('message')))
88+
click.echo("%s - %s" % (f.get('teamPk'), f.get('message')))
89+
90+
click.echo("\n")
7791

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

88102
if r.status_code != 200:
89-
click.echo('\n' + json_data['data']['addCollaboratorsToProject']['error']['message'] + '\n')
103+
if not project_pk:
104+
click.echo("\nLooks like you might be missing some args, add `--help` to your command to see the options.\n")
105+
else:
106+
click.echo('\n' + json_data['data']['addCollaboratorsToProject']['error']['message'] + '\n')
90107
else:
91-
data_success = json_data['data']['addCollaboratorsToProject']['succeeded']
92-
data_failed = json_data['data']['addCollaboratorsToProject']['failed']
108+
# status_code 200 without all args
109+
if not email:
110+
click.echo("\nLooks like you might be missing some args, add `--help` to your command to see the options.\n")
111+
else:
112+
data_success = json_data['data']['addCollaboratorsToProject']['succeeded']
113+
data_failed = json_data['data']['addCollaboratorsToProject']['failed']
93114

94-
if data_success:
95-
successful_emails = []
96-
for s in data_success:
97-
successful_emails.append(s.get('email'))
98-
click.echo("\nThe following people were successfully added to project %s: %s" % (pk, ', '.join(successful_emails)))
115+
if data_success:
116+
successful_emails = []
117+
for s in data_success:
118+
successful_emails.append(s.get('email'))
119+
click.echo("\nThe following people were successfully added to project %s: %s" % (project_pk, ', '.join(successful_emails)))
99120

100-
if data_failed:
101-
click.echo('\nThe following people could not be added to project %s:' % (pk))
102-
for f in data_failed:
103-
click.echo("%s - '%s' \n" % (f.get('email'), f.get('message')))
121+
if data_failed:
122+
click.echo('\nThe following people could not be added to project %s for the following reasons:' % (project_pk))
123+
for f in data_failed:
124+
click.echo("%s - '%s'" % (f.get('email'), f.get('message')))
125+
126+
click.echo("\n")
104127

105128

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

116139
if r.status_code != 200:
117-
click.echo('\n' + json_data['data']['removeCollaboratorsFromProject']['error']['message'] + '\n')
140+
if not project_pk:
141+
click.echo("\nLooks like you might be missing some args, add `--help` to your command to see the options.\n")
142+
else:
143+
click.echo('\n' + json_data['data']['removeCollaboratorsFromProject']['error']['message'] + '\n')
118144
else:
119-
if json_data['data']['removeCollaboratorsFromProject']['succeeded']:
120-
click.echo("\nThe following people were successfully removed from project %s: %s" % (pk, ', '.join(data_success)))
145+
if not email:
146+
click.echo("\nLooks like you might be missing some args, add `--help` to your command to see the options.\n")
147+
else:
148+
data_success = json_data['data']['removeCollaboratorsFromProject']['succeeded']
149+
if json_data['data']['removeCollaboratorsFromProject']['succeeded']:
150+
click.echo("\nThe following people were successfully removed from project %s: %s" % (project_pk, data_success))
121151

122-
data_failed = json_data['data']['removeCollaboratorsFromProject']['failed']
123-
if data_failed:
124-
click.echo('\nThe following people could not be removed from project %s:' % (pk))
125-
for f in data_failed:
126-
click.echo("%s - '%s' \n" % (f.get('email'), f.get('message')))
152+
data_failed = json_data['data']['removeCollaboratorsFromProject']['failed']
153+
if data_failed:
154+
click.echo('\nThe following people could not be removed from project %s for the following reasons:' % (project_pk))
155+
for f in data_failed:
156+
click.echo("%s - '%s'" % (f.get('email'), f.get('message')))
157+
158+
click.echo("\n")
127159

128160

129161
@click.option('-n', '--name', type=str, help='Name of project')
@@ -132,16 +164,26 @@ def remove_collabs_from_project(project_pk: int, email: list, auth: str):
132164
@click.command()
133165
def create_project(name: str, password: str, auth: str):
134166
"""Create a new project"""
135-
params = {'name': name,'password': password}
136-
if not password:
137-
params['password'] = ''
138-
query = project_queries.create_project_query
139-
r, json_data = utils.make_request(auth, query, params)
140-
141-
if r.status_code != 200:
142-
click.echo('\n' + 'A new project could not be created at this time."' + '\n')
167+
if not name:
168+
click.echo("\nLooks like you might be missing some args, add `--help` to your command to see the options.\n")
143169
else:
144-
click.echo('\n"%s" has been successfully created in your Marvel account \n' % name)
170+
user_query = workspace_queries.get_billing_info_query
171+
req, json_data_user = utils.make_request(auth, user_query)
172+
plan = json_data_user['data']['user']['company']['billing']['plan']['title']
173+
proj_used = json_data_user['data']['user']['company']['billing']['projectQuantityUsed']
174+
if plan == 'Free' and proj_used == 1:
175+
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")
176+
else:
177+
params = {'name': name,'password': password}
178+
if not password:
179+
params['password'] = ''
180+
query = project_queries.create_project_query
181+
r, json_data = utils.make_request(auth, query, params)
182+
183+
if r.status_code != 200:
184+
click.echo('\n' + 'A new project could not be created at this time."' + '\n')
185+
else:
186+
click.echo('\n"%s" has been successfully created in your Marvel account \n' % name)
145187

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

162204
project_count = len(json_data['data']['user']['projects']['edges'])
163-
click.echo('\nYou have %s project(s)' % project_count)
205+
click.echo('\nYou have %s project(s):' % project_count)
164206

165207
for url in urls:
166208
click.echo(url)
209+
210+
click.echo("\n")

0 commit comments

Comments
 (0)