From e19dd96ed1b23090f8b942026757510807e6b23d Mon Sep 17 00:00:00 2001 From: Clarissa <cdp13@inf.ufpr.br> Date: Thu, 11 May 2017 11:43:48 -0300 Subject: [PATCH] #204: creating moderator role and adding to user --- app/models/role.rb | 4 ++++ app/models/user.rb | 11 +++++++++++ db/seeds.rb | 1 + lib/portalmec/sociable_tests.rb | 2 ++ 4 files changed, 18 insertions(+) diff --git a/app/models/role.rb b/app/models/role.rb index 9a9797ce..cfca39da 100644 --- a/app/models/role.rb +++ b/app/models/role.rb @@ -29,4 +29,8 @@ class Role < ApplicationRecord def self.curator find_by(name: 'curator') || create!(name: 'curator') end + + def self.moderator + find_by(name: 'moderator') || create!(name: 'moderator') + end end diff --git a/app/models/user.rb b/app/models/user.rb index a68598c8..31bf89b2 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -100,6 +100,17 @@ class User < ApplicationRecord false end + def is_moderator? + roles.each do |role| + return true if role.name == 'moderator' + end + false + end + + def can_moderate? + self.is_admin? || self.is_moderator? + end + def associated_collections c = collections.blank? ? [] : collections.to_a institutions.each { |i| c.push(*i.collections.to_a) } diff --git a/db/seeds.rb b/db/seeds.rb index 785a3bb7..0a4ba3ef 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -9,6 +9,7 @@ Role.create(name: 'teacher', description: 'This role represents a Teacher in Por Role.create(name: 'student', description: 'This role represents a Student in Portal MEC.') Role.create(name: 'admin', description: 'This role represents an MEC Admin, that can perform any action.') Role.create(name: 'curator', description: 'This role represents a content Curator in Portal MEC.') +Role.create(name: 'moderator', description: 'This role represents a content Moderator in Portal MEC, with less privileges than admin.') # create the default admin User.create( diff --git a/lib/portalmec/sociable_tests.rb b/lib/portalmec/sociable_tests.rb index b7dbc330..822eff0d 100644 --- a/lib/portalmec/sociable_tests.rb +++ b/lib/portalmec/sociable_tests.rb @@ -1,3 +1,5 @@ +require 'active_support' + module Portalmec::SociableTests extend ActiveSupport::Testing::Declarative -- GitLab