Skip to main content

User and group management

Project description

Latest PyPI version Number of PyPI downloads https://travis-ci.org/bluedynamics/cone.ugm.svg?branch=master https://coveralls.io/repos/github/bluedynamics/cone.ugm/badge.svg?branch=master

Plugin for cone.app providing a user and group management UI.

Features

  • Users and Groups CRUD

  • Principal membership of users and groups

  • Roles support

  • Local Manager Support

  • User and group form configuration

Setup

Prerequirements

While installation lxml gets compiled, the required dev headers must be installed on the system.

On debian based systems install:

$ apt-get install -y libxml2-dev libxslt1-dev

Development and Testing

For testing and development, cone.ugm contains a buildout configuration. Download or checkout package and run:

cone.ugm$ ./bootstrap.sh python3

Example Configuration

For testing and demo purposes, an example UGM configuration is contained in the cfg folder of the source package.

It contains the configuration file ugm.xml, containing the general UGM configuration and localmanager.xml, containing the configuration about local users and groups management. These two files can be edited TTW via the settings UI.

The ugm.ini file contains the application configuration:

[app:ugm]
...

cone.plugins =
    cone.ugm

ugm.backend = file
ugm.config = %(here)s/ugm.xml
ugm.localmanager_config = %(here)s/localmanager.xml

ugm.users_file = %(here)s/../parts/ugm/users
ugm.groups_file = %(here)s/../parts/ugm/groups
ugm.roles_file = %(here)s/../parts/ugm/roles
ugm.datadir = %(here)s/../parts/ugm/data

...

In this example the file backend is configured as UGM backend. For configuring SQL or LDAP based backends, see documentation at cone.sql respective cone.ldap.

Start the application:

cone.ugm$ ./bin/pserver cfg/ugm.ini

and browse http://localhost:8081/. Default admin user password is admin.

Configuration and Customization

General

For customizing the plugin, make an integration package and include it in your setup.

Roles

cone.ugm internally uses 3 roles in order to permit user actions.

editor is permitted to manage membership, admin additionally is permitted to add, edit and delete users and groups, and manager is a superuser. If UGM is the only plugin used, you can reduce the available roles to this three:

cone.app.security.DEFAULT_ROLES = [
    ('editor', 'Editor'),
    ('admin', 'Admin'),
    ('manager', 'Manager')
]

Principal Forms

The basic principal form customization happens in the ugm XML configuration file. Each field to render must have an entry in users_form_attrmap respective groups_form_attrmap:

<users_form_attrmap>
  <elem>
    <key>my_field</key>
    <value>My Field</value>
  </elem>
</users_form_attrmap>

By default, a non required text field gets rendered for each custom entry in the XML configuration.

To make a custom field required, the easiest way is to use default_form_field_factory and register it with user_field respective group_field:

from cone.ugm.browser.principal import default_form_field_factory
from cone.ugm.browser.principal import user_field
from functools import partial

my_field_factory = user_field('my_field')(
    partial(default_form_field_factory, required=True)
)

It’s possible to register custom principal field factories for dedicated UGM backends. This example is taken from cone.ldap and registers a user field factory for cn attribute in ldap backend:

ldap_cn_field_factory = user_field('cn', backend='ldap')(
    partial(default_form_field_factory, required=True)
)

The most flexible way for principal form field customization is to provide a callback function and call the yafowil factory directly:

from yafowil.base import factory

@user_field('age')
def age_field_factory(form, label, value):
    return factory(
        'field:label:error:number',
        value=value,
        props={
            'label': label,
            'datatype': int
        })

Note. The value of the custom field gets written to principal attributes as extracted from the widget. Make sure to define the expected datatype in the widget properties or define a suitable custom extractor.

Principal Listings

XXX

Object Events

You can react to creation, modification and deletion of users and groups by binding to the given event classes.

These events are fired when the user manipulations are done in the UGM management forms.

necessary imports:

from zope.event import classhandler
from cone.ugm import events

Defining the event handlers

for users:

@classhandler.handler(events.UserCreatedEvent)
def on_user_created(event):
    print(f"user {event.principal} with id {event.principal.name} created")

@classhandler.handler(events.UserModifiedEvent)
def on_user_modified(event):
    print(f"user {event.principal} with id {event.principal.name} modified")

@classhandler.handler(events.UserDeletedEvent)
def on_user_deleted(event):
    print(f"user {event.principal} with id {event.principal.name} deleted")

and for groups:

@classhandler.handler(events.GroupCreatedEvent)
def on_group_created(event):
    print(f"group {event.principal} with id {event.principal.name} created")

@classhandler.handler(events.GroupModifiedEvent)
def on_group_modified(event):
    print(f"group {event.principal} with id {event.principal.name} modified")

@classhandler.handler(events.GroupDeletedEvent)
def on_group_deleted(event):
    print(f"group {event.principal} with id {event.principal.name} deleted")

Contributors

  • Robert Niederreiter (Author)

  • Florian Friesdorf

  • Jens Klein

Changes

1.0a7 (2023-02-02)

  • Catch AttributeError in model.user.User.expires. Happens in user add form where user not exists yet. [rnix]

1.0a6 (2022-12-05)

  • Remove expiration yafowil blueprint from cone.ugm.browser.expires. Account expiration is now done with a regular date field since UGM backends allow setting expires attributes as datetime objects as of node.ext.ugm 1.1. [rnix]

  • Move users_expires_attr and users_expires_unit settings to cone.ldap, since they always have been used only for LDAP UGM backend. [rnix]

  • Expose expires attribute of backend user in cone.ugm.model.User. [rnix]

  • Fix general settings form according to changes in yafowil 3.0. [rnix]

1.0a5 (2022-10-06)

  • Replace deprecated use of Nodify by MappingNode. [rnix]

1.0a4 (2021-11-08)

  • Adopt import path of safe_decode and node_path. [rnix]

1.0a3 (2021-10-25)

  • Fix UsersListing and GroupsListing search filter to ignore None values.

  • Increase listing slice size to 15. [rnix]

  • Add change_password form. [rnix]

  • Add support for objects events on user and group add/modify/delete. [zworkb]

1.0a2 (2020-11-12)

  • Fix delete principal. [rnix]

1.0a1 (2020-07-09)

  • Use ContentAddForm and ContentEditForm behaviors instead of B/C AddBehavior and EditBehavior for user and group form. [rnix]

  • Use layout_config decorator introduced in cone.app 1.0rc1. [rnix]

  • Remove cone.ugm.model.users.users_factory and cone.ugm.model.groups.groups_factory. Register related node classes directly as app entries. [rnix]

  • Bind UGM columns content view to UGM models. [rnix]

  • Move LDAP related code to cone.ldap. [rnix]

  • Users autoincrement start setting value may be empty in config. [rnix]

  • Do not remember users and groups on volatile storage. [rnix]

  • Use IUgm.invalidate for invalidation of users and groups on UGM backend. [rnix]

  • Rename cone.ugm.browser.listing.ColumnListing.query_items to listing_items. [rnix]

  • Turn cone.ugm.browser.group.Users and cone.ugm.browser.user.Groups property descriptors into ColumnListing deriving tiles. [rnix]

  • Remove superfluous jQuery.sortElements.js and naturalSort.js. [rnix]

  • Move plugin config code inside main hook function. [rnix]

  • Python 3 Support. [rnix]

  • Convert doctests to unittests. [rnix]

  • Use cone.app.ugm.ugm_backend instead of cone.app.cfg.auth. [rnix]

  • Use cone.tile.tile decorator instead of cone.tile.registerTile. [rnix]

  • Use request.has_permission instead of pyramid.security.has_permission. [rnix]

  • Remove inout widget. Listing widget is the only principal membership now. Remove corresponding default_membership_assignment_widget, user_display_name_attribute and group_display_name_attribute from settings [rnix]

  • Change UI. Principal form and principal membership are not displayed in right column together any more. When viewing a principals content, left column displays the listing and right column the principal form. When viewing a principal, left column displays the principal form and right column displays the principal membership. [rnix]

  • Update to cone.app >= 1.0. [rnix]

  • Change license to LGPLv3. [rnix]

0.9.7

  • Directly depend on lxml in setup.py [rnix, 2014-05-13]

0.9.6

  • Adopt dependencies. [rnix, 2013-01-10]

0.9.5

  • Portrait CSS fix. [rnix, 2012-10-30]

  • Python 2.7 Support. [rnix, 2012-10-16]

  • adopt to cone.app 0.9.4 [rnix, 2012-07-29]

  • adopt to node 0.9.8 [rnix, 2012-07-29]

  • adopt to plumber 1.2 [rnix, 2012-07-29]

  • Simplify cone.ugm.browser.actions. [rnix, 2012-07-26]

  • Add local manager functionality. [rnix, 2012-07-25]

0.9.4

  • Get rid of BBB classes usage from cone.app. [rnix, 2012-05-18]

  • Fix invalidation after settings form save. [rnix, 2012-04-23]

  • Portrait Image support. [rnix, 2012-04-21]

  • Configuration for attributes exposed to attribute map. [rnix, 2012-04-19]

  • Invalidate after creating principal or roles container. [rnix, 2012-04-19]

  • Adopt expires blueprint to yafowil.widget.datetime 1.3. [rnix, 2012-04-19]

0.9.3

  • Add Autoincrement Feature for user ids. [rnix, 2012-03-30]

0.9.2

  • Account expiration widget improvements. [rnix, 2012-03-20]

0.9.1

  • Add account expiration functionality. [rnix, 2011-03-06]

  • Make display field of In-Out widget configurable. [rnix, 2011-01-31]

  • Dynamic width CSS. [rnix, 2011-12-18]

  • Get rid of global cone.ugm.backend. cone.app.cfg.auth is returend by cone.ugm.model.utils.ugm_backend. [rnix, 2011-11-22]

  • Explicit names for settings forms. [rnix, 2011-11-18]

  • Add node properties for users and groups to get displayed in navtree if displayed. [rnix, 2011-11-16]

0.9

  • Initial release.

License

GNU LESSER GENERAL PUBLIC LICENSE

Version 3, 29 June 2007

Copyright © 2007 Free Software Foundation, Inc. <https://fsf.org/>

Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed.

This version of the GNU Lesser General Public License incorporates the terms and conditions of version 3 of the GNU General Public License, supplemented by the additional permissions listed below.

  1. Additional Definitions.

As used herein, “this License” refers to version 3 of the GNU Lesser General Public License, and the “GNU GPL” refers to version 3 of the GNU General Public License.

“The Library” refers to a covered work governed by this License, other than an Application or a Combined Work as defined below.

An “Application” is any work that makes use of an interface provided by the Library, but which is not otherwise based on the Library. Defining a subclass of a class defined by the Library is deemed a mode of using an interface provided by the Library.

A “Combined Work” is a work produced by combining or linking an Application with the Library. The particular version of the Library with which the Combined Work was made is also called the “Linked Version”.

The “Minimal Corresponding Source” for a Combined Work means the Corresponding Source for the Combined Work, excluding any source code for portions of the Combined Work that, considered in isolation, are based on the Application, and not on the Linked Version.

The “Corresponding Application Code” for a Combined Work means the object code and/or source code for the Application, including any data and utility programs needed for reproducing the Combined Work from the Application, but excluding the System Libraries of the Combined Work.

  1. Exception to Section 3 of the GNU GPL.

You may convey a covered work under sections 3 and 4 of this License without being bound by section 3 of the GNU GPL.

  1. Conveying Modified Versions.

If you modify a copy of the Library, and, in your modifications, a facility refers to a function or data to be supplied by an Application that uses the facility (other than as an argument passed when the facility is invoked), then you may convey a copy of the modified version:

  1. under this License, provided that you make a good faith effort to ensure that, in the event an Application does not supply the function or data, the facility still operates, and performs whatever part of its purpose remains meaningful, or

  2. under the GNU GPL, with none of the additional permissions of this License applicable to that copy.

  1. Object Code Incorporating Material from Library Header Files.

The object code form of an Application may incorporate material from a header file that is part of the Library. You may convey such object code under terms of your choice, provided that, if the incorporated material is not limited to numerical parameters, data structure layouts and accessors, or small macros, inline functions and templates (ten or fewer lines in length), you do both of the following:

  1. Give prominent notice with each copy of the object code that the Library is used in it and that the Library and its use are covered by this License.

  2. Accompany the object code with a copy of the GNU GPL and this license document.

  1. Combined Works.

You may convey a Combined Work under terms of your choice that, taken together, effectively do not restrict modification of the portions of the Library contained in the Combined Work and reverse engineering for debugging such modifications, if you also do each of the following:

  1. Give prominent notice with each copy of the Combined Work that the Library is used in it and that the Library and its use are covered by this License.

  2. Accompany the Combined Work with a copy of the GNU GPL and this license document.

  3. For a Combined Work that displays copyright notices during execution, include the copyright notice for the Library among these notices, as well as a reference directing the user to the copies of the GNU GPL and this license document.

  4. Do one of the following:

    1. Convey the Minimal Corresponding Source under the terms of this License, and the Corresponding Application Code in a form suitable for, and under terms that permit, the user to recombine or relink the Application with a modified version of the Linked Version to produce a modified Combined Work, in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source.

    2. Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (a) uses at run time a copy of the Library already present on the user’s computer system, and (b) will operate properly with a modified version of the Library that is interface-compatible with the Linked Version.

  5. Provide Installation Information, but only if you would otherwise be required to provide such information under section 6 of the GNU GPL, and only to the extent that such information is necessary to install and execute a modified version of the Combined Work produced by recombining or relinking the Application with a modified version of the Linked Version. (If you use option 4d0, the Installation Information must accompany the Minimal Corresponding Source and Corresponding Application Code. If you use option 4d1, you must provide the Installation Information in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source.)

  1. Combined Libraries.

You may place library facilities that are a work based on the Library side by side in a single library together with other library facilities that are not Applications and are not covered by this License, and convey such a combined library under terms of your choice, if you do both of the following:

  1. Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities, conveyed under the terms of this License.

  2. Give prominent notice with the combined library that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work.

  1. Revised Versions of the GNU Lesser General Public License.

The Free Software Foundation may publish revised and/or new versions of the GNU Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns.

Each version is given a distinguishing version number. If the Library as you received it specifies that a certain numbered version of the GNU Lesser General Public License “or any later version” applies to it, you have the option of following the terms and conditions either of that published version or of any later version published by the Free Software Foundation. If the Library as you received it does not specify a version number of the GNU Lesser General Public License, you may choose any version of the GNU Lesser General Public License ever published by the Free Software Foundation.

If the Library as you received it specifies that a proxy can decide whether future versions of the GNU Lesser General Public License shall apply, that proxy’s public statement of acceptance of any version is permanent authorization for you to choose that version for the Library.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cone.ugm-1.0a7.tar.gz (77.8 kB view hashes)

Uploaded Source

Built Distribution

cone.ugm-1.0a7-py3-none-any.whl (100.5 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page