-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #141 from CodeandoMexico/hotfix/proposals
corrección de implementación
- Loading branch information
Showing
6 changed files
with
57 additions
and
51 deletions.
There are no files selected for viewing
This file contains 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 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,46 +1,50 @@ | ||
module Decidim | ||
class GeographicScopeMatcher < Rectify::Command | ||
# This extension helps associate user's district or sector to their participation in a component. If the component has a scope, and the scope is permissions' associated, this extension will find the corresponding user's scope, and match it to the component's needs. | ||
|
||
GEO_SCOPES = { | ||
"DISTRITOS" => "district_code", | ||
"SECTORES" => "sector_code" | ||
} | ||
|
||
def initialize(item, current_user) | ||
@item = item | ||
@component = item.component | ||
@current_user = current_user | ||
end | ||
module Extensions | ||
module Decidim | ||
class GeographicScopeMatcher < Rectify::Command | ||
# This extension helps associate user's district or sector to their participation in a component. If the component has a scope, and the scope is permissions' associated, this extension will find the corresponding user's scope, and match it to the component's needs. | ||
|
||
def call | ||
return broadcast(:nil) if @component.scope.nil? | ||
GEO_SCOPES = { | ||
"DISTRITOS" => "district_code", | ||
"SECTORES" => "sector_code" | ||
} | ||
|
||
component_scope_type = scope_type_checker | ||
return broadcast(:nil) if component_scope_type.nil? | ||
def initialize(item, current_user) | ||
@item = item | ||
@component = item.component | ||
@current_user = current_user | ||
end | ||
|
||
authorizations = user_authorization_checker | ||
return broadcast(:nil) if authorizations.nil? | ||
def call | ||
return broadcast(:nil) if @component.scope.nil? | ||
|
||
matcher = component_scope_matcher(component_scope_type, authorizations) | ||
component_scope_type = scope_type_checker | ||
return broadcast(:nil) if component_scope_type.nil? | ||
|
||
broadcast(:ok, matcher) | ||
end | ||
authorizations = user_authorization_checker | ||
return broadcast(:nil) if authorizations.nil? | ||
|
||
private | ||
matcher = item_scope_matcher(component_scope_type, authorizations) | ||
|
||
def scope_type_checker | ||
GEO_SCOPES[@component.scope.code] | ||
end | ||
broadcast(:ok, matcher) | ||
end | ||
|
||
def user_authorization_checker | ||
authorizations = Decidim::Authorization.where.not(granted_at: nil).where(user: @current_user, name: ["ine", "managed_user_authorization_handler"]) | ||
private | ||
|
||
authorizations.nil? || authorizations | ||
end | ||
attr_reader :current_user, :item | ||
|
||
def scope_type_checker | ||
GEO_SCOPES[@component.scope.code] | ||
end | ||
|
||
def user_authorization_checker | ||
authorizations = ::Decidim::Authorization.where.not(granted_at: nil).where(user: @current_user, name: ["ine", "managed_user_authorization_handler"]) | ||
|
||
authorizations.nil? || authorizations | ||
end | ||
|
||
def item_scope_matcher(scope_type, authorization) | ||
Decidim::Scope.find_by! code: authorizations.last.metadata[scope_type] | ||
def item_scope_matcher(scope_type, authorizations) | ||
::Decidim::Scope.find_by! code: authorizations.last.metadata[scope_type] | ||
end | ||
end | ||
end | ||
end |
This file contains 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 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 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 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