Group

Supported by Redmine starting from version 2.1

Manager

All operations on the Group resource are provided by its manager. To get access to it you have to call redmine.group 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 Group resource with given fields and saves it to the Redmine.

Parameters:
  • name (string) – (required). Group name.

  • user_ids (list) – (optional). Ids of users who will be members of a group.

Returns:

Resource object

>>> group = redmine.group.create(name='Developers', user_ids=[13, 15, 25])
>>> group
<redminelib.resources.Group #8 "Developers">

new

redminelib.managers.ResourceManager.new()

Creates new empty Group 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

>>> group = redmine.group.new()
>>> group.name = 'Developers'
>>> group.user_ids = [13, 15, 25]
>>> group.save()
<redminelib.resources.Group #8 "Developers">

Read methods

get

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

Returns single group resource from Redmine by its id.

Parameters:
  • resource_id (int) – (required). Id of the group.

  • include (list) – (optional). Fetches associated data in one call. Accepted values:

    • memberships

    • users

Returns:

Resource object

>>> group = redmine.group.get(524, include=['memberships', 'users'])
>>> group
<redminelib.resources.Group #524 "DESIGN">

Hint

Group 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 Group 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 Group resource object are the same as in the get() method above:

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

all

redminelib.managers.ResourceManager.all()

Returns all Group 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

>>> groups = redmine.group.all()
>>> groups
<redminelib.resultsets.ResourceSet object with Group resources>

filter

Not supported by Redmine

Update methods

update

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

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

Parameters:
  • resource_id (int) – (required). Group id.

  • name (string) – (optional). Group name.

  • user_ids (list) – (optional). Ids of users who will be members of a group.

Returns:

True

>>> redmine.group.update(1, name='Developers', user_ids=[13, 15, 25])
True

save

redminelib.resources.Group.save(**attrs)

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

Returns:

Resource object

>>> group = redmine.group.get(1)
>>> group.name = 'Developers'
>>> group.user_ids = [13, 15, 25]
>>> group.save()
<redminelib.resources.Group #1 "Developers">

Added in version 2.1.0: Alternative syntax was introduced.

>>> group = redmine.group.get(1).save(
...     name='Developers',
...     user_ids=[13, 15, 25]
... )
>>> group
<redminelib.resources.Group #1 "Developers">

Delete methods

delete

redminelib.managers.ResourceManager.delete(resource_id)

Deletes single Group resource from Redmine by its id.

Parameters:

resource_id (int) – (required). Group id.

Returns:

True

>>> redmine.group.delete(1)
True
redminelib.resources.Group.delete()

Deletes current Group resource object from Redmine.

Returns:

True

>>> group = redmine.group.get(1)
>>> group.delete()
True

Export

Not supported by Redmine

Users

Python-Redmine provides 2 methods to work with group users:

add

redminelib.resources.Group.User.add(user_id)

Adds a user to a group by its id.

Parameters:

user_id (int) – (required). User id.

Returns:

True

>>> group = redmine.group.get(1)
>>> group.user.add(1)
True

remove

redminelib.resources.Group.User.remove(user_id)

Removes a user from a group by its id.

Parameters:

user_id (int) – (required). User id.

Returns:

True

>>> group = redmine.group.get(1)
>>> group.user.remove(1)
True