Files
nairobi/config/routes/sdg_management.rb
Javi Martín 7aee4f6241 Add SDG phases cards management
These cards will be displayed in the SDG homepage.

Note there seems to be a strange behavior in cancancan. If we define
these rules:

can :manage, Widget::Card, page_type: "SDG::Phase"
can :manage, Widget::Card

The expected behavior is the first rule will always be ignored because
the second one overwrites it. However, when creating a new card with
`load_and_authorize_resource` will automatically add `page_type:
"SDG::Phase"`.

Similarly, if we do something like:

can :manage, Widget::Card, id: 3
can :manage, Widget::Card

Then the new card will have `3` as an ID.

Maybe upgrading cancancan solves the issue; we haven't tried it. For now
we're defining a different rule when creating widget cards.
2021-01-14 17:40:02 +01:00

29 lines
1023 B
Ruby

namespace :sdg_management do
root to: "goals#index"
resources :goals, only: [:index]
resources :targets, only: [:index]
resources :local_targets, except: [:show]
resource :homepage, controller: :homepage, only: [:show]
resources :phases, only: [], as: :sdg_phases do
resources :cards, except: [:index, :show], as: :widget_cards
end
types = SDG::Related::RELATABLE_TYPES.map(&:tableize)
types_constraint = /#{types.join("|")}/
get "*relatable_type", to: "relations#index", as: "relations", relatable_type: types_constraint
get "*relatable_type/:id/edit", to: "relations#edit", as: "edit_relation", relatable_type: types_constraint
patch "*relatable_type/:id", to: "relations#update", as: "relation", relatable_type: types_constraint
types.each do |type|
get type, to: "relations#index", as: type
get "#{type}/:id/edit", to: "relations#edit", as: "edit_#{type.singularize}"
end
end
resolve "SDG::LocalTarget" do |target, options|
[:local_target, options.merge(id: target)]
end