User

Supported by Redmine starting from version 1.1

Manager

All operations on the User resource are provided by it’s manager. To get access to it you have to call redmine.user where redmine is a configured redmine object. See the Configuration about how to configure redmine object.

Create methods

create

redminelib.managers.ResourceManager.create(**fields)

Creates new User resource with given fields and saves it to the Redmine.

Parameters:
  • login (string) – (required). User login.
  • password (string) – (optional). User password.
  • firstname (string) – (required). User name.
  • lastname (string) – (required). User surname.
  • mail (string) – (required). User email.
  • auth_source_id (int) – (optional). Authentication mode id.
  • mail_notification (string) – (optional). Type of mail notification, one of:
    • all
    • selected
    • only_my_events
    • only_assigned
    • only_owner
    • none
  • notified_project_ids (list) – (optional). Project IDs for a “selected” mail notification type.
  • must_change_passwd (bool) – (optional). Whether user must change password.
  • custom_fields (list) – (optional). Custom fields as [{‘id’: 1, ‘value’: ‘foo’}].
Returns:

Resource object

>>> user = redmine.user.create(
...     login='jsmith',
...     password='qwerty',
...     firstname='John',
...     lastname='Smith',
...     mail='john@smith.com',
...     auth_source_id=1,
...     mail_notification='selected',
...     notified_project_ids=[1, 2],
...     must_change_passwd=True,
...     custom_fields=[{'id': 1, 'value': 'foo'}, {'id': 2, 'value': 'bar'}]
... )
>>> user
<redminelib.resources.User #32 "John Smith">

new

redminelib.managers.ResourceManager.new()

Creates new empty User resource but saves it to the Redmine only when save() is called, also calls pre_create() and post_create() methods of the Resource object. Valid attributes are the same as for create() method above.

Returns:Resource object
>>> user = redmine.user.new()
>>> user.login = 'jsmith'
>>> user.password = 'qwerty'
>>> user.firstname = 'John
>>> user.lastname = 'Smith'
>>> user.mail = 'john@smith.com'
>>> user.auth_source_id = 1
>>> user.mail_notification = 'selected'
>>> user.notified_project_ids = [1, 2]
>>> user.must_change_passwd = True
>>> user.custom_fields = [{'id': 1, 'value': 'foo'}, {'id': 2, 'value': 'bar'}]
>>> user.save()
True

Read methods

get

redminelib.managers.ResourceManager.get(resource_id, **params)

Returns single User resource from Redmine by it’s id.

Parameters:
  • resource_id (int) – (required). Id of the user.
  • include (string) – (optional). Can be used to fetch associated data in one call. Accepted values (separated by ,):
    • memberships
    • groups
Returns:

Resource object

>>> user = redmine.user.get(17, include='memberships,groups')
>>> user
<redminelib.resources.User #17 "John Smith">

Hint

You can easily get the details of the user whose credentials were used to access the API:

>>> user = redmine.user.get('current')
>>> user
<redminelib.resources.User #17 "John Smith">

Hint

User resource object provides you with on demand includes. On demand includes are the other resource objects wrapped in a ResourceSet which are associated with a User resource object. Keep in mind that on demand includes are retrieved in a separate request, that means that if the speed is important it is recommended to use get() method with include keyword argument. On demand includes provided by the User resource object are the same as in the get() method above:

>>> user = redmine.user.get(17)
>>> user.groups
<redminelib.resultsets.ResourceSet object with Group resources>

Hint

User resource object provides you with some relations. Relations are the other resource objects wrapped in a ResourceSet which are somehow related to a User resource object. The relations provided by the User resource object are:

  • issues
  • time_entries
  • deals (requires Pro Edition and CRM plugin)
  • contacts (requires Pro Edition and CRM plugin)
>>> user = redmine.user.get(17)
>>> user.issues
<redminelib.resultsets.ResourceSet object with Issue resources>

all

redminelib.managers.ResourceManager.all(**params)

Returns all User resources from Redmine.

Parameters:
  • limit (int) – (optional). How much resources to return.
  • offset (int) – (optional). Starting from what resource to return the other resources.
Returns:

ResourceSet object

>>> users = redmine.user.all(offset=10, limit=100)
>>> users
<redminelib.resultsets.ResourceSet object with User resources>

filter

redminelib.managers.ResourceManager.filter(**filters)

Returns User resources that match the given lookup parameters.

Parameters:
  • status (int) – (optional). Get only users with given status. One of:
    • 0 - anonymous
    • 1 - active (default)
    • 2 - registered
    • 3 - locked
  • name (string) – (optional). Filter users on their login, firstname, lastname and mail. If the pattern contains a space, it will also return users whose firstname match the first word or lastname match the second word.
  • group_id (int) – (optional). Get only members of the given group.
  • limit (int) – (optional). How much resources to return.
  • offset (int) – (optional). Starting from what resource to return the other resources.
Returns:

ResourceSet object

>>> users = redmine.user.filter(offset=10, limit=100, status=3)
>>> users
<redminelib.resultsets.ResourceSet object with User resources>

Hint

You can also get users from a Group resource object directly using users on demand includes:

>>> group = redmine.group.get(524)
>>> group.users
<redminelib.resultsets.ResourceSet object with User resources>

Update methods

update

redminelib.managers.ResourceManager.update(resource_id, **fields)

Updates values of given fields of a User resource and saves them to the Redmine.

Parameters:
  • resource_id (int) – (required). User id.
  • login (string) – (optional). User login.
  • password (string) – (optional). User password.
  • firstname (string) – (optional). User name.
  • lastname (string) – (optional). User surname.
  • mail (string) – (optional). User email.
  • auth_source_id (int) – (optional). Authentication mode id.
  • mail_notification (string) – (optional). Type of mail notification, one of:
    • all
    • selected
    • only_my_events
    • only_assigned
    • only_owner
    • none
  • notified_project_ids (list) – (optional). Project IDs for a “selected” mail notification type.
  • must_change_passwd (bool) – (optional). Whether user must change password.
  • custom_fields (list) – (optional). Custom fields as [{‘id’: 1, ‘value’: ‘foo’}].
Returns:

True

>>> redmine.user.update(
...     1,
...     login='jsmith',
...     password='qwerty',
...     firstname='John',
...     lastname='Smith',
...     mail='john@smith.com',
...     auth_source_id=1,
...     mail_notification='selected',
...     notified_project_ids=[1, 2],
...     must_change_passwd=True,
...     custom_fields=[{'id': 1, 'value': 'foo'}, {'id': 2, 'value': 'bar'}]
... )
True

save

redminelib.resources.User.save()

Saves the current state of a User resource to the Redmine. Fields that can be changed are the same as for update() method above.

Returns:True
>>> user = redmine.user.get(1)
>>> user.login = 'jsmith'
>>> user.password = 'qwerty'
>>> user.firstname = 'John'
>>> user.lastname = 'Smith'
>>> user.mail = 'john@smith.com'
>>> user.auth_source_id = 1
>>> user.mail_notification = 'selected'
>>> user.notified_project_ids = [1, 2]
>>> user.must_change_passwd = True
>>> user.custom_fields = [{'id': 1, 'value': 'foo'}, {'id': 2, 'value': 'bar'}]
>>> user.save()
True

Delete methods

delete

redminelib.managers.ResourceManager.delete(resource_id)

Deletes single User resource from Redmine by it’s id.

Parameters:resource_id (int) – (required). User id.
Returns:True
>>> redmine.user.delete(1)
True
redminelib.resources.User.delete()

Deletes current User resource object from Redmine.

Returns:True
>>> user = redmine.user.get(1)
>>> user.delete()
True

Export

Not supported by Redmine