forked from Github-Mirrors/canaille
add a 'all' utility class method to LDAPObject to retrieve all class instances
This commit is contained in:
parent
da1b911172
commit
8d804616fd
11 changed files with 18 additions and 14 deletions
|
@ -159,7 +159,7 @@ def firstlogin(uid):
|
||||||
@bp.route("/users")
|
@bp.route("/users")
|
||||||
@permissions_needed("manage_users")
|
@permissions_needed("manage_users")
|
||||||
def users(user):
|
def users(user):
|
||||||
users = User.filter()
|
users = User.all()
|
||||||
return render_template("users.html", users=users, menuitem="users")
|
return render_template("users.html", users=users, menuitem="users")
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -27,11 +27,11 @@ def clean():
|
||||||
|
|
||||||
setup_backend(current_app)
|
setup_backend(current_app)
|
||||||
|
|
||||||
for t in Token.filter():
|
for t in Token.all():
|
||||||
if t.is_expired():
|
if t.is_expired():
|
||||||
t.delete()
|
t.delete()
|
||||||
|
|
||||||
for a in AuthorizationCode.filter():
|
for a in AuthorizationCode.all():
|
||||||
if a.is_expired():
|
if a.is_expired():
|
||||||
a.delete()
|
a.delete()
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@ bp = Blueprint("groups", __name__, url_prefix="/groups")
|
||||||
@bp.route("/")
|
@bp.route("/")
|
||||||
@permissions_needed("manage_groups")
|
@permissions_needed("manage_groups")
|
||||||
def groups(user):
|
def groups(user):
|
||||||
groups = Group.filter()
|
groups = Group.all()
|
||||||
return render_template("groups.html", groups=groups, menuitem="groups")
|
return render_template("groups.html", groups=groups, menuitem="groups")
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -276,6 +276,10 @@ class LDAPObject:
|
||||||
except (IndexError, ldap.NO_SUCH_OBJECT):
|
except (IndexError, ldap.NO_SUCH_OBJECT):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def all(cls, conn=None):
|
||||||
|
return cls.filter(conn=conn)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def filter(cls, base=None, filter=None, conn=None, **kwargs):
|
def filter(cls, base=None, filter=None, conn=None, **kwargs):
|
||||||
conn = conn or cls.ldap()
|
conn = conn or cls.ldap()
|
||||||
|
|
|
@ -194,7 +194,7 @@ class Group(LDAPObject):
|
||||||
except KeyError:
|
except KeyError:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
groups = cls.filter(conn=conn)
|
groups = cls.all(conn=conn)
|
||||||
Group.ldap_object_attributes(conn=conn)
|
Group.ldap_object_attributes(conn=conn)
|
||||||
return [(group[name_attribute][0], group.dn) for group in groups]
|
return [(group[name_attribute][0], group.dn) for group in groups]
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ bp = Blueprint("authorizations", __name__, url_prefix="/admin/authorization")
|
||||||
@bp.route("/")
|
@bp.route("/")
|
||||||
@permissions_needed("manage_oidc")
|
@permissions_needed("manage_oidc")
|
||||||
def index(user):
|
def index(user):
|
||||||
authorizations = AuthorizationCode.filter()
|
authorizations = AuthorizationCode.all()
|
||||||
return render_template(
|
return render_template(
|
||||||
"oidc/admin/authorization_list.html",
|
"oidc/admin/authorization_list.html",
|
||||||
authorizations=authorizations,
|
authorizations=authorizations,
|
||||||
|
|
|
@ -21,14 +21,14 @@ bp = Blueprint("clients", __name__, url_prefix="/admin/client")
|
||||||
@bp.route("/")
|
@bp.route("/")
|
||||||
@permissions_needed("manage_oidc")
|
@permissions_needed("manage_oidc")
|
||||||
def index(user):
|
def index(user):
|
||||||
clients = Client.filter()
|
clients = Client.all()
|
||||||
return render_template(
|
return render_template(
|
||||||
"oidc/admin/client_list.html", clients=clients, menuitem="admin"
|
"oidc/admin/client_list.html", clients=clients, menuitem="admin"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def client_audiences():
|
def client_audiences():
|
||||||
return [(client.dn, client.name) for client in Client.filter()]
|
return [(client.dn, client.name) for client in Client.all()]
|
||||||
|
|
||||||
|
|
||||||
class ClientAdd(FlaskForm):
|
class ClientAdd(FlaskForm):
|
||||||
|
|
|
@ -13,7 +13,7 @@ bp = Blueprint("tokens", __name__, url_prefix="/admin/token")
|
||||||
@bp.route("/")
|
@bp.route("/")
|
||||||
@permissions_needed("manage_oidc")
|
@permissions_needed("manage_oidc")
|
||||||
def index(user):
|
def index(user):
|
||||||
tokens = Token.filter()
|
tokens = Token.all()
|
||||||
items = (
|
items = (
|
||||||
(token, Client.get(token.client), User.get(dn=token.subject))
|
(token, Client.get(token.client), User.get(dn=token.subject))
|
||||||
for token in tokens
|
for token in tokens
|
||||||
|
|
|
@ -333,7 +333,7 @@ def cleanup_users_and_groups(slapd_connection):
|
||||||
yield
|
yield
|
||||||
User.ldap_object_classes(slapd_connection)
|
User.ldap_object_classes(slapd_connection)
|
||||||
Group.ldap_object_classes(slapd_connection)
|
Group.ldap_object_classes(slapd_connection)
|
||||||
for user in User.filter(conn=slapd_connection):
|
for user in User.all(conn=slapd_connection):
|
||||||
user.delete(conn=slapd_connection)
|
user.delete(conn=slapd_connection)
|
||||||
for group in Group.filter(conn=slapd_connection):
|
for group in Group.all(conn=slapd_connection):
|
||||||
group.delete(conn=slapd_connection)
|
group.delete(conn=slapd_connection)
|
||||||
|
|
|
@ -130,5 +130,5 @@ def consent(slapd_connection, client, user):
|
||||||
@pytest.fixture(autouse=True)
|
@pytest.fixture(autouse=True)
|
||||||
def cleanup_consents(slapd_connection):
|
def cleanup_consents(slapd_connection):
|
||||||
yield
|
yield
|
||||||
for consent in Consent.filter(conn=slapd_connection):
|
for consent in Consent.all(conn=slapd_connection):
|
||||||
consent.delete(conn=slapd_connection)
|
consent.delete(conn=slapd_connection)
|
||||||
|
|
|
@ -331,7 +331,7 @@ def test_code_challenge(testclient, slapd_connection, logged_user, client):
|
||||||
def test_authorization_code_flow_when_consent_already_given(
|
def test_authorization_code_flow_when_consent_already_given(
|
||||||
testclient, slapd_connection, logged_user, client
|
testclient, slapd_connection, logged_user, client
|
||||||
):
|
):
|
||||||
assert not Consent.filter(conn=slapd_connection)
|
assert not Consent.all(conn=slapd_connection)
|
||||||
|
|
||||||
res = testclient.get(
|
res = testclient.get(
|
||||||
"/oauth/authorize",
|
"/oauth/authorize",
|
||||||
|
@ -388,7 +388,7 @@ def test_authorization_code_flow_when_consent_already_given(
|
||||||
def test_authorization_code_flow_when_consent_already_given_but_for_a_smaller_scope(
|
def test_authorization_code_flow_when_consent_already_given_but_for_a_smaller_scope(
|
||||||
testclient, slapd_connection, logged_user, client
|
testclient, slapd_connection, logged_user, client
|
||||||
):
|
):
|
||||||
assert not Consent.filter(conn=slapd_connection)
|
assert not Consent.all(conn=slapd_connection)
|
||||||
|
|
||||||
res = testclient.get(
|
res = testclient.get(
|
||||||
"/oauth/authorize",
|
"/oauth/authorize",
|
||||||
|
|
Loading…
Reference in a new issue