diff --git a/app/models/ability/admin.rb b/app/models/ability/admin.rb index 8cf3f3d3664ec304942b6d598c71de6d811febb1..428058e2d9533723de98ec2a905bca455311cf75 100644 --- a/app/models/ability/admin.rb +++ b/app/models/ability/admin.rb @@ -55,12 +55,12 @@ class Ability::Admin < Ability # Est-ce bien raisonnable de laisser supprimer un site ? # Le risque de faussse manip est grand. cannot :destroy, Communication::Website, university_id: @user.university_id + can :manage, Communication::Website::Agenda::Event, university_id: @user.university_id can :manage, Communication::Website::Category, university_id: @user.university_id can :manage, Communication::Website::Menu, university_id: @user.university_id can :manage, Communication::Website::Menu::Item, university_id: @user.university_id can :manage, Communication::Website::Page, university_id: @user.university_id can :manage, Communication::Website::Post, university_id: @user.university_id - can :manage, Communication::Website::Agenda::Event, university_id: @user.university_id end def admin_communication_extranet diff --git a/app/models/ability/author.rb b/app/models/ability/author.rb new file mode 100644 index 0000000000000000000000000000000000000000..29897a43c6ea26744f51c680c0679a1d3e3f2d66 --- /dev/null +++ b/app/models/ability/author.rb @@ -0,0 +1,26 @@ +class Ability::Author < Ability + + def initialize(user) + super + can :manage, Communication::Block, university_id: @user.university_id, about_type: 'Communication::Website::Agenda::Event', about_id: managed_events_ids + can :manage, Communication::Block, university_id: @user.university_id, about_type: 'Communication::Website::Post', about_id: managed_posts_ids + can :create, Communication::Block + can :manage, Communication::Block::Heading, university_id: @user.university_id, about_type: 'Communication::Website::Agenda::Event', about_id: managed_events_ids + can :manage, Communication::Block::Heading, university_id: @user.university_id, about_type: 'Communication::Website::Post', about_id: managed_posts_ids + can :create, Communication::Block::Heading + can :read, Communication::Website, university_id: @user.university_id, id: managed_websites_ids + can :manage, Communication::Website::Agenda::Event, university_id: @user.university_id, communication_website_id: managed_websites_ids + can :manage, Communication::Website::Post, university_id: @user.university_id, communication_website_id: managed_websites_ids, author_id: @user.person&.id + end + + protected + + def managed_posts_ids + @managed_posts_ids ||= Communication::Website::Post.where(university_id: @user.university_id, author_id: @user.person&.id).pluck(:id) + end + + def managed_events_ids + @managed_events_ids ||= Communication::Website::Agenda::Event.where(university_id: @user.university_id).pluck(:id) + end + +end \ No newline at end of file diff --git a/app/models/ability/contributor.rb b/app/models/ability/contributor.rb index 39fc8973e4e753cddab3f620976c7ce7ab18e9dc..6af36f49645d2040a1bd979b4704e29d6fcfc353 100644 --- a/app/models/ability/contributor.rb +++ b/app/models/ability/contributor.rb @@ -1,15 +1,9 @@ -class Ability::Contributor < Ability +class Ability::Contributor < Ability::Author def initialize(user) super - can :manage, Communication::Block, university_id: @user.university_id, about_type: 'Communication::Website::Post', about_id: Communication::Website::Post.where(university_id: @user.university_id, author_id: @user.person&.id).pluck(:id) - can :manage, Communication::Block, university_id: @user.university_id, about_type: 'Communication::Website::Agenda::Event' - can :create, Communication::Block - can :manage, Communication::Block::Heading, university_id: @user.university_id, about_type: 'Communication::Website::Post', about_id: Communication::Website::Post.where(university_id: @user.university_id, author_id: @user.person&.id).pluck(:id) - can :manage, Communication::Block::Heading, university_id: @user.university_id, about_type: 'Communication::Website::Agenda::Event' - can :create, Communication::Block::Heading - can :read, Communication::Website, university_id: @user.university_id, id: managed_websites_ids - can :manage, Communication::Website::Post, university_id: @user.university_id, communication_website_id: managed_websites_ids, author_id: @user.person&.id + cannot :publish, Communication::Website::Agenda::Event cannot :publish, Communication::Website::Post end + end \ No newline at end of file diff --git a/app/models/ability/program_manager.rb b/app/models/ability/program_manager.rb index 870d882a8859ddb665414ef176cd8c68ca7393ec..73f4827c58108b5b30050522a5ba348d713633f1 100644 --- a/app/models/ability/program_manager.rb +++ b/app/models/ability/program_manager.rb @@ -2,19 +2,19 @@ class Ability::ProgramManager < Ability def initialize(user) super - can :manage, Communication::Block, university_id: @user.university_id, about_type: 'Communication::Website::Post', about_id: Communication::Website::Post.where(university_id: @user.university_id).pluck(:id) - can :manage, Communication::Block, university_id: @user.university_id, about_type: 'Communication::Website::Agenda::Event' + can :manage, Communication::Block, university_id: @user.university_id, about_type: 'Communication::Website::Agenda::Event', about_id: managed_events_ids + can :manage, Communication::Block, university_id: @user.university_id, about_type: 'Communication::Website::Post', about_id: managed_posts_ids can :manage, Communication::Block, university_id: @user.university_id, about_type: 'University::Person', about_id: University::Person.where(university_id: @user.university_id).pluck(:id) can :manage, Communication::Block, university_id: @user.university_id, about_type: 'Education::Program', about_id: managed_programs_ids can :create, Communication::Block - can :manage, Communication::Block::Heading, university_id: @user.university_id, about_type: 'Communication::Website::Post', about_id: Communication::Website::Post.where(university_id: @user.university_id).pluck(:id) - can :manage, Communication::Block::Heading, university_id: @user.university_id, about_type: 'Communication::Website::Agenda::Event' + can :manage, Communication::Block::Heading, university_id: @user.university_id, about_type: 'Communication::Website::Agenda::Event', about_id: managed_events_ids + can :manage, Communication::Block::Heading, university_id: @user.university_id, about_type: 'Communication::Website::Post', about_id: managed_posts_ids can :manage, Communication::Block::Heading, university_id: @user.university_id, about_type: 'Education::Program', about_id: managed_programs_ids can :manage, Communication::Block::Heading, university_id: @user.university_id, about_type: 'University::Person', about_id: University::Person.where(university_id: @user.university_id).pluck(:id) can :create, Communication::Block::Heading can :read, Communication::Website, university_id: @user.university_id - can :manage, Communication::Website::Post, university_id: @user.university_id can :manage, Communication::Website::Agenda::Event, university_id: @user.university_id + can :manage, Communication::Website::Post, university_id: @user.university_id can :manage, Education::Program, id: managed_programs_ids can [:read, :children], Education::Program, university_id: @user.university_id cannot :create, Education::Program @@ -28,4 +28,13 @@ class Ability::ProgramManager < Ability def managed_programs_ids @managed_programs_ids ||= @user.programs_to_manage.pluck(:education_program_id) end + + def managed_posts_ids + @managed_posts_ids ||= Communication::Website::Post.where(university_id: @user.university_id).pluck(:id) + end + + def managed_events_ids + @managed_events_ids ||= Communication::Website::Agenda::Event.where(university_id: @user.university_id).pluck(:id) + end + end \ No newline at end of file diff --git a/app/models/ability/website_manager.rb b/app/models/ability/website_manager.rb index 593b9fdca0988c9389b947d3d406da6c18a3119c..cfda573a6c836a1b9cb63a570b3c4b6c38dfd616 100644 --- a/app/models/ability/website_manager.rb +++ b/app/models/ability/website_manager.rb @@ -2,19 +2,20 @@ class Ability::WebsiteManager < Ability def initialize(user) super + can :manage, Communication::Block, university_id: @user.university_id, about_type: 'Communication::Website::Agenda::Event', about_id: managed_events_ids can :manage, Communication::Block, university_id: @user.university_id, about_type: 'Communication::Website::Page', about_id: managed_pages_ids can :manage, Communication::Block, university_id: @user.university_id, about_type: 'Communication::Website::Post', about_id: managed_posts_ids - can :manage, Communication::Block, university_id: @user.university_id, about_type: 'Communication::Website::Agenda::Event', about_id: managed_events_ids can :manage, Communication::Block, university_id: @user.university_id, about_type: 'University::Organization', about_id: University::Organization.where(university_id: @user.university_id).pluck(:id) can :manage, Communication::Block, university_id: @user.university_id, about_type: 'University::Person', about_id: University::Person.where(university_id: @user.university_id).pluck(:id) can :create, Communication::Block + can :manage, Communication::Block::Heading, university_id: @user.university_id, about_type: 'Communication::Website::Agenda::Event', about_id: managed_events_ids can :manage, Communication::Block::Heading, university_id: @user.university_id, about_type: 'Communication::Website::Page', about_id: managed_pages_ids can :manage, Communication::Block::Heading, university_id: @user.university_id, about_type: 'Communication::Website::Post', about_id: managed_posts_ids - can :manage, Communication::Block::Heading, university_id: @user.university_id, about_type: 'Communication::Website::Agenda::Event', about_id: managed_events_ids can :manage, Communication::Block::Heading, university_id: @user.university_id, about_type: 'University::Organization', about_id: University::Organization.where(university_id: @user.university_id).pluck(:id) can :manage, Communication::Block::Heading, university_id: @user.university_id, about_type: 'University::Person', about_id: University::Person.where(university_id: @user.university_id).pluck(:id) can :create, Communication::Block::Heading can [:read, :analytics], Communication::Website, university_id: @user.university_id, id: managed_websites_ids + can :manage, Communication::Website::Agenda::Event, university_id: @user.university_id, communication_website_id: managed_websites_ids can :manage, Communication::Website::Category, university_id: @user.university_id, communication_website_id: managed_websites_ids can [:read, :update, :reorder], Communication::Website::Menu, university_id: @user.university_id, communication_website_id: managed_websites_ids can :manage, Communication::Website::Menu::Item, university_id: @user.university_id, website_id: managed_websites_ids