2019-04-30 08:27:42 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-10-11 17:41:23 +08:00
|
|
|
require 'rails_helper'
|
2013-05-27 08:22:37 +08:00
|
|
|
|
|
|
|
describe UserActionsController do
|
|
|
|
context 'index' do
|
|
|
|
|
2013-05-27 09:02:58 +08:00
|
|
|
it 'fails if username is not specified' do
|
2018-06-05 21:02:59 +08:00
|
|
|
get "/user_actions.json"
|
|
|
|
expect(response.status).to eq(400)
|
2013-05-27 09:02:58 +08:00
|
|
|
end
|
|
|
|
|
2013-05-27 08:22:37 +08:00
|
|
|
it 'renders list correctly' do
|
2019-01-04 01:03:01 +08:00
|
|
|
UserActionManager.enable
|
|
|
|
post = create_post
|
2013-05-27 08:22:37 +08:00
|
|
|
|
2018-06-05 21:02:59 +08:00
|
|
|
get "/user_actions.json", params: { username: post.user.username }
|
2013-05-27 08:22:37 +08:00
|
|
|
|
2015-01-10 01:04:02 +08:00
|
|
|
expect(response.status).to eq(200)
|
2020-05-07 23:04:12 +08:00
|
|
|
parsed = response.parsed_body
|
2013-05-27 08:22:37 +08:00
|
|
|
actions = parsed["user_actions"]
|
2015-01-10 01:04:02 +08:00
|
|
|
expect(actions.length).to eq(1)
|
2013-05-27 08:22:37 +08:00
|
|
|
action = actions[0]
|
2015-01-10 01:04:02 +08:00
|
|
|
expect(action["acting_name"]).to eq(post.user.name)
|
|
|
|
expect(action["email"]).to eq(nil)
|
|
|
|
expect(action["post_number"]).to eq(1)
|
2013-05-27 08:22:37 +08:00
|
|
|
end
|
2015-04-22 02:36:46 +08:00
|
|
|
|
2019-01-16 10:40:16 +08:00
|
|
|
it 'can be filtered by acting_username' do
|
2019-01-04 01:03:01 +08:00
|
|
|
UserActionManager.enable
|
2019-01-16 10:40:16 +08:00
|
|
|
PostActionNotifier.enable
|
|
|
|
|
|
|
|
post = Fabricate(:post)
|
|
|
|
user = Fabricate(:user)
|
2019-01-04 01:03:01 +08:00
|
|
|
PostActionCreator.like(user, post)
|
2019-01-16 10:40:16 +08:00
|
|
|
|
|
|
|
get "/user_actions.json", params: {
|
|
|
|
username: post.user.username,
|
|
|
|
acting_username: user.username
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
|
2020-05-07 23:04:12 +08:00
|
|
|
response_body = response.parsed_body
|
2019-01-16 10:40:16 +08:00
|
|
|
|
|
|
|
expect(response_body["user_actions"].count).to eq(1)
|
|
|
|
|
|
|
|
expect(response_body["user_actions"].first["acting_username"])
|
|
|
|
.to eq(user.username)
|
|
|
|
end
|
|
|
|
|
2016-11-29 14:55:39 +08:00
|
|
|
it 'renders help text if provided for self' do
|
2018-06-05 21:02:59 +08:00
|
|
|
logged_in = sign_in(Fabricate(:user))
|
2016-11-29 14:55:39 +08:00
|
|
|
|
2018-06-05 21:02:59 +08:00
|
|
|
get "/user_actions.json", params: {
|
2017-08-31 12:06:56 +08:00
|
|
|
filter: UserAction::LIKE,
|
|
|
|
username: logged_in.username,
|
|
|
|
no_results_help_key: "user_activity.no_bookmarks"
|
2018-06-05 21:02:59 +08:00
|
|
|
}
|
2016-11-29 14:55:39 +08:00
|
|
|
|
|
|
|
expect(response.status).to eq(200)
|
2020-05-07 23:04:12 +08:00
|
|
|
parsed = response.parsed_body
|
2016-11-29 14:55:39 +08:00
|
|
|
|
|
|
|
expect(parsed["no_results_help"]).to eq(I18n.t("user_activity.no_bookmarks.self"))
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'renders help text for others' do
|
|
|
|
user = Fabricate(:user)
|
2017-08-31 12:06:56 +08:00
|
|
|
|
2018-06-05 21:02:59 +08:00
|
|
|
get "/user_actions.json", params: {
|
2017-08-31 12:06:56 +08:00
|
|
|
filter: UserAction::LIKE,
|
|
|
|
username: user.username,
|
|
|
|
no_results_help_key: "user_activity.no_bookmarks"
|
2018-06-05 21:02:59 +08:00
|
|
|
}
|
2016-11-29 14:55:39 +08:00
|
|
|
|
|
|
|
expect(response.status).to eq(200)
|
2020-05-07 23:04:12 +08:00
|
|
|
parsed = response.parsed_body
|
2016-11-29 14:55:39 +08:00
|
|
|
|
2016-11-29 15:01:09 +08:00
|
|
|
expect(parsed["no_results_help"]).to eq(I18n.t("user_activity.no_bookmarks.others"))
|
2016-11-29 14:55:39 +08:00
|
|
|
end
|
|
|
|
|
2020-10-10 05:18:44 +08:00
|
|
|
context 'hidden profiles' do
|
|
|
|
fab!(:post) { Fabricate(:post) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
UserActionManager.enable
|
|
|
|
post.user.user_option.update_column(:hide_profile_and_presence, true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns a 404" do
|
|
|
|
get "/user_actions.json", params: { username: post.user.username }
|
|
|
|
expect(response.code).to eq("404")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "succeeds when `allow_users_to_hide_profile` is false" do
|
|
|
|
SiteSetting.allow_users_to_hide_profile = false
|
|
|
|
get "/user_actions.json", params: { username: post.user.username }
|
|
|
|
expect(response.code).to eq("200")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-09-29 20:24:28 +08:00
|
|
|
context "other users' activity" do
|
|
|
|
fab!(:another_user) { Fabricate(:user) }
|
|
|
|
|
|
|
|
UserAction.private_types.each do |action_type|
|
|
|
|
action_name = UserAction.types.key(action_type)
|
|
|
|
it "anonymous users cannot list other users' actions of type: #{action_name}" do
|
|
|
|
list_and_check(action_type, 404)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
UserAction.private_types.each do |action_type|
|
|
|
|
fab!(:user) { Fabricate(:user) }
|
|
|
|
action_name = UserAction.types.key(action_type)
|
|
|
|
|
|
|
|
it "logged in users cannot list other users' actions of type: #{action_name}" do
|
|
|
|
sign_in(user)
|
|
|
|
list_and_check(action_type, 404)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
UserAction.private_types.each do |action_type|
|
|
|
|
fab!(:moderator) { Fabricate(:moderator) }
|
|
|
|
action_name = UserAction.types.key(action_type)
|
|
|
|
|
|
|
|
it "moderators cannot list other users' actions of type: #{action_name}" do
|
|
|
|
sign_in(moderator)
|
|
|
|
list_and_check(action_type, 404)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
UserAction.private_types.each do |action_type|
|
|
|
|
fab!(:admin) { Fabricate(:admin) }
|
|
|
|
action_name = UserAction.types.key(action_type)
|
|
|
|
|
|
|
|
it "admins can list other users' actions of type: #{action_name}" do
|
|
|
|
sign_in(admin)
|
|
|
|
list_and_check(action_type, 200)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def list_and_check(action_type, expected_response)
|
|
|
|
get "/user_actions.json", params: {
|
|
|
|
filter: action_type,
|
|
|
|
username: another_user.username
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(response.status).to eq(expected_response)
|
|
|
|
end
|
|
|
|
end
|
2013-05-27 08:22:37 +08:00
|
|
|
end
|
|
|
|
end
|