Ejemplo n.º 1
0
def project_admin_list(context, data_dict):
    '''
    Return a list of dicts containing the id and name of all active project
    admin users.

    :rtype: list of dictionaries
    '''

    toolkit.check_access('ckanext_project_admin_list', context, data_dict)

    model = context["model"]

    user_ids = projectAdmin.get_project_admin_ids()

    if user_ids:
        q = model.Session.query(model.User) \
            .filter(model.User.state == 'active') \
            .filter(model.User.id.in_(user_ids))

        project_admin_list = []
        for user in q.all():
            project_admin_list.append({'name': user.name, 'id': user.id})
        return project_admin_list

    return []
Ejemplo n.º 2
0
    def test_project_admin_add_no_args(self):
        '''
        Calling ckanext_project_admin_add with no args raises ValidationError
        and no projectAdmin object is created.
        '''
        nosetools.assert_raises(toolkit.ValidationError, helpers.call_action,
                                'ckanext_project_admin_add', context={})

        nosetools.assert_equal(model.Session.query(projectAdmin).count(), 0)
        nosetools.assert_equal(projectAdmin.get_project_admin_ids(), [])
Ejemplo n.º 3
0
    def test_project_admin_add_multiple_users(self):
        '''
        Calling ckanext_project_admin_add for multiple users correctly adds
        them to project admin list.
        '''
        user_to_add = factories.User()
        second_user_to_add = factories.User()

        nosetools.assert_equal(model.Session.query(projectAdmin).count(), 0)

        helpers.call_action('ckanext_project_admin_add', context={},
                            username=user_to_add['name'])

        helpers.call_action('ckanext_project_admin_add', context={},
                            username=second_user_to_add['name'])

        nosetools.assert_equal(model.Session.query(projectAdmin).count(), 2)
        nosetools.assert_true(user_to_add['id'] in projectAdmin.get_project_admin_ids())
        nosetools.assert_true(second_user_to_add['id'] in projectAdmin.get_project_admin_ids())
Ejemplo n.º 4
0
    def test_project_admin_add_username_doesnot_exist(self):
        '''
        Calling ckanext_project_admin_add with non-existent username raises
        ValidationError and no projectAdmin object is created.
        '''
        nosetools.assert_raises(toolkit.ObjectNotFound, helpers.call_action,
                                'ckanext_project_admin_add', context={},
                                username='******')

        nosetools.assert_equal(model.Session.query(projectAdmin).count(), 0)
        nosetools.assert_equal(projectAdmin.get_project_admin_ids(), [])
Ejemplo n.º 5
0
    def test_project_admin_delete_user_removes_project_admin_object(self):
        '''
        Deleting a user also deletes the corresponding projectAdmin object.
        '''
        user = factories.User()

        helpers.call_action('ckanext_project_admin_add', context={},
                            username=user['name'])

        # There's a projectAdmin object
        nosetools.assert_equal(model.Session.query(projectAdmin).count(), 1)
        nosetools.assert_true(user['id'] in projectAdmin.get_project_admin_ids())

        # purge the user, should also delete the projectAdmin object
        # associated with it.
        user_obj = model.Session.query(model.User).get(user['id'])
        user_obj.purge()
        model.repo.commit_and_remove()

        # The projectAdmin has also been removed
        nosetools.assert_equal(model.Session.query(projectAdmin).count(), 0)
        nosetools.assert_equal(projectAdmin.get_project_admin_ids(), [])
Ejemplo n.º 6
0
    def test_project_admin_add_creates_project_admin_user(self):
        '''
        Calling ckanext_project_admin_add adds user to project admin list.
        '''
        user_to_add = factories.User()

        nosetools.assert_equal(model.Session.query(projectAdmin).count(), 0)

        helpers.call_action('ckanext_project_admin_add', context={},
                            username=user_to_add['name'])

        nosetools.assert_equal(model.Session.query(projectAdmin).count(), 1)
        nosetools.assert_true(user_to_add['id'] in projectAdmin.get_project_admin_ids())
Ejemplo n.º 7
0
    def test_project_admin_remove_deletes_project_admin_user(self):
        '''
        Calling ckanext_project_admin_remove deletes projectAdmin object.
        '''
        user = factories.User()

        helpers.call_action('ckanext_project_admin_add', context={},
                            username=user['name'])

        # There's a projectAdmin obj
        nosetools.assert_equal(model.Session.query(projectAdmin).count(), 1)

        helpers.call_action('ckanext_project_admin_remove', context={},
                            username=user['name'])

        # There's no projectAdmin obj
        nosetools.assert_equal(model.Session.query(projectAdmin).count(), 0)
        nosetools.assert_equal(projectAdmin.get_project_admin_ids(), [])
Ejemplo n.º 8
0
def project_admin_list(context, data_dict):
    """
    Return a list of dicts containing the id and name of all active project
    admin users.

    :rtype: list of dictionaries
    """

    toolkit.check_access("ckanext_project_admin_list", context, data_dict)

    model = context["model"]

    user_ids = projectAdmin.get_project_admin_ids()

    if user_ids:
        q = model.Session.query(model.User).filter(model.User.state == "active").filter(model.User.id.in_(user_ids))

        project_admin_list = []
        for user in q.all():
            project_admin_list.append({"name": user.name, "id": user.id})
        return project_admin_list

    return []