def group(self, name, description, users=None, debug=False):

        r = GroupResource(self)
        valid_fields = [("name", name),
                        ("description", description)]

        if self.module.params['state'] == 'present':
            if r.name_exists(name):
                ret = r.update_by_name(name, {k: v for k, v in valid_fields
                                              if v is not None})
            else:
                ret = r.create({k: v for k, v in valid_fields
                                if v is not None})

            if users is not None:
                ret["added"] = []
                ret["removed"] = []
                ret["updated"] = []

                group_id = ret['_id']

                # Validate and normalize the user list
                for user in users:
                    assert "login" in user.keys(), \
                        "User list must have a login attribute"

                    user['type'] = self.access_types.get(
                        user.get('type', 'member'), "member")

                # dict of passed in login -> type
                user_levels = {u['login']: u['type'] for u in users}

                # dict of current login -> user information for this group
                members = {m['login']: m for m in
                           self.get('group/{}/member'.format(group_id))}

                # Add these users
                for login in (set(members.keys()) - set(user_levels.keys())):
                    user = self._get_user_by_login(login)
                    if user is not None:
                        # add user at level
                        self.post("group/{}/invitation".format(group_id),
                                  {"userId": user["_id"],
                                   "level": user_levels[login],
                                   "quiet": True,
                                   "force": True})
                        ret['added'].append(user)
                    else:
                        raise Exception('{} is not a valid login!'
                                        .format(login))

                # Remove these users
                for login in (set(members.keys()) - set(user_levels.keys())):
                    self.delete("/group/{}/member".format(group_id),
                                {"userId": members[login]['_id']})
                    ret['removed'].append(members[login])

                # Set of users that potentially need to be updated
                if len(set(members.keys()) & set(user_levels.keys())):
                    group_access = self.get('group/{}/access'.format(group_id))
                    # dict of current login -> access information for this group
                    user_access = {m['login']: m
                                   for m in group_access['access']['users']}

                    # dict of login -> level for the current group
                    # Note:
                    #  Here we join members with user_access - if the member
                    #  is not in user_access then the member has a level of 0 by
                    #  default. This gives us  a complete list of every login,
                    #  and its access level, including those that are IN the
                    #  group, but have no permissions ON the group.
                    member_levels = {m['login']:
                                     user_access.get(m['login'],
                                                     {"level": 0})['level']
                                     for m in members.values()}

                    ret = self._promote_or_demote_in_group(ret,
                                                           member_levels,
                                                           user_levels,
                                                           group_id)

                # Make sure 'changed' is handled correctly if we've
                # manipulated the group's users in any way
                if (len(ret['added']) != 0 or len(ret['removed']) != 0 or
                        len(ret['updated']) != 0):
                    self.changed = True

        elif self.module.params['state'] == 'absent':
            ret = r.delete_by_name(name)

        return ret
dataset/ETHPy150Open girder/girder/clients/ansible/girder.py/GirderClientModule.group/swapped operands of `-`