Skip to content
Snippets Groups Projects
Commit 9a2fe8af authored by Marcela Ribeiro de Oliveira's avatar Marcela Ribeiro de Oliveira
Browse files

Merge branch 'master' of gitlab.c3sl.ufpr.br:portalmec/portalmec into...

Merge branch 'master' of gitlab.c3sl.ufpr.br:portalmec/portalmec into fix-collection_item_serializer
parents d10d1b5a badacd18
No related branches found
No related tags found
No related merge requests found
......@@ -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
......@@ -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
......
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
......@@ -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) }
......
......@@ -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
......
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?
......
......@@ -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,
......
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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment