Skip to content

Commit

Permalink
add draft status for scope disabling check + exclude current authoriz…
Browse files Browse the repository at this point in the history
…ation request from the check
  • Loading branch information
mehdi-farsi committed May 15, 2024
1 parent 6d2f895 commit 373485c
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 5 deletions.
6 changes: 4 additions & 2 deletions app/helpers/authorization_requests_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,10 @@ def authorization_request_can_be_updated?(authorization_request)
authorization_request.filling?
end

def hubee_dila_selected_scopes_for_current_organization
authorization_requests = AuthorizationRequest.where(type: 'AuthorizationRequest::HubEEDila', organization: current_organization.id, state: %w[validated submitted changes_requested],)
def hubee_dila_selected_scopes_for_current_organization(authorization_request = nil)
authorization_requests = AuthorizationRequest.where(type: 'AuthorizationRequest::HubEEDila', organization: current_organization.id, state: %w[draft validated submitted changes_requested])

authorization_requests = authorization_requests.where.not(id: authorization_request.id) if authorization_request.present?

authorization_requests.map(&:scopes).flatten.uniq.join(', ')
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/authorization_request/hubee_dila.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def unique_scope_request
.where(
organization:,
type: 'AuthorizationRequest::HubEEDila',
state: %w[validated submitted changes_requested]
state: %w[draft validated submitted changes_requested]
)

existing_scopes = existing_requests.map(&:scopes).flatten.uniq
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def hubee_scope_uniqueness_constraint?
end

def requested_scopes?
existing_requests = current_organization&.active_authorization_requests&.where(type: authorization_request_class, state: %w[validated submitted changes_requested])
existing_requests = current_organization&.active_authorization_requests&.where(type: authorization_request_class, state: %w[draft validated submitted changes_requested])

return false unless existing_requests.any?

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

<div class="scopes-group__grid">
<% scopes.each do |scope| %>
<% if hubee_dila_selected_scopes_for_current_organization.include? scope.value %>
<% if hubee_dila_selected_scopes_for_current_organization(@authorization_request).include? scope.value %>
<%= f.dsfr_scope(scope, disabled: true) %>
<% else %>
<%= f.dsfr_scope scope %>
Expand Down

0 comments on commit 373485c

Please sign in to comment.