diff --git a/app/controllers/concerns/followable_controller.rb b/app/controllers/concerns/followable_controller.rb index d4d1cf569c518cd6fa3caf4e6aaf47478e6e12e9..40cd9139c58200a605c9275eebad11669c096657 100644 --- a/app/controllers/concerns/followable_controller.rb +++ b/app/controllers/concerns/followable_controller.rb @@ -4,7 +4,7 @@ module FollowableController extend ActiveSupport::Concern included do - before_action :authenticate_user!, only: [:follow, :unfollow] + before_action :authenticate_user!, only: [:follow, :unfollow, :follow_toggle] end # POST /v1/users/1/follow diff --git a/app/controllers/v1/collections_controller.rb b/app/controllers/v1/collections_controller.rb index f98194f415a493d02a97252fbfae90702ca218c2..de2f898e974414262eba88d13e6842292f5a851a 100644 --- a/app/controllers/v1/collections_controller.rb +++ b/app/controllers/v1/collections_controller.rb @@ -9,10 +9,10 @@ class V1::CollectionsController < ApplicationController include ::SubjectableController include ::StageableController - before_action :authenticate_user!, only: [:create, :update, :destroy, :tagging, :untagging] - before_action :set_collection, only: [:show, :update, :destroy, :add_object, :delete_object, :subjecting, :unsubjecting, :add_stages, :remove_stages] + before_action :authenticate_user!, only: [:create, :update, :destroy, :tagging, :untagging, :follow, :unfollow, :follow_toggle] + before_action :set_collection, only: [:show, :update, :destroy, :add_object, :delete_object, :subjecting, :unsubjecting, :add_stages, :remove_stages, :follow, :unfollow, :follow_toggle] before_action :set_new_collection, only: :index - before_action :authorize!, except: [:create, :tagging, :untagging, :follow, :unfollow, :download] + before_action :authorize!, except: [:create, :tagging, :untagging, :download] # GET /v1/collections # GET /v1/collections.json diff --git a/app/controllers/v1/feed_controller.rb b/app/controllers/v1/feed_controller.rb index cd1aeb110f26b4f7787d676647ac57d7cacb8f28..365474469518ab4070ef94c0d41a7d5a35462c7a 100644 --- a/app/controllers/v1/feed_controller.rb +++ b/app/controllers/v1/feed_controller.rb @@ -1,5 +1,6 @@ class V1::FeedController < ApplicationController include ::Paginator + include ActivitiesFilterService before_action :authenticate_user! # GET v1/feed @@ -13,11 +14,23 @@ class V1::FeedController < ApplicationController private def activities_followed - activities = [] + query = "" + values = [""] + current_user.watching.each do |watching| - activities.push(*watching.activities_filtered.to_a) + if !watching.respond_to?(:state) || watching.state == "published" + query += " (trackable_type = ? and trackable_id = ?) or (owner_type = ? and owner_id = ?) or (recipient_type = ? and recipient_id = ?) or" + values << watching.class.to_s + values << watching.id + values << watching.class.to_s + values << watching.id + values << watching.class.to_s + values << watching.id + end end - activities + + values[0] = query[0..-3] + PublicActivity::Activity.where(key: activities_filter).where(values).order(created_at: :desc) end end diff --git a/app/policies/followable_policy.rb b/app/policies/followable_policy.rb index 17aba92708f7ba0ea0ddd702d95a22cb1fc1c3e6..c3b5870e6dc8d28f74f98112e4263f2bf8f59b9e 100644 --- a/app/policies/followable_policy.rb +++ b/app/policies/followable_policy.rb @@ -7,4 +7,8 @@ module FollowablePolicy def unfollow? record if user_exists? end + + def follow_toggle? + record if user_exists? + end end diff --git a/spec/acceptance/activities_spec.rb b/spec/acceptance/activities_spec.rb index cb9193f80a09a2118c2620718ff2ed5795c8585b..d20694caab25dde3fd8206e6b51f7dc58214b9bc 100644 --- a/spec/acceptance/activities_spec.rb +++ b/spec/acceptance/activities_spec.rb @@ -40,9 +40,10 @@ resource 'Activities' do include_context "authenticate_user" let(:id) { users.first.id } - + before do create(:follow, followable: users.first, user: @user) + create(:like, user: users.first) end example 'Showing activities from a specific user' do @@ -56,7 +57,8 @@ resource 'Activities' do include_context "authenticate_user" before do - create(:like, user: @user) + create(:follow, followable: users.first, user: @user) + create(:like, user: users.first) end example 'Showing all activities that logged user can see' do