Beispiel #1
0
    def set_project_users(self, users):
        from pybossa.cache.users import get_users_access_levels
        from pybossa.data_access import can_assign_user

        valid_users = set([])
        proj_levels = self.info.get('data_access', [])
        if not proj_levels:
            return

        users = get_users_access_levels(users)
        for user in users:
            user_levels = user.get('data_access', [])
            if can_assign_user(proj_levels, user_levels):
                valid_users.add(user['id'])
        self.info['project_users'] = list(valid_users)
Beispiel #2
0
def ensure_user_assignment_to_project(project):
    from pybossa.cache.users import get_users_access_levels

    access_levels = project.info.get('data_access')
    ensure_valid_access_levels(access_levels)
    if not project.info.get('project_users'):
        return

    # ensure users assigned to project has project access levels
    project_levels = project.info['data_access']
    users = project.info['project_users']
    users = get_users_access_levels(users)
    invalid_user_ids = set()
    for user in users:
        user_levels = user.get('data_access', [])
        if not can_assign_user(project_levels, user_levels):
            invalid_user_ids.add(user['id'])
    if invalid_user_ids:
        raise ValueError(u'Data access level mismatch. Cannot assign user {} to project'
            .format(', '.join(map(str, invalid_user_ids))))