diff --git a/app/controllers/v1/activities_controller.rb b/app/controllers/v1/activities_controller.rb index 4d2b7cca1fd972fdc403d1b7a17d8bf017106784..e8de993b7653abc24f5f0ba1c050d3867af60236 100644 --- a/app/controllers/v1/activities_controller.rb +++ b/app/controllers/v1/activities_controller.rb @@ -18,13 +18,13 @@ class V1::ActivitiesController < ApplicationController # Only followers can see user activities def user_activities raise ::Pundit::NotAuthorizedError unless ::ActivityPolicy.new(current_user, resource_model).user_activities? - activities = paginate resource_model.activities + activities = paginate resource_model.activities_filtered render json: activities end def me authorize :activity, :index? - activities = paginate current_user.activities + activities = paginate current_user.activities_filtered render json: activities end end diff --git a/app/controllers/v1/feed_controller.rb b/app/controllers/v1/feed_controller.rb index 3a1d894494aa40c2ee300b2eecd9ffc4d1aba55a..cd1aeb110f26b4f7787d676647ac57d7cacb8f28 100644 --- a/app/controllers/v1/feed_controller.rb +++ b/app/controllers/v1/feed_controller.rb @@ -15,7 +15,7 @@ class V1::FeedController < ApplicationController def activities_followed activities = [] current_user.watching.each do |watching| - activities.push(*watching.activities.to_a) + activities.push(*watching.activities_filtered.to_a) end activities end diff --git a/app/models/concerns/trackable.rb b/app/models/concerns/trackable.rb index f3ee59309230bf71a785b12a15410acff3058363..a8da93f4f48c87701517dfcfef7be35c2164abd5 100644 --- a/app/models/concerns/trackable.rb +++ b/app/models/concerns/trackable.rb @@ -1,10 +1,12 @@ module Trackable extend ActiveSupport::Concern include PublicActivity::Model + include ActivitiesFilterService included do tracked owner: proc { |controller, model| model.try(:user) || model.try(:owner) || controller.try(:current_user) } tracked recipient: proc { |_controller, model| model.try(:recipient) || model } tracked privacy: proc { |_controller, model| model.try(:privacy) || "public" } + end end diff --git a/app/models/learning_object.rb b/app/models/learning_object.rb index 2a4b12d7e532f7ffdffc3dfeedbfcb65b5d1ed8f..6f8678bfd02b61282f35c12517855a286c39bc22 100644 --- a/app/models/learning_object.rb +++ b/app/models/learning_object.rb @@ -59,7 +59,7 @@ class LearningObject < ApplicationRecord belongs_to :attachment, class_name: 'LearningObject::Attachment' validates_presence_of :name, :publisher, :object_type, :language, :author, unless: :draft? - validates :id_dspace, presence: true, uniqueness: true + validates :id_dspace, presence: true, uniqueness: true, unless: :published? default_scope { includes(:object_type, :attachment, :attachments) } scope :missing_thumbnail, ->() { where(thumbnail_file_name: nil) } diff --git a/app/models/user.rb b/app/models/user.rb index 471b39b82e5eeaba1fac6aa768fa90dfa3bf794b..dc186028006aeb0ff63b96c4db549307cca48baa 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -41,6 +41,7 @@ class User < ApplicationRecord include Complainable include Publisher include PublicActivity::Common + include ActivitiesFilterService after_create -> { new_activity("create") } after_update -> { new_activity("update") } @@ -73,7 +74,7 @@ class User < ApplicationRecord after_create :default_role has_attached_file :avatar, styles: { medium: '300x300>', thumb: '60x60>' }, default_url: '' - validates_attachment_content_type :avatar, content_type: %r{ \Aimage\/.*\Z } + validates_attachment_content_type :avatar, content_type: ['image/jpg', 'image/jpeg', 'image/png', 'image/gif'] validates :terms_of_service, acceptance: true searchkick language: 'brazilian', match: :word_start, searchable: [:name], callbacks: :async @@ -177,8 +178,6 @@ class User < ApplicationRecord # ~~~~ end followable actions ~~~~ # - private - def default_role roles << Role.teacher end diff --git a/app/policies/activity_policy.rb b/app/policies/activity_policy.rb index cf550a904aefffe22da19d376b9afa393f382511..ee15995f6a871c2fc9c314388af3c9f5fd6fa74d 100644 --- a/app/policies/activity_policy.rb +++ b/app/policies/activity_policy.rb @@ -1,5 +1,6 @@ class ActivityPolicy < ApplicationPolicy class Scope < Scope + include ActivitiesFilterService attr_reader :user, :scope def initialize(user, scope) @@ -8,8 +9,9 @@ class ActivityPolicy < ApplicationPolicy end def resolve - scope.includes(:owner,:recipient).where("privacy = 'public'").order('created_at DESC').all + scope.includes(:owner,:recipient).where("privacy = 'public'").where.not(key: activities_filter).order('created_at DESC').all end + end def index? diff --git a/app/serializers/learning_object_serializer.rb b/app/serializers/learning_object_serializer.rb index 244635101daf8ab4e0b2b041c5f3f6e8738e19a5..72aa4e3685d071b4803c8f1da0a00960cf7b3d0d 100644 --- a/app/serializers/learning_object_serializer.rb +++ b/app/serializers/learning_object_serializer.rb @@ -21,7 +21,7 @@ class LearningObjectSerializer < ActiveModel::Serializer object.object_type.try(:name) end - def liked? + def liked object.liked? current_user end @@ -42,7 +42,7 @@ class LearningObjectSerializer < ActiveModel::Serializer :link, :software, :license, - :liked?, + :liked, :likes_count, :shares_count, :created_at, diff --git a/app/services/activities_filter_service.rb b/app/services/activities_filter_service.rb new file mode 100644 index 0000000000000000000000000000000000000000..c4e763ff12865bbcd4879a2501dbbb22c75920b0 --- /dev/null +++ b/app/services/activities_filter_service.rb @@ -0,0 +1,22 @@ +module ActivitiesFilterService + + def activities_filtered + self.activities.where.not(key: activities_filter) + end + + def activities_filter + [ 'complaint.update', 'complaint.destroy', + 'complaint_reason.create', 'complaint_reason.update', 'complaint_reason.destroy', + 'institution.create', 'institution.update', 'institution.destroy', + 'review.update', 'review.destroy', + 'rate.create', 'rate.update', 'rate.destroy', + 'follow.create', 'follow.update', 'follow.destroy', + 'share.create', 'share.update', 'share.destroy', + 'view.create', 'view.update', 'view.destroy', + 'tagging.create', 'tagging.update', 'tagging.destroy', + 'bookmark.create', 'bookmark.update', 'bookmark.destroy', + 'download.update', 'download.destroy', + 'like.update' + ] + end +end