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

Amélioration de l’explication de la permission pour changer un agent de service #4903

Open
wants to merge 5 commits into
base: production
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions app/views/admin/agents/edit.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,21 @@
.card-body.js_agent_role_form
= simple_form_for [:admin, current_organisation, @agent] do |f|
= render "model_errors", model: @agent
- allowed_to_change_services = Agent::TerritoryPolicy.new(current_agent, current_territory).allow_to_manage_access_rights?

= f.association :services, collection: @services, disabled: true, input_html: { class: "select2-input" }, wrapper_html: { class: "mb-0" }, hint: allowed_to_change_services ? nil : "Le changement de service est réservé aux admins de territoire"
- if allowed_to_change_services
span.small.text-muted
| Vous pouvez désormais attribuer plusieurs services à un agent, via votre interface de Configuration - Admin de territoire. 
= link_to "Accéder à la configuration des agents", edit_admin_territory_agent_path(territory_id: current_territory.id, agent_id: @agent.id)
p
- if @agent.services.count == 1
| #{@agent.full_name} appartient à un seul service :
Copy link
Contributor

Choose a reason for hiding this comment

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

c'est un joli détail d'avoir fait ce if 😍 . Tant qu'à faire, pour rendre ce cas un petit peu plus joli on pourrait même inliner le nom du service :

Suggested change
| #{@agent.full_name} appartient à un seul service :
| #{@agent.full_name} appartient au service <b>#{@agent.services.first.name}</b>

- else
| #{@agent.full_name} appartient à #{@agent.services.count} services :
ul.fr-pl-2w
- @agent.services.each do |service|
li.rdv-font-weight-bold= service.name

- if Agent::TerritoryPolicy.new(current_agent, current_territory).allow_to_manage_access_rights?
= link_to "Ajouter ou retirer des services", edit_admin_territory_agent_path(territory_id: current_territory.id, agent_id: @agent.id), class: "fr-link fr-icon-pencil-line fr-link--icon-left"
- else
span.small.text-muted
| En tant qu’agent, vous pouvez désormais être rattaché à plusieurs services d’une même organisation. Pour cela, contacter un agent admin du territoire.
.fr-mb-0.fr-text--sm.text-muted
| Le changement ou l’ajout de service est réservé aux admins de territoire avec ce droit d’accès

hr

Expand Down
69 changes: 39 additions & 30 deletions app/views/admin/territories/agents/edit.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,46 @@ h1
= @agent.full_name_or_email

.container-fluid
- if Agent::TerritoryPolicy.new(current_agent, current_territory).allow_to_manage_access_rights?
.card.m-2.rounded
h2.card-header
= t(".agent_services_legend")
= simple_form_for @agent, url: update_services_admin_territory_agent_path(current_territory, @agent) do |f|
.card-body
= f.input :service_ids, collection: current_territory.services,
label: t(".services"),
label_method: :name,
input_html: { \
multiple: true, \
class: "select2-input",\
}
.card-footer
.row
.col.text-right
= f.submit class: "btn btn-primary", value: "Enregistrer les services"
- can_edit_services = Agent::TerritoryPolicy.new(current_agent, current_territory).allow_to_manage_access_rights?
.card.m-2.rounded
h2.card-header
= t(".agent_services_legend")
= simple_form_for @agent, url: update_services_admin_territory_agent_path(current_territory, @agent) do |f|
Copy link
Contributor

Choose a reason for hiding this comment

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

c'est assez verbeux de mettre le formulaire en entier alors que l'agent ne peut pas s'en servir. Est-ce qu'on pourrait se contenter de mettre le texte d'info qui explique que l'agent n'a pas les permissions suffisances pour gérer les droits d'accès ?

.card-body
= f.input :service_ids, collection: current_territory.services,
label: t(".services"),
label_method: :name,
input_html: { \
multiple: true, \
class: "select2-input",\
},
disabled: !can_edit_services
.card-footer
.row
.col.text-right
- if can_edit_services
= f.submit class: "btn btn-primary", value: "Enregistrer les services", disabled: !can_edit_services
Copy link
Contributor

Choose a reason for hiding this comment

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

je crois que le disabled n'est plus nécessaire ici

- else
.fr-mb-0.fr-text--sm.text-muted
| Vous n’avez pas les droits nécessaires pour modifier les services des agents

- if Agent::AgentTerritorialAccessRightPolicy.new(current_agent, @agent.agent_territorial_access_rights.find_by(territory: current_territory)).edit?
.card.m-2.rounded
h2.card-header
= t(".agent_access_rights_legend")
= simple_form_for @agent.agent_territorial_access_rights.find_by(territory: current_territory), url: admin_territory_agent_territorial_access_right_path do |f|
.card-body
= f.input :allow_to_manage_teams, as: :boolean, hint: t(".hint_allow_to_manage_teams")
= f.input :allow_to_manage_access_rights, as: :boolean, hint: t(".hint_allow_to_manage_access_rights")
= f.input :allow_to_invite_agents, as: :boolean, hint: t(".hint_allow_to_invite_agents")
.card-footer
.row
.col.text-right
= f.submit class: "btn btn-primary", value: "Enregistrer les droits d'accès"
- can_edit_access_rights = Agent::AgentTerritorialAccessRightPolicy.new(current_agent, @agent.agent_territorial_access_rights.find_by(territory: current_territory)).edit?
.card.m-2.rounded
h2.card-header
= t(".agent_access_rights_legend")
= simple_form_for @agent.agent_territorial_access_rights.find_by(territory: current_territory), url: admin_territory_agent_territorial_access_right_path do |f|
.card-body
= f.input :allow_to_manage_teams, as: :boolean, hint: t(".hint_allow_to_manage_teams"), disabled: !can_edit_access_rights
= f.input :allow_to_manage_access_rights, as: :boolean, hint: t(".hint_allow_to_manage_access_rights"), disabled: !can_edit_access_rights
= f.input :allow_to_invite_agents, as: :boolean, hint: t(".hint_allow_to_invite_agents"), disabled: !can_edit_access_rights
.card-footer
.row
.col.text-right
- if can_edit_access_rights
= f.submit class: "btn btn-primary", value: "Enregistrer les droits d'accès", disabled: !can_edit_access_rights
Copy link
Contributor

Choose a reason for hiding this comment

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

idem

- else
.fr-mb-0.fr-text--sm.text-muted
| Vous n’avez pas les droits nécessaires pour modifier les droits d’accès des agents

- if Agent::AgentTerritorialRolePolicy.new(current_agent, AgentTerritorialRole.new(agent: @agent, territory: current_territory)).create_or_destroy?
.card.m-2.rounded.agent-territorial
Expand Down
2 changes: 1 addition & 1 deletion config/locales/models/agent.fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ fr:
display_cancelled_rdv: Affichage des rendez-vous annulés
agent_territorial_access_right:
allow_to_manage_teams: Autorisé à créer, supprimer, modifier des équipes
allow_to_manage_access_rights: Autorisé à gérer les droits d'accès
allow_to_manage_access_rights: Autorisé à gérer les droits d'accès et les services des agents
allow_to_invite_agents: Autorisé à inviter et affecter des agents sur des organisations
agent/rdv_notifications_levels:
all: À chaque modification
Expand Down
2 changes: 1 addition & 1 deletion config/locales/views/admin_territories_agents.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ fr:
submit: Enregistrer
delete_agent_role: Retirer
hint_allow_to_manage_teams: "Créer, supprimer, modifier toutes les équipes du territoires"
hint_allow_to_manage_access_rights: "Modifier les droits d'accès de tous les agents du territoire"
hint_allow_to_manage_access_rights: "Modifier les droits d'accès et les services de tous les agents du territoire"
hint_allow_to_invite_agents: "Inviter d'autre personne sur le territoire, les affecter ou retirer de chacune des organisations du territoire"
Loading