Пример #1
0
def remove_groups_from_project(project_pk: int, group_pk: list, auth: str):
	"""Remove groups from a project"""
	params = {'projectPk': project_pk,'teamPks': group_pk}
	query = project_queries.remove_groups_from_project_query
	r, json_data = utils.make_request(auth, query, params)

	if r.status_code != 200:
		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']

		if data_success:
			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\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" % (f.get('teamPk'), f.get('message')))

		click.echo("\n")
Пример #2
0
def add_collabs_to_project(project_pk: int, email: list, auth: str):
	"""Add collaborators to a project"""
	params = {'projectPk': project_pk,'emails': email}
	query = project_queries.add_collabs_to_project_query
	r, json_data = utils.make_request(auth, query, params)

	if r.status_code != 200:
		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:
		# 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" % (project_pk, ', '.join(successful_emails)))

			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")
Пример #3
0
def delete_groups(group_pk: list, auth: str):
    """Delete a list of groups"""
    params = {'groupPks': group_pk}
    query = group_queries.delete_groups_query
    r, json_data = utils.make_request(auth, query, params)

    if r.status_code != 200:
        click.echo(json_data['data']['deleteGroups']['error']['message'])
    else:
        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_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')))

            click.echo("\n")
Пример #4
0
def remove_collabs_from_project(project_pk: int, email: list, auth: str):
	"""Remove collaborators from a project"""
	params = {'projectPk': project_pk,'emails': email}
	query = project_queries.remove_collabs_from_project_query
	r, json_data = utils.make_request(auth, query, params)

	if r.status_code != 200:
		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 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 for the following reasons:' % (project_pk))
				for f in data_failed:
					click.echo("%s  - '%s'" % (f.get('email'), f.get('message')))

			click.echo("\n")
Пример #5
0
def remove_users_from_workspace(email: list, auth: str):
    """Remove users from your workspace"""
    params = {'emails': email}
    query = workspace_queries.remove_users_from_workspace_query
    r, json_data = utils.make_request(auth, query, params)

    if not email:
        click.echo(
            'Looks like you are missing some args, add `--help` to the command to see the options'
        )
    if r.status_code != 200:
        if not email:
            click.echo(
                'Looks like you are missing some args, add `--help` to the command to see the options'
            )
        else:
            click.echo('\n' + json_data['data']['removeUsersFromWorkspace']
                       ['error']['message'] + '\n')
    else:
        data_success = json_data['data']['removeUsersFromWorkspace'][
            'succeeded']
        data_failed = json_data['data']['removeUsersFromWorkspace']['failed']

        if data_success:
            succeeded = "\nThe following people were successfully removed from your workspace: %s \n" % ', '.join(
                data_success)
            click.echo(succeeded)

        if data_failed:
            click.echo(
                '\nThe following people could not be removed from your workspace:'
            )
            for f in data_failed:
                click.echo("%s  - '%s'\n" % (f.get('email'), f.get('message')))
Пример #6
0
def get_billing_info(auth: str):
    """Get billing information"""
    query = workspace_queries.get_billing_info_query
    r, json_data = utils.make_request(auth, query)

    if r.status_code != 200:
        click.echo('\n' + 'Billing data could not be returned right now.' +
                   '\n')
    else:
        billing = json_data['data']['user']['company']['billing']
        plan = billing['plan']

        if billing['billingCycle'] == 'yearly':
            price = int(plan['priceYearly'] / 100)
            price_per_seat = round(price / billing['seatQuantityUsed'], 2)
        else:
            price = int(plan['priceMonthly'] / 100)
            price_per_seat = round(price / billing['seatQuantityUsed'], 2)

        click.echo(utils.colour.BOLD + "\nYour Plan" + utils.colour.END)
        click.echo("Type: %s" % plan['title'])
        if plan['title'] != 'Free':
            click.echo("Price: %s %s" % (price, billing['currency'].upper()))
            click.echo("Seats: %s (%s %s per user)" %
                       (plan['teamMembers'], price_per_seat,
                        billing['currency'].upper()))
            click.echo("Projects: Unlimited \n")
        else:
            click.echo("Seats: %s " % (plan['teamMembers']))
            click.echo("Projects: 1 \n")

        click.echo(utils.colour.BOLD + "Your Usage" + utils.colour.END)
        click.echo("Seats Purchased: %s" % billing['seatQuantityPurchased'])
        click.echo("Seats Used: %s" % billing['seatQuantityUsed'])
        click.echo("Projects: %s \n" % billing['projectQuantityUsed'])

        if plan['title'] != 'Free':
            next_payment_date = billing['nextPaymentDate']
            dt = datetime.datetime(int(next_payment_date[0:4]),
                                   int(next_payment_date[5:7]),
                                   int(next_payment_date[8:10]), 0, 0)
            next_payment_date = "%s-%s-%s" % (dt.day, dt.month, dt.year)
            next_payment_amount = price_per_seat * billing[
                'seatQuantityPurchased']
            click.echo(
                "Your next payment date is %s. You'll be paying %s %s for %s seats.\n"
                % (next_payment_date, next_payment_amount,
                   billing['currency'].upper(),
                   billing['seatQuantityPurchased']))
        else:
            click.echo(
                "Upgrade to create more projects and add more team members: https://marvelapp.com/plans\n"
            )
Пример #7
0
def create_project(name: str, password: str, auth: str):
	"""Create a new project"""
	if not name:
		click.echo("\nLooks like you might be missing some args, add `--help` to your command to see the options.\n")
	else:
		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)
Пример #8
0
def delete_project(project_pk: str, auth: str):
	"""Delete a project"""
	params = {'pk': project_pk}
	query = project_queries.delete_project_query
	r, json_data = utils.make_request(auth, query, params)

	if r.status_code == 200:
		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" % project_pk)
	else:
		click.echo("\nTry 'marvelcli delete_project --help' to make sure you are not missing any args.\n")
Пример #9
0
def update_group_name(group_pk: int, name: str, auth: str):
    """Update a group name"""
    params = {'pk': group_pk, 'name': name}
    query = group_queries.update_group_name_query
    r, json_data = utils.make_request(auth, query, params)

    if r.status_code == 200:
        if not json_data['data']['updateGroup']['ok']:
            click.echo('\n' +
                       json_data['data']['updateGroup']['error']['message'])
        else:
            click.echo(
                "\nThe name of the group was updated successfully to '%s'\n" %
                name)
    else:
        click.echo(
            "\nTry 'marvelcli update_group_name --help' to make sure you are not missing any args.\n"
        )
Пример #10
0
def create_group(name: str, auth: str):
    """Create a group"""
    params = {'name': name}
    query = group_queries.create_group_query
    r, json_data = utils.make_request(auth, query, params)

    if r.status_code == 200:
        if not json_data['data']['createTeam']['ok']:
            click.echo('\n' +
                       json_data['data']['createTeam']['error']['message'] +
                       '\n')
        else:
            click.echo(
                '\nThe group "%s" has been successfully created in your Marvel account\n'
                % name)
    else:
        click.echo(
            "\nTry 'marvelcli create-group --help' to make sure you are not missing any args.\n"
        )
Пример #11
0
def get_personal_projects(auth: str):
	"""List all projects owned by you"""
	query = project_queries.get_all_personal_projects_query
	r, json_data = utils.make_request(auth, query)

	if r.status_code != 200:
		click.echo('\n' + 'Your personal projects could not be returned at this time."' + '\n')
	else:
		data = json_data['data']['user']['projects']['edges']
		urls = []
		for d in data:
			url = d['node']['prototypeUrl']
			urls.append(url)

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

		for url in urls:
			click.echo(url)

		click.echo("\n")
Пример #12
0
def about_user(auth: str):
    """User statistics"""
    query = user_queries.about_user_query
    r, json_data = utils.make_request(auth, query)

    if r.status_code != 200:
        click.echo(
            "\nWe could not retrieve the data at this time, possibly due to a ratelimit. Try again in a few minutes\n"
        )
    else:
        user = json_data['data']['user']
        last_active = user['lastActiveAt']
        last_active = datetime.datetime(int(last_active[0:4]),
                                        int(last_active[5:7]),
                                        int(last_active[8:10]), 0, 0)

        click.echo(utils.colour.BOLD + '\nYour Account:' + utils.colour.END)
        click.echo('Email: %s' % user['email'])
        click.echo('Last Active: %s' % last_active)
        click.echo('Status: %s' % user['status'])
        click.echo('Username: %s \n' % user['username'])
Пример #13
0
def create_folder(name: str, visibility: str, auth: str):
    """Create a folder"""
    if not visibility:
        visibility = 'WORKSPACE'
    params = {'name': name, 'visibility': visibility.upper()}
    query = folder_queries.create_folder_query
    r, json_data = utils.make_request(auth, query, params)

    if r.status_code == 200:
        if not json_data['data']['createFolder']['ok']:
            click.echo('\n' +
                       json_data['data']['createFolder']['error']['message'] +
                       '\n')
        else:
            click.echo(
                '\nThe %s folder "%s" has been successfully created in your Marvel account\n'
                % (visibility.lower(), name))
    else:
        click.echo(
            "\nTry 'marvelcli create-folder --help' to make sure you are not missing any args.\n"
        )
Пример #14
0
def add_members_to_group(group_pk: int, email: list, auth: str):
    """Add members to a group"""
    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:
        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:
        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'))

                click.echo(
                    "\nThe following people were successfully added to group %s: %s"
                    % (group_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')))

            click.echo("\n")
Пример #15
0
def remove_members_from_group(group_pk: int, email: list, auth: str):
    """Remove members from a group"""
    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:
        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:
        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:
                click.echo(
                    "\nThe following people were successfully removed from group %s: %s"
                    % (group_pk, data_success))

            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')))

            click.echo("\n")