From b1d1f4db825732ba0f571d4758d234ccb79ee08a Mon Sep 17 00:00:00 2001 From: Li Chaoran Date: Sat, 29 Jul 2023 18:00:44 +0800 Subject: [PATCH] frontend: group alias need 1:1 mapping to group When i was developing group supported in OIDC, i found some wired hehavior in group activated in #2825, So i submitted this PR, and @praiskup also give advice a TODO so i include the fix as well This PR try to fix: #2825 1. add unique contraint to fas_name and add migration script generated by alembic revision --autogenerate 2. I think macro fas_group_href canbe replaced by config.GROUP_INFO.link.forma which is more configurable 3. When creating a new alias for a group, if the group already has one alias, popup a flash and redirect to the already existed group Signed-off-by: Li Chaoran --- ...743d_add_unique_constraint_to_fas_group.py | 24 ++++++++++++++++ frontend/coprs_frontend/coprs/models.py | 3 +- .../coprs/templates/_helpers.html | 7 +---- .../coprs/templates/coprs/show/group.html | 2 +- .../templates/groups/user_fas_groups.html | 4 +-- .../coprs/views/groups_ns/groups_general.py | 28 +++++++++++-------- 6 files changed, 46 insertions(+), 22 deletions(-) create mode 100644 frontend/coprs_frontend/alembic/versions/daa62cd0743d_add_unique_constraint_to_fas_group.py diff --git a/frontend/coprs_frontend/alembic/versions/daa62cd0743d_add_unique_constraint_to_fas_group.py b/frontend/coprs_frontend/alembic/versions/daa62cd0743d_add_unique_constraint_to_fas_group.py new file mode 100644 index 000000000..7da6fdae7 --- /dev/null +++ b/frontend/coprs_frontend/alembic/versions/daa62cd0743d_add_unique_constraint_to_fas_group.py @@ -0,0 +1,24 @@ +""" +add unique constraint to fas_group + +Revision ID: daa62cd0743d +Revises: ba6ac0936bfb +Create Date: 2023-08-01 09:52:01.522171 +""" + +from alembic import op + + +# revision identifiers, used by Alembic. +revision = 'daa62cd0743d' +down_revision = 'ba6ac0936bfb' +branch_labels = None +depends_on = None + + +def upgrade(): + op.create_unique_constraint(None, 'group', ['fas_name']) + + +def downgrade(): + op.drop_constraint(None, 'group', type_='unique') diff --git a/frontend/coprs_frontend/coprs/models.py b/frontend/coprs_frontend/coprs/models.py index 038534b47..f33cbede6 100644 --- a/frontend/coprs_frontend/coprs/models.py +++ b/frontend/coprs_frontend/coprs/models.py @@ -2206,8 +2206,7 @@ class Group(db.Model, helpers.Serializer): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(127)) - # TODO: add unique=True - fas_name = db.Column(db.String(127)) + fas_name = db.Column(db.String(127), unique=True) @property def at_name(self): diff --git a/frontend/coprs_frontend/coprs/templates/_helpers.html b/frontend/coprs_frontend/coprs/templates/_helpers.html index 317d82e74..3956dd6f2 100644 --- a/frontend/coprs_frontend/coprs/templates/_helpers.html +++ b/frontend/coprs_frontend/coprs/templates/_helpers.html @@ -304,7 +304,7 @@

{{ g.user.name | capitalize}}

{{ g.user.coprs_count }} My projects - {% if config.FAS_LOGIN or config.LDAP_URL %} + {% if config.FAS_LOGIN or config.LDAP_URL or config.OIDC_LOGIN %} {{ user.user_groups|length }} My groups @@ -458,11 +458,6 @@

News - Read All

{{- copr_url('coprs_ns.copr_package', package.copr, package_name=package.name) -}} {% endmacro %} -{%- macro fas_group_href(name) -%} -https://accounts.fedoraproject.org/group/{{name}} -{%- endmacro -%} - - {% macro repo_file_href(copr, repo, arch=None) %} {%- if not arch %} {{- owner_url('coprs_ns.generate_repo_file', diff --git a/frontend/coprs_frontend/coprs/templates/coprs/show/group.html b/frontend/coprs_frontend/coprs/templates/coprs/show/group.html index e7185d45c..6679298ab 100644 --- a/frontend/coprs_frontend/coprs/templates/coprs/show/group.html +++ b/frontend/coprs_frontend/coprs/templates/coprs/show/group.html @@ -1,7 +1,7 @@ {% extends "coprs/group_show.html" %} {% block title %}Project List{% endblock %} {% block header %}Project List{% endblock %} -{% from "_helpers.html" import render_pagination, fas_group_href %} +{% from "_helpers.html" import render_pagination %} {% block breadcrumbs %}