-
Notifications
You must be signed in to change notification settings - Fork 8
Display definitions #1632
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
Merged
Merged
Display definitions #1632
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
725cdbc
improve claude's time to fix lint
JeSuisUnCaillou ed22fc7
display unused keys in test
JeSuisUnCaillou 4da877f
allow wide component previews
JeSuisUnCaillou 3702c2c
extract UserRoles concern from User model
JeSuisUnCaillou d8388a5
ignore prompt files
JeSuisUnCaillou 2a507f0
display list of all authorization definitions with search
JeSuisUnCaillou 0394f7e
feature flag : display menu only for admins
JeSuisUnCaillou 580e963
move authorization definitions feature flag from policy to controller
jbfeldis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -67,3 +67,5 @@ app/migration/.hubee_config.yml | |
| lib/suivi_dtnum/sources/* | ||
| lib/suivi_dtnum/__pycache__ | ||
| venv/ | ||
|
|
||
| /docs/shaping/* | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| .data-provider-card-img { | ||
| display: flex; | ||
| align-items: center; | ||
| justify-content: center; | ||
| width: 4.2rem; | ||
| padding: .2em; | ||
| } | ||
|
|
||
| .data-provider-card-img img { | ||
| max-width: 4rem; | ||
| max-height: 4rem; | ||
| } | ||
|
|
||
| .definitions-search-count { | ||
| text-align: right; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| .wide-header-logo { | ||
| max-height: 5rem; | ||
| max-width: 10rem; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| class ApplicationComponent < ViewComponent::Base | ||
| include ApplicationHelper | ||
|
|
||
| delegate :policy, to: :helpers | ||
| delegate :policy, :policy_scope, to: :helpers | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,14 @@ | ||
| class InstructorMenuComponent < ApplicationComponent | ||
| def initialize(show_drafts:, show_templates:, show_user_rights:) | ||
| def initialize(show_drafts:, show_templates:, show_user_rights:, show_definitions: false) | ||
| @show_drafts = show_drafts | ||
| @show_templates = show_templates | ||
| @show_user_rights = show_user_rights | ||
| @show_definitions = show_definitions | ||
| end | ||
|
|
||
| def render? | ||
| @show_drafts || @show_templates || @show_user_rights | ||
| @show_drafts || @show_templates || @show_user_rights || @show_definitions | ||
| end | ||
|
|
||
| attr_reader :show_drafts, :show_templates, :show_user_rights | ||
| attr_reader :show_drafts, :show_templates, :show_user_rights, :show_definitions | ||
| end |
31 changes: 31 additions & 0 deletions
31
app/components/molecules/instruction/authorization_definition/card_component.html.erb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| <div class="fr-card fr-enlarge-link"> | ||
| <div class="fr-card__body"> | ||
| <div class="fr-card__content fr-pb-2w"> | ||
| <div class="fr-grid-row fr-grid-row--gutters"> | ||
| <% if provider.logo&.attached? %> | ||
| <div class="data-provider-card-img"> | ||
| <%= image_tag provider.logo, alt: '', class: 'fr-mr-1w' %> | ||
| </div> | ||
| <% end %> | ||
| <div class="fr-col"> | ||
| <h2 class="fr-card__title"> | ||
| <%= link_to name_with_stage, '#' %> | ||
| </h2> | ||
| <p class="fr-card__desc"><%= provider.name %></p> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| <div class="fr-card__footer"> | ||
| <div class="fr-grid-row fr-grid-row--gutters"> | ||
| <div class="fr-col-auto"> | ||
| <span><%= validated_count %></span> | ||
| <span class="fr-badge fr-badge--sm fr-badge--success fr-badge--no-icon"><%= t('authorization_request.status.validated') %></span> | ||
| </div> | ||
| <div class="fr-col-auto"> | ||
| <span><%= submitted_count %></span> | ||
| <span class="fr-badge fr-badge--sm fr-badge--info fr-badge--no-icon"><%= t('authorization_request.status.submitted') %></span> | ||
|
JeSuisUnCaillou marked this conversation as resolved.
|
||
| </div> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </div> | ||
13 changes: 13 additions & 0 deletions
13
app/components/molecules/instruction/authorization_definition/card_component.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| class Molecules::Instruction::AuthorizationDefinition::CardComponent < ApplicationComponent | ||
| def initialize(authorization_definition:, validated_count:, submitted_count:) | ||
| @authorization_definition = authorization_definition | ||
| @validated_count = validated_count | ||
| @submitted_count = submitted_count | ||
| end | ||
|
|
||
| private | ||
|
|
||
| attr_reader :authorization_definition, :validated_count, :submitted_count | ||
|
|
||
| delegate :name_with_stage, :provider, to: :authorization_definition | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| <div class="fr-background-alt--blue-france fr-py-4w fr-mb-4w"> | ||
| <div class="fr-container"> | ||
| <% if back_link %> | ||
| <div class="fr-text--sm fr-mb-2w fr-text-mention--grey"> | ||
| <%= link_to back_link[:text], | ||
| back_link[:path], | ||
| class: 'fr-link fr-icon-arrow-left-line fr-link--icon-left' %> | ||
| </div> | ||
| <% end %> | ||
|
|
||
| <div class="fr-grid-row fr-grid-row--top fr-grid-row--gutters"> | ||
| <div class="fr-col-auto"> | ||
| <% if logo_asset&.attached? %> | ||
| <%= image_tag logo_asset, alt: title, class: 'wide-header-logo' %> | ||
| <% elsif dsfr_logo %> | ||
| <%= dsfr_pictogram(dsfr_logo) %> | ||
| <% end %> | ||
| </div> | ||
| <div class="fr-col"> | ||
| <h1 class="fr-mb-1v"> | ||
| <%= title %> | ||
| </h1> | ||
| <%= subtitle_content %> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| class Molecules::Instruction::WideHeader < ApplicationComponent | ||
| renders_one :subtitle_content | ||
|
|
||
| def initialize(title:, logo_asset: nil, dsfr_logo: nil, back_link: nil) | ||
| @title = title | ||
| @logo_asset = logo_asset | ||
| @dsfr_logo = dsfr_logo | ||
| @back_link = back_link | ||
| end | ||
|
|
||
| private | ||
|
|
||
| attr_reader :title, :logo_asset, :dsfr_logo, :back_link | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
app/controllers/instruction/authorization_definitions_controller.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| class Instruction::AuthorizationDefinitionsController < Instruction::FormManagementController | ||
| def index | ||
| authorize %i[instruction authorization_definition], :index? | ||
| @authorization_definitions = accessible_definitions | ||
| @counts_by_definition = preload_counts(@authorization_definitions) | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def accessible_definitions | ||
| AuthorizationDefinition.all | ||
| .select { |d| current_user.reporter?(d.id) } | ||
| .sort_by(&:name) | ||
| end | ||
|
|
||
| def preload_counts(definitions) | ||
| types = definitions.map { |d| d.authorization_request_class.to_s } | ||
| raw_counts = AuthorizationRequest | ||
| .where(type: types, state: %w[validated submitted]) | ||
| .group(:type, :state) | ||
| .count | ||
|
|
||
| definitions.to_h do |d| | ||
| type = d.authorization_request_class.to_s | ||
| [d.id, { | ||
| validated: raw_counts[[type, 'validated']] || 0, | ||
| submitted: raw_counts[[type, 'submitted']] || 0 | ||
| }] | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| class Instruction::FormManagementController < InstructionController | ||
| private | ||
|
|
||
| def layout_name | ||
| 'wide_container' | ||
|
JeSuisUnCaillou marked this conversation as resolved.
|
||
| end | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import { Controller } from '@hotwired/stimulus' | ||
|
|
||
| export default class extends Controller { | ||
| static targets = ['input', 'item', 'count', 'emptyMessage'] | ||
|
|
||
| filter () { | ||
| const query = this._normalize(this.inputTarget.value) | ||
| let visibleCount = 0 | ||
|
|
||
| this.itemTargets.forEach(item => { | ||
| const match = !query || item.dataset.searchText.includes(query) | ||
| item.classList.toggle('fr-hidden', !match) | ||
| if (match) visibleCount++ | ||
| }) | ||
|
|
||
| this._updateCount(visibleCount) | ||
|
|
||
| if (this.hasEmptyMessageTarget) { | ||
| this.emptyMessageTarget.classList.toggle('fr-hidden', visibleCount > 0) | ||
| } | ||
| } | ||
|
|
||
| _updateCount (count) { | ||
| if (!this.hasCountTarget) return | ||
|
|
||
| const templates = JSON.parse(this.countTarget.dataset.templates) | ||
| const key = count === 0 ? 'zero' : count === 1 ? 'one' : 'other' | ||
| this.countTarget.textContent = templates[key].replace('%{count}', count) | ||
| } | ||
|
|
||
| _normalize (text) { | ||
| return text.normalize('NFD').replace(/[\u0300-\u036f]/g, '').toLowerCase().trim() | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| module UserRoles | ||
| extend ActiveSupport::Concern | ||
|
|
||
| def roles=(value) | ||
| super | ||
| @role_sets = nil | ||
| end | ||
|
|
||
| def roles_for(kind) | ||
| @role_sets ||= {} | ||
| @role_sets[kind] ||= RoleSet.new(roles, kind) | ||
| end | ||
|
|
||
| def instructor?(definition_id = nil) | ||
| roles_for(:instructor).covers?(definition_id) | ||
| end | ||
|
|
||
| def manager?(definition_id = nil) | ||
| roles_for(:manager).covers?(definition_id) | ||
| end | ||
|
|
||
| def reporter?(definition_id = nil) | ||
| return true if admin? | ||
|
|
||
| roles_for(:reporter).covers?(definition_id) | ||
| end | ||
|
|
||
| def fd_reporter?(provider_slug) | ||
| return true if admin? | ||
|
|
||
| roles_for(:reporter).provider_slugs.include?(provider_slug) | ||
| end | ||
|
|
||
| def developer? | ||
| roles_for(:developer).any? | ||
| end | ||
|
|
||
| def definition_ids_for(kind) | ||
| roles_for(kind).definition_ids | ||
| end | ||
|
|
||
| def managed_fd_slugs | ||
| roles.filter_map { |role_string| | ||
| parsed = ParsedRole.parse(role_string) | ||
| parsed.provider_slug if parsed.fd_level? && parsed.role == 'manager' | ||
| }.uniq | ||
| end | ||
|
|
||
| def manages_role?(role_string) | ||
| parsed = ParsedRole.parse(role_string) | ||
| return false if parsed.admin? || parsed.role.nil? | ||
|
|
||
| if parsed.fd_level? | ||
| managed_fd_slugs.include?(parsed.provider_slug) | ||
| else | ||
| definition_ids_for(:manager).include?(parsed.definition_id) | ||
| end | ||
| end | ||
|
|
||
| def managed_by?(other_user) | ||
| roles.any? { |role| other_user.manages_role?(role) } | ||
| end | ||
|
|
||
| def authorization_request_types_for(kind) | ||
| roles_for(kind).authorization_request_types | ||
| end | ||
|
|
||
| def grant_role(kind, definition_id) | ||
| fd = ParsedRole.resolve_provider_slug(definition_id) | ||
| raise ParsedRole::UnknownDefinitionError, "Unknown definition: #{definition_id}" unless fd | ||
|
|
||
| roles << "#{fd}:#{definition_id}:#{kind}" | ||
| roles.uniq! | ||
| @role_sets = nil | ||
| end | ||
|
|
||
| def grant_fd_role(kind, provider_slug) | ||
| roles << "#{provider_slug}:*:#{kind}" | ||
| roles.uniq! | ||
| @role_sets = nil | ||
| end | ||
|
|
||
| def grant_admin_role | ||
| roles << 'admin' | ||
| roles.uniq! | ||
| @role_sets = nil | ||
| end | ||
|
|
||
| def revoke_all_roles | ||
| self.roles = [] | ||
| @role_sets = nil | ||
| end | ||
|
|
||
| def admin? | ||
| roles.include?('admin') || | ||
| bug_bounty_users_within_staging_env? | ||
| end | ||
|
|
||
| def bug_bounty_users_within_staging_env? | ||
| Rails.env.staging? && | ||
| /-ywhadmin@yopmail.com$/.match?(email) | ||
| end | ||
|
|
||
| def authorization_definition_roles_as(kind) | ||
| roles_for(kind).authorization_definitions | ||
| end | ||
| end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pourquoi ne pas utiliser le component
Atoms::ColorBadgeComponentici ?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Par ce que nulle part dans le code on utilise
Atom::ColorBadgeComponentpour les badges des status de demandes, et que c'est pas le scope de cette PR de refacto tout ça.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DsfrComponent::BadgeComponentgère les badge d'état.C'est a appliquer ici.
ex
<%= dsfr_badge(status: :success) { 'Validé' } %>There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nulle part dans le code on utilise
dsfr_badgepour les badges de status de demandes, et c'est pas le scope de cette PR d'introduire ça.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Si tu veux, fait un ticket "utiliser
dsfr_badgepour les badges de status de demandes", et on harmonise tout ça dans un followup. Mais je vais pas faire juste l'effort ici et laisser tout le reste de la codebase faire autrement.