def set_account_password(self, account, raw_password): """ Account's password was changed. """ luser = self._get_account(account.username) changes = changeset(luser, { 'password': raw_password, }) save(changes, database=self._database)
def set_account_password(self, account, raw_password): """ Account's password was changed. """ luser = self._get_account(account.username) changes = changeset(luser, { 'password': raw_password, }) save(changes, database=self._database)
def remove_account_from_group(self, account, group): """ Remove account from group. """ lgroup: OpenldapGroup = self._get_group(group.name) person: OpenldapAccount = self._get_account(account.username) changes = changeset(lgroup, {}) changes = lgroup.remove_member(changes, person) save(changes, database=self._database)
def add_account_to_group(self, account, group): """ Add account to group. """ lgroup: OpenldapGroup = self._get_group(group.name) person: OpenldapAccount = self._get_account(account.username) changes = changeset(lgroup, {}) changes = lgroup.add_member(changes, person) save(changes, database=self._database)
def remove_account_from_group(self, account, group): """ Remove account from group. """ lgroup: OpenldapGroup = self._get_group(group.name) person: OpenldapAccount = self._get_account(account.username) changes = changeset(lgroup, {}) changes = lgroup.remove_member(changes, person) save(changes, database=self._database)
def add_account_to_group(self, account, group): """ Add account to group. """ lgroup: OpenldapGroup = self._get_group(group.name) person: OpenldapAccount = self._get_account(account.username) changes = changeset(lgroup, {}) changes = lgroup.add_member(changes, person) save(changes, database=self._database)
def save_account(self, account: Account) -> None: """ Account was saved. """ person = account.person if self._primary_group == 'institute': lgroup = self._get_group(person.institute.group.name) elif self._primary_group == 'default_project': if account.default_project is None: lgroup = self._get_group(self._default_primary_group) else: lgroup = self._get_group(account.default_project.group.name) else: raise RuntimeError("Unknown value of PRIMARY_GROUP.") if account.default_project is None: default_project = "none" else: default_project = account.default_project.pid try: luser = self._get_account(account.username) changes = changeset(luser, {}) new_user = False except ObjectDoesNotExist: new_user = True luser = self._account_class() changes = changeset(luser, {'uid': account.username}) changes = changes.merge({ 'gidNumber': lgroup['gidNumber'], 'givenName': person.first_name, 'sn': person.last_name, 'telephoneNumber': _str_or_none(person.telephone), 'mail': _str_or_none(person.email), 'title': _str_or_none(person.title), 'o': person.institute.name, 'cn': person.full_name, 'default_project': default_project, 'loginShell': account.shell, 'locked': account.is_locked() }) save(changes, database=self._database) if new_user: # add all groups for group in account.person.groups.all(): self.add_account_to_group(account, group)
def save_group(self, group): """ Group was saved. """ # If group already exists, take over existing group rather then error. try: lgroup = self._get_group(group.name) changes = changeset(lgroup, {}) except ObjectDoesNotExist: lgroup = self._group_class() changes = changeset(lgroup, { 'cn': group.name, }) changes = changes.merge({'description': group.description}) save(changes, database=self._database)
def delete_account(self, account): """ Account was deleted. """ try: luser = self._get_account(account.username) groups = luser['groups'].load(database=self._database) for group in groups: changes = changeset(group, {}) changes = group.remove_member(changes, luser) save(changes, database=self._database) delete(luser, database=self._database) except ObjectDoesNotExist: # it doesn't matter if it doesn't exist pass
def delete_account(self, account): """ Account was deleted. """ try: luser = self._get_account(account.username) groups = luser['groups'].load(database=self._database) for group in groups: changes = changeset(group, {}) changes = group.remove_member(changes, luser) save(changes, database=self._database) delete(luser, database=self._database) except ObjectDoesNotExist: # it doesn't matter if it doesn't exist pass
def save_account(self, account: Account) -> None: """ Account was saved. """ person = account.person if self._primary_group == 'institute': lgroup = self._get_group(person.institute.group.name) elif self._primary_group == 'default_project': if account.default_project is None: lgroup = self._get_group(self._default_primary_group) else: lgroup = self._get_group(account.default_project.group.name) else: raise RuntimeError("Unknown value of PRIMARY_GROUP.") if account.default_project is None: default_project = "none" else: default_project = account.default_project.pid try: luser = self._get_account(account.username) changes = changeset(luser, {}) new_user = False except ObjectDoesNotExist: new_user = True luser = self._account_class() changes = changeset(luser, { 'uid': account.username }) changes = changes.merge({ 'gidNumber': lgroup['gidNumber'], 'givenName': person.first_name, 'sn': person.last_name, 'telephoneNumber': _str_or_none(person.telephone), 'mail': _str_or_none(person.email), 'title': _str_or_none(person.title), 'o': person.institute.name, 'cn': person.full_name, 'default_project': default_project, 'loginShell': account.shell, 'locked': account.is_locked() }) save(changes, database=self._database) if new_user: # add all groups for group in account.person.groups.all(): self.add_account_to_group(account, group)
def save_group(self, group): """ Group was saved. """ # If group already exists, take over existing group rather then error. try: lgroup = self._get_group(group.name) changes = changeset(lgroup, {}) except ObjectDoesNotExist: lgroup = self._group_class() changes = changeset(lgroup, { 'cn': group.name, }) changes = changes.merge({ 'description': group.description }) save(changes, database=self._database)