Beispiel #1
0
    def _check_restrictions(cls):
        # If there are already users in the DB, don't bother
        if User.query.count() > 0:
            return

        if Restriction.query.count() == 0:
            if click.confirm(
                    orange('There are no permissions specified') +
                    ' - that means, that by default '
                    'users will not have access to any resources. Would you like to create '
                    'a default permission together with a default group now? (All users '
                    'would have access to every resource)',
                    default=True):
                default_group = Group(name='users')
                default_group._is_default = True
                default_group.save()

                default_restriction = Restriction(
                    name='can always use everything',
                    starts_at=datetime.utcnow(),
                    is_global=True)
                default_restriction.apply_to_group(default_group)

                click.echo(
                    green(
                        'Created a default group: {} and a permission "{}" '.
                        format(default_group.name, default_restriction.name) +
                        'allowing access to every resource '
                        'at any time.'))
            else:
                click.echo(
                    orange(
                        '[•] OK - not creating any permissions. Remember that you need to define permissions'
                        ' in order for users to be able to access the resources.'
                    ))
Beispiel #2
0
def test_more_than_one_default_group(tables, new_group):
    new_group.is_default = True
    new_group.save()

    another_group = Group(name='AnotherGroup')
    another_group.is_default = True
    another_group.save()

    defaults = Group.get_default_groups()
    assert new_group in defaults
    assert another_group in defaults
def test_get_default_groups(tables, client, new_group):
    new_group.is_default = True
    new_group.save()

    another_group = Group(name='Not a default group')
    another_group.save()

    resp = client.get(ENDPOINT + '?only_default=true', headers=HEADERS)
    resp_json = json.loads(resp.data.decode('utf-8'))

    assert resp.status_code == HTTPStatus.OK
    assert len(resp_json) == 1
    assert resp_json[0]['id'] == new_group.id
Beispiel #4
0
def create(group: Dict[str, Any]) -> Tuple[Content, HttpStatusCode]:
    try:
        new_group = Group(
            name=group['name'],
            is_default=group['isDefault'] if 'isDefault' in group else False)
        new_group.save()
    except AssertionError as e:
        content = {
            'msg': GROUP['create']['failure']['invalid'].format(reason=e)
        }
        status = HTTPStatus.UNPROCESSABLE_ENTITY.value
    except Exception as e:
        content = {'msg': GENERAL['internal_error'] + str(e)}
        status = HTTPStatus.INTERNAL_SERVER_ERROR.value
    else:
        content = {
            'msg': GROUP['create']['success'],
            'group': new_group.as_dict()
        }
        status = HTTPStatus.CREATED.value
    finally:
        return content, status
def test_on_signup_user_gets_added_to_all_default_groups_if_there_are_more_than_one(
        tables, client, new_group):
    new_group.is_default = True
    new_group.save()

    another_default_group = Group(name='AnotherDefaultGroup', is_default=True)
    another_default_group.save()

    data = {
        'email': '*****@*****.**',
        'username': '******',
        'password': '******'
    }
    resp = client.post(ENDPOINT + '/create',
                       data=json.dumps(data),
                       headers=HEADERS)
    resp_json = json.loads(resp.data.decode('utf-8'))

    assert resp.status_code == HTTPStatus.CREATED
    assert len(resp_json['user']['groups']) == 2
    assert resp_json['user']['groups'][0]['id'] == new_group.id
    assert resp_json['user']['groups'][1]['id'] == another_default_group.id
    assert new_group in User.get(resp_json['user']['id']).groups
    assert another_default_group in User.get(resp_json['user']['id']).groups
Beispiel #6
0
def new_group_with_member(new_user):
    group = Group(name='TestGroup1')
    group.save()
    group.add_user(new_user)
    return group