Files
grecia/app/models/abilities/administrator.rb
Javi Martín 38b38d1fcc Rename Poll::Question::Answer to Poll::Question::Option
Having a class named `Poll::Question::Answer` and another class named
`Poll::Answer` was so confusing that no developer working on the project
has ever been capable of remembering which is which for more than a few
seconds.

Furthermore, we're planning to add open answers to polls, and we might
add a reference from the `poll_answers` table to the
`poll_question_answers` table to property differentiate between open
answers and closed answers. Having yet another thing named answer would
be more than what our brains can handle (we know it because we did this
once in a prototype).

So we're renaming `Poll::Question::Answer` to `Poll::Question::Option`.
Hopefully that'll make it easier to remember. The name is also (more or
less) consistent with the `Legislation::QuestionOption` class, which is
similar.

We aren't changing the table or columns names for now in order to avoid
possible issues when upgrading (old code running with the new database
tables/columns after running the migrations but before deployment has
finished, for instance). We might do it in the future.

I've tried not to change the internationalization keys either so
existing translations would still be valid. However, since we have to
change the keys in `activerecord.yml` so methods like
`human_attribute_name` keep working, I'm also changing them in places
where similar keys were used (like `poll_question_answer` or
`poll/question/answer`).

Note that it isn't clear whether we should use `option` or
`question_option` in some cases. In order to keep things simple, we're
using `option` where we were using `answer` and `question_option` where
we were using `question_answer`.

Also note we're adding tests for the admin menu component, since at
first I forgot to change the `answers` reference there and all tests
passed.
2024-06-13 19:13:01 +02:00

148 lines
5.3 KiB
Ruby

module Abilities
class Administrator
include CanCan::Ability
def initialize(user)
merge Abilities::Moderation.new(user)
merge Abilities::SDG::Manager.new(user)
can :restore, Comment
cannot :restore, Comment, hidden_at: nil
can :restore, Debate
cannot :restore, Debate, hidden_at: nil
can :restore, Proposal
cannot :restore, Proposal, hidden_at: nil
can :create, Legislation::Proposal
can :show, Legislation::Proposal
can :proposals, ::Legislation::Process
can :restore, Legislation::Proposal
cannot :restore, Legislation::Proposal, hidden_at: nil
can :restore, Budget::Investment
cannot :restore, Budget::Investment, hidden_at: nil
can :restore, User
cannot :restore, User, hidden_at: nil
can :confirm_hide, Comment
cannot :confirm_hide, Comment, hidden_at: nil
can :confirm_hide, Debate
cannot :confirm_hide, Debate, hidden_at: nil
can :confirm_hide, Proposal
cannot :confirm_hide, Proposal, hidden_at: nil
can :confirm_hide, Legislation::Proposal
cannot :confirm_hide, Legislation::Proposal, hidden_at: nil
can :confirm_hide, Budget::Investment
cannot :confirm_hide, Budget::Investment, hidden_at: nil
can :confirm_hide, User
cannot :confirm_hide, User, hidden_at: nil
can :mark_featured, Debate
can :unmark_featured, Debate
can :comment_as_administrator, [Debate, Comment, Proposal, Poll, Poll::Question,
Budget::Investment, Legislation::Question,
Legislation::Proposal, Legislation::Annotation, Topic]
can [:search, :create, :index, :destroy, :update], ::Administrator
can [:search, :create, :index, :destroy], ::Moderator
can [:search, :show, :update, :create, :index, :destroy, :summary], ::Valuator
can [:search, :create, :index, :destroy], ::Manager
can [:create, :read, :destroy], ::SDG::Manager
can [:search, :index], ::User
can :manage, Dashboard::Action
can [:index, :read, :create, :update, :destroy], Budget
can :publish, Budget, id: Budget.drafting.ids
can :calculate_winners, Budget, &:reviewing_ballots?
can :read_results, Budget do |budget|
budget.balloting_finished? && budget.has_winning_investments?
end
can [:read, :create, :update, :destroy], Budget::Group
can [:read, :create, :update, :destroy], Budget::Heading
can [:hide, :admin_update, :toggle_selection], Budget::Investment
can [:valuate, :comment_valuation], Budget::Investment
cannot [:admin_update, :toggle_selection, :valuate, :comment_valuation],
Budget::Investment, budget: { phase: "finished" }
can :create, Budget::ValuatorAssignment
can :read_admin_stats, Budget, &:balloting_or_later?
can [:search, :update, :create, :index, :destroy], Banner
can [:index, :create, :update, :destroy], Geozone
can [:read, :create, :update, :destroy, :booth_assignments], Poll
can [:read, :create, :update, :destroy, :available], Poll::Booth
can [:search, :create, :index, :destroy], ::Poll::Officer
can [:create, :destroy, :manage], ::Poll::BoothAssignment
can [:create, :destroy], ::Poll::OfficerAssignment
can :read, Poll::Question
can [:create], Poll::Question do |question|
question.poll.blank? || !question.poll.started?
end
can [:update, :destroy], Poll::Question do |question|
!question.poll.started?
end
can [:read, :order_options], Poll::Question::Option
can [:create, :update, :destroy], Poll::Question::Option do |option|
can?(:update, option.question)
end
can :read, Poll::Question::Option::Video
can [:create, :update, :destroy], Poll::Question::Option::Video do |video|
can?(:update, video.option)
end
can [:destroy], Image do |image|
image.imageable_type == "Poll::Question::Option" && can?(:update, image.imageable)
end
can :manage, SiteCustomization::Page
can :manage, SiteCustomization::Image
can :manage, SiteCustomization::ContentBlock
can :manage, Widget::Card
can :access, :ckeditor
can :manage, Ckeditor::Picture
can [:read, :debate, :draft_publication, :allegations, :result_publication,
:milestones], Legislation::Process
can [:create, :update, :destroy], Legislation::Process
can [:manage], ::Legislation::DraftVersion
can [:manage], ::Legislation::Question
can [:manage], ::Legislation::Proposal
cannot :comment_as_moderator,
[::Legislation::Question, Legislation::Annotation, ::Legislation::Proposal]
can [:create], Document
can [:destroy], Document do |document|
document.documentable_type == "Poll::Question::Option" && can?(:update, document.documentable)
end
can [:create, :destroy], DirectUpload
can [:deliver], Newsletter, hidden_at: nil
can [:manage], Dashboard::AdministratorTask
can :manage, Setting::LocalesSettings
can :manage, LocalCensusRecord
can [:create, :read], LocalCensusRecords::Import
if Rails.application.config.multitenancy && Tenant.default?
can [:create, :read, :update, :hide, :restore], Tenant
end
end
end
end