From 09bb3c7fae8095a6653d417c131d8f4a891b3d22 Mon Sep 17 00:00:00 2001 From: Giovanne Marcelo <gms15@inf.ufpr.br> Date: Thu, 10 Mar 2016 11:57:07 -0300 Subject: [PATCH] Fixing concerns policies --- app/policies/collection_policy.rb | 2 ++ app/policies/followable_policy.rb | 10 ++++++++++ app/policies/learning_object_policy.rb | 3 +++ app/policies/reportable_policy.rb | 10 ++++++++++ app/policies/sociable_policy.rb | 18 ++++++++++++++++++ app/policies/user_policy.rb | 9 ++------- 6 files changed, 45 insertions(+), 7 deletions(-) create mode 100644 app/policies/followable_policy.rb create mode 100644 app/policies/reportable_policy.rb create mode 100644 app/policies/sociable_policy.rb diff --git a/app/policies/collection_policy.rb b/app/policies/collection_policy.rb index ecb2a483..e24b8c1c 100644 --- a/app/policies/collection_policy.rb +++ b/app/policies/collection_policy.rb @@ -1,4 +1,6 @@ class CollectionPolicy < ApplicationPolicy + include SociablePolicy + include FollowablePolicy def create? record if user_exists? diff --git a/app/policies/followable_policy.rb b/app/policies/followable_policy.rb new file mode 100644 index 00000000..17aba927 --- /dev/null +++ b/app/policies/followable_policy.rb @@ -0,0 +1,10 @@ +module FollowablePolicy + + def follow? + record if user_exists? + end + + def unfollow? + record if user_exists? + end +end diff --git a/app/policies/learning_object_policy.rb b/app/policies/learning_object_policy.rb index 15b25f33..e91c7db7 100644 --- a/app/policies/learning_object_policy.rb +++ b/app/policies/learning_object_policy.rb @@ -1,4 +1,7 @@ class LearningObjectPolicy < ApplicationPolicy + include SociablePolicy + include ReportablePolicy + class Scope < Scope def resolve if user.nil? diff --git a/app/policies/reportable_policy.rb b/app/policies/reportable_policy.rb new file mode 100644 index 00000000..e7a36a5d --- /dev/null +++ b/app/policies/reportable_policy.rb @@ -0,0 +1,10 @@ +module ReportablePolicy + + def report_object? + record if user_exists? + end + + def set_complaint_messages? + record if user_exists? + end +end diff --git a/app/policies/sociable_policy.rb b/app/policies/sociable_policy.rb new file mode 100644 index 00000000..ca646cc8 --- /dev/null +++ b/app/policies/sociable_policy.rb @@ -0,0 +1,18 @@ +module SociablePolicy + + def like? + record if user_exists? + end + + def dislike? + record if user_exists? + end + + def liked? + record if user_exists? + end + + def download? + record if user_exists? + end +end diff --git a/app/policies/user_policy.rb b/app/policies/user_policy.rb index 5fc8e584..9e4a7612 100644 --- a/app/policies/user_policy.rb +++ b/app/policies/user_policy.rb @@ -1,4 +1,6 @@ class UserPolicy < ApplicationPolicy + include FollowablePolicy + def show? record if user_exists? end @@ -7,11 +9,4 @@ class UserPolicy < ApplicationPolicy record end - def follow? - record if user_exists? - end - - def unfollow? - record if user_exists? - end end -- GitLab