Exemplo n.º 1
0
    def test_can_assign_user(self):
        with patch.dict(data_access.data_access_levels, self.patched_levels()):
            proj_levels = ["L3"]
            user_levels = ["L2", "L4"]
            assign_users = data_access.can_assign_user(proj_levels,
                                                       user_levels)
            assert assign_users

            proj_levels = ["L5"]
            user_levels = ["L2", "L4"]
            assign_users = data_access.can_assign_user(proj_levels,
                                                       user_levels)
            assert not assign_users, "project level should be reported invalid"

            proj_levels = ["L3"]
            user_levels = ["L2", "L6"]
            assign_users = data_access.can_assign_user(proj_levels,
                                                       user_levels)
            assert not assign_users, "user levels should be reported invalid"

            proj_levels = ["L1"]
            user_levels = ["L2", "L4"]
            assign_users = data_access.can_assign_user(proj_levels,
                                                       user_levels)
            assert not assign_users, "user with level L2, L4 cannot be assigned to project with level L1"

            proj_levels = ["L2"]
            user_levels = ["L1"]
            assign_users = data_access.can_assign_user(proj_levels,
                                                       user_levels)
            assert assign_users, "user with level L1 can work on project with level L2; user should be assigned"
Exemplo n.º 2
0
    def test_can_assign_user(self):
        from pybossa import data_access

        with patch.object(data_access, 'data_access_levels',
                          self.patch_data_access_levels):
            proj_levels = ["L3"]
            user_levels = ["L2", "L4"]
            assign_users = data_access.can_assign_user(proj_levels,
                                                       user_levels)
            assert assign_users

            proj_levels = ["L5"]
            user_levels = ["L2", "L4"]
            assign_users = data_access.can_assign_user(proj_levels,
                                                       user_levels)
            assert not assign_users, "project level should be reported invalid"

            proj_levels = ["L3"]
            user_levels = ["L2", "L6"]
            assign_users = data_access.can_assign_user(proj_levels,
                                                       user_levels)
            assert not assign_users, "user levels should be reported invalid"

            proj_levels = ["L1"]
            user_levels = ["L2", "L4"]
            assign_users = data_access.can_assign_user(proj_levels,
                                                       user_levels)
            assert not assign_users, "user with level L2, L4 cannot be assigned to project with level L1"

            proj_levels = ["L2"]
            user_levels = ["L1"]
            assign_users = data_access.can_assign_user(proj_levels,
                                                       user_levels)
            assert assign_users, "user with level L1 can work on project with level L2; user should be assigned"
Exemplo n.º 3
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)