Skip to content

Cli

ldap()

The LDAP CLI.

Source code in ckanext/ldap/cli.py
 9
10
11
12
13
14
@click.group()
def ldap():
    """
    The LDAP CLI.
    """
    pass

setup_org()

Sets up the default organisation which all ldap users will be automatically made members of.

Source code in ckanext/ldap/cli.py
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
@ldap.command(name='setup-org')
def setup_org():
    """
    Sets up the default organisation which all ldap users will be automatically made
    members of.
    """
    # get the organisation all users will be added to
    organization_id = toolkit.config['ckanext.ldap.organization.id']

    # set up context
    user = toolkit.get_action('get_site_user')({'ignore_auth': True}, {})
    context = {'user': user['name']}

    try:
        toolkit.get_action('organization_show')(context, {'id': organization_id})
        click.secho('Organisation already exists, doing nothing', fg='green')
    except toolkit.ObjectNotFound:
        # see the following commit to understand why this line is here
        # http://github.com/ckan/ckanext-harvest/commit/f315f41c86cbde4a49ef869b6993598f8cb11e2d
        context.pop('__auth_audit', None)
        toolkit.get_action('organization_create')(
            context, {'id': organization_id, 'name': organization_id}
        )
        click.secho('New organisation created', fg='green')