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

Allow only enterprise managers to connect apps #12507

Merged

Conversation

mkllnk
Copy link
Member

@mkllnk mkllnk commented May 23, 2024

What? Why?

Connecting apps only works for enterprise managers because non-managers, like super admins, are not authorised to access enterprise data via the DFC API.

What should we test?

  • Edit an enterprise and go to the connected apps panel (feature toggle on).
  • As manager, you see the normal connect button.
  • As non-manager (super admin) the button is disabled and a not displays. You can't click that button.

Release notes

Changelog Category (reviewers may add a label for the release notes):

  • User facing changes
  • API changes (V0, V1, DFC or Webhook)
  • Technical changes only
  • Feature toggled

The title of the pull request will be included in the release notes.

Dependencies

Documentation updates

Otherwise it doesn't work because non-managers, like super admins, are
not authorised to access enterprise data via the DFC API.
@mkllnk mkllnk self-assigned this May 23, 2024
@mkllnk mkllnk added the feature toggled These pull requests' changes are invisible by default and are grouped in release notes label May 23, 2024
@mkllnk mkllnk marked this pull request as ready for review May 23, 2024 04:05
Copy link
Member

@dacook dacook left a comment

Choose a reason for hiding this comment

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

Great, nice simple update. I have a suggestion to make the message more verbose though.

@@ -1357,6 +1357,7 @@ en:
enable: "Allow data sharing"
disable: "Stop sharing"
loading: "Loading"
need_to_be_manager: "Only managers can connect apps."
Copy link
Member

Choose a reason for hiding this comment

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

Would this be a more helpful explanation? Helps work out how to solve the problem.

Suggested change
need_to_be_manager: "Only managers can connect apps."
need_to_be_manager: "You cannot connect an app because you are not a manager of this enterprise."

Copy link
Member Author

Choose a reason for hiding this comment

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

That would probably be more helpful. I kept it short because it fits better in that space. It's only seen by super-admins and therefore I wouldn't put too much effort into the message.

@@ -14,6 +14,10 @@ def select_only_item(producers)
producers.size == 1 ? producers.first.id : nil
end

def can_connect_apps?(enterprise)
Copy link
Member

Choose a reason for hiding this comment

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

What do you think about naming this for the condition? It's what the message talks about. Forgive me if I'm overthinking it now..

    def managed_by_user?(enterprise)

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, that sounds good. It is clearer for now because you know what the method is doing. If the condition changes in the future then we may need a different name again. Anyway, I think either is good but I applied your recommendation.

Copy link
Collaborator

@rioug rioug left a comment

Choose a reason for hiding this comment

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

Looks good !

@filipefurtad0 filipefurtad0 self-assigned this May 31, 2024
@filipefurtad0 filipefurtad0 added pr-staged-au staging.openfoodnetwork.org.au pr-staged-fr staging.coopcircuits.fr and removed pr-staged-au staging.openfoodnetwork.org.au labels May 31, 2024
@filipefurtad0
Copy link
Contributor

filipefurtad0 commented May 31, 2024

Hey @mkllnk ,

I've verified that after staging and logging in as superadmin the connect button is disabled 🟢

image

It remains enabled for both enterprise owners 🟢

image

And managers 🟢

image

(the orange line is meant to indicate, that for this enterprise, button remains with the endless spinner, but this is not introduced by this PR. The button is correctly displayed for other enterprises, and works as expected).

I've noticed though, that the user is sent to the login screen, when clicking the Disconnect app button. There seems to be some inconsistent behavior, on this regard. I'll need to investigate master, to be sure this is not introduced by this PR.

Merging!

@filipefurtad0 filipefurtad0 removed the pr-staged-fr staging.coopcircuits.fr label May 31, 2024
@filipefurtad0
Copy link
Contributor

Ok, I've retested clicking the Stop sharing button. This seems to be present on release v4.4.48 (c81e7f3, i.e., before merging #12535). That means, this is not a regression introduced here.

I think the way forward is to open an issue and merge this PR.

@filipefurtad0 filipefurtad0 merged commit 706da37 into openfoodfoundation:master Jun 1, 2024
54 checks passed
@mkllnk mkllnk deleted the connected-apps-super-admin branch June 28, 2024 05:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature toggled These pull requests' changes are invisible by default and are grouped in release notes
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants