Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

group alias need 1:1 mapping to group #2826

Closed
wants to merge 1 commit into from

Conversation

pkking
Copy link
Contributor

@pkking pkking commented Jul 29, 2023

This PR try to fix: #2825 also fortunately fix: #2563

  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 onfig.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

fas_group, group.name)
else:
message = "Group {} is activated in the System under the alias {} ".format(
fas_group, alias)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:-) how do you trigger this one actually? Is there a reproducer?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:-) how do you trigger this one actually? Is there a reproducer?

Yeah, i just go /groups/activate/<group_name> twice with two different alias
The second submit will lead to a 404 page

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AAAh, this. Yeah, I totally misunderstood the thing you want to fix (I though you want to map 2 external groups to a single Copr group, and it is vice versa).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please return "400 Bad Request" if user visits /groups/activate/<existing_group> for the second time? There's no such link, so that must be an error anyway (processing the request seems just redundant).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will simplely return 400 be a good experience?
Or just redirect user to the existed group?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure. Do you think users can get to the route once it is activated? If yes, redirecting is indeed a better option.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure. Do you think users can get to the route once it is activated? If yes, redirecting is indeed a better option.

Seems no possible unless they know the route and play with it like me :)
But return 400 or redirect will not waste anything, so why not?

@@ -37,7 +37,7 @@ <h1>
<tbody>
{% for team in teams %}
<tr>
<td><a href="{{ fas_group_href(team) }}">
<td><a href="{{ config.GROUP_INFO.link.format(name=team) }}">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this #2563?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this #2563?

Don‘t know this ticket before :) but in our case, we should be redirect to openEuler group info page instead of fas_group stuff, so i think fas_group_href can be replaced with GROUP_INFO.link 😄

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think that's exactly #2563 (forgotten hard-coded link). Can you use Fixes: #2563, too?

@praiskup
Copy link
Member

Nit that I can fix myself for the PR - but would be helpful to write commit messages like:

<component>: <what you are doing>

_Why_ (rather how, it's the commit itself) are doing that. This should be readable and
describe the background story.

<tag>: value (e.g. Fixes: #XYZ)
<tag>: value

@pkking
Copy link
Contributor Author

pkking commented Jul 31, 2023

Nit that I can fix myself for the PR - but would be helpful to write commit messages like:

<component>: <what you are doing>

_Why_ (rather how, it's the commit itself) are doing that. This should be readable and
describe the background story.

<tag>: value (e.g. Fixes: #XYZ)
<tag>: value

I tried to describe it in the newly pushed commit message, any advice appreciated 😃

@pkking pkking requested a review from praiskup July 31, 2023 14:48
@praiskup
Copy link
Member

praiskup commented Aug 1, 2023

alembic revision --autogenerate

This was a correct action (adding the index via migration); can you add the migration script into this PR?

@pkking
Copy link
Contributor Author

pkking commented Aug 1, 2023

alembic revision --autogenerate

This was a correct action (adding the index via migration); can you add the migration script into this PR?

Ah i forget to push this file 🐷, Done

# can't have more than one alias for a group
if group.name != alias:
message = "Group {} already activated as alias {} ".format(
fas_group, group.name)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we go with error 400 or redirect, this if/else condition is redundant. While on this, would you mind making the flash message "green" with flash("message", "success") :-) so it is more visible? The grey color doesn't look like something actually happened...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

return flask.redirect(url_for(
"groups_ns.list_projects_by_group", group_name=alias))
"groups_ns.list_projects_by_group", group_name=group.name))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is certainly OK and better behavior than before, thank you!

What I thought meant before was that we should redirect the user (or error 400) much earlier, before the user starts even thinking about how to name the group (it is wasting of time, the group is already activated so nothing will happen). Something like:

def activate_group(fas_group):
    if "fas group is activated":
        return flask.redirect(...)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's sounds a good idea, will tweak the code :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is certainly OK and better behavior than before, thank you!

What I thought meant before was that we should redirect the user (or error 400) much earlier, before the user starts even thinking about how to name the group (it is wasting of time, the group is already activated so nothing will happen). Something like:

def activate_group(fas_group):
    if "fas group is activated":
        return flask.redirect(...)

Done

@praiskup
Copy link
Member

praiskup commented Aug 2, 2023

+1 (note the missing thing above, but still good enough)

@pkking pkking force-pushed the fix_group_constraint branch 3 times, most recently from b1d1f4d to 931e2a9 Compare August 2, 2023 07:54
db.session.add(group)
group = UsersLogic.create_group_by_fas_name(fas_group, alias)
# db.session.add(group) is done by UsersLogic.create_group_by_fas_name()
db.session.flush()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I bet flush() is not needed. I'd drop the commented-out line with db.session.add() (NB adding the same object twice shouldn't hurt).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, commit() will unconditionally call flush() before commit

Copy link
Contributor Author

@pkking pkking Aug 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I bet flush() is not needed. I'd drop the commented-out line with db.session.add() (NB adding the same object twice shouldn't hurt).

But why should we still keep add() since it was done by create_group_by_fas_name

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, add() is redundant, I have no objections to removing it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, add() is redundant, I have no objections to removing it.

I totally misunderstand you :)
Done

When i was developing group supported in OIDC, i found some wired hehavior in group activated in fedora-copr#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: fedora-copr#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 <[email protected]>
Copy link
Member

@praiskup praiskup left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you

@praiskup
Copy link
Member

praiskup commented Aug 3, 2023

NOTE: Needs manual merge.

@praiskup
Copy link
Member

praiskup commented Aug 4, 2023

Merged as: bddee02

Thank you.

@praiskup praiskup closed this Aug 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants