forked from Github-Mirrors/canaille
remove 'available_groups' Group classmethod (replaced by already existing 'all' LDAPObject method)
This commit is contained in:
parent
ffd85e5ee0
commit
f95bffadd6
4 changed files with 5 additions and 26 deletions
|
@ -302,7 +302,7 @@ def registration(data, hash):
|
|||
if "groups" not in form and invitation.groups:
|
||||
form["groups"] = wtforms.SelectMultipleField(
|
||||
_("Groups"),
|
||||
choices=[(group[1], group[0]) for group in Group.available_groups()],
|
||||
choices=[(group.dn, group.name) for group in Group.all()],
|
||||
render_kw={"readonly": "true"},
|
||||
)
|
||||
form.process(CombinedMultiDict((request.files, request.form)) or None, data=data)
|
||||
|
|
|
@ -174,13 +174,10 @@ def profile_form(write_field_names, readonly_field_names):
|
|||
if PROFILE_FORM_FIELDS.get(name)
|
||||
}
|
||||
|
||||
if (
|
||||
"groups" in write_field_names | readonly_field_names
|
||||
and Group.available_groups()
|
||||
):
|
||||
if "groups" in write_field_names | readonly_field_names and Group.all():
|
||||
fields["groups"] = wtforms.SelectMultipleField(
|
||||
_("Groups"),
|
||||
choices=[(group[1], group[0]) for group in Group.available_groups()],
|
||||
choices=[(group.dn, group.name) for group in Group.all()],
|
||||
render_kw={"placeholder": _("users, admins ...")},
|
||||
)
|
||||
|
||||
|
@ -228,6 +225,6 @@ class InvitationForm(FlaskForm):
|
|||
)
|
||||
groups = wtforms.SelectMultipleField(
|
||||
_("Groups"),
|
||||
choices=lambda: [(group[1], group[0]) for group in Group.available_groups()],
|
||||
choices=lambda: [(group.dn, group.name) for group in Group.all()],
|
||||
render_kw={},
|
||||
)
|
||||
|
|
|
@ -184,20 +184,6 @@ class Group(LDAPObject):
|
|||
DEFAULT_NAME_ATTRIBUTE = "cn"
|
||||
DEFAULT_USER_FILTER = "member={user.dn}"
|
||||
|
||||
@classmethod
|
||||
def available_groups(cls, conn=None):
|
||||
conn = conn or cls.ldap()
|
||||
try:
|
||||
name_attribute = current_app.config["LDAP"].get(
|
||||
"GROUP_NAME_ATTRIBUTE", Group.DEFAULT_NAME_ATTRIBUTE
|
||||
)
|
||||
except KeyError:
|
||||
return []
|
||||
|
||||
groups = cls.all(conn=conn)
|
||||
Group.ldap_object_attributes(conn=conn)
|
||||
return [(group[name_attribute][0], group.dn) for group in groups]
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
attribute = current_app.config["LDAP"].get(
|
||||
|
|
|
@ -4,15 +4,11 @@ from canaille.models import User
|
|||
|
||||
def test_no_group(app, slapd_connection):
|
||||
with app.app_context():
|
||||
assert Group.available_groups(conn=slapd_connection) == []
|
||||
assert Group.all(conn=slapd_connection) == []
|
||||
|
||||
|
||||
def test_set_groups(app, slapd_connection, user, foo_group, bar_group):
|
||||
with app.app_context():
|
||||
assert set(Group.available_groups(conn=slapd_connection)) == {
|
||||
("foo", foo_group.dn),
|
||||
("bar", bar_group.dn),
|
||||
}
|
||||
foo_dns = {m.dn for m in foo_group.get_members(conn=slapd_connection)}
|
||||
assert user.dn in foo_dns
|
||||
assert user.groups[0].dn == foo_group.dn
|
||||
|
|
Loading…
Reference in a new issue