You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

290 lines
8.4 KiB

Optional notification muting (#5087) * Add a hide_notifications column to mutes * Add muting_notifications? and a notifications argument to mute! * block notifications in notify_service from hard muted accounts * Add specs for how mute! interacts with muting_notifications? * specs testing that hide_notifications in mutes actually hides notifications * Add support for muting notifications in MuteService * API support for muting notifications (and specs) * Less gross passing of notifications flag * Break out a separate mute modal with a hide-notifications checkbox. * Convert profile header mute to use mute modal * Satisfy eslint. * specs for MuteService notifications params * add trailing newlines to files for Pork :) * Put the label for the hide notifications checkbox in a label element. * Add a /api/v1/mutes/details route that just returns the array of mutes. * Define a serializer for /api/v1/mutes/details * Add more specs for the /api/v1/mutes/details endpoint * Expose whether a mute hides notifications in the api/v1/relationships endpoint * Show whether muted users' notifications are muted in account lists * Allow modifying the hide_notifications of a mute with the /api/v1/accounts/:id/mute endpoint * make the hide/unhide notifications buttons work * satisfy eslint * In probably dead code, replace a dispatch of muteAccount that was skipping the modal with launching the mute modal. * fix a missing import * add an explanatory comment to AccountInteractions * Refactor handling of default params for muting to make code cleaner * minor code style fixes oops * Fixed a typo that was breaking the account mute API endpoint * Apply white-space: nowrap to account relationships icons * Fix code style issues * Remove superfluous blank line * Rename /api/v1/mutes/details -> /api/v2/mutes * Don't serialize "account" in MuteSerializer Doing so is somewhat unnecessary since it's always the current user's account. * Fix wrong variable name in api/v2/mutes * Use Toggle in place of checkbox in the mute modal. * Make the Toggle in the mute modal look better * Code style changes in specs and removed an extra space * Code review suggestions from akihikodaki Also fixed a syntax error in tests for AccountInteractions. * Make AddHideNotificationsToMute Concurrent It's not clear how much this will benefit instances in practice, as the number of mutes tends to be pretty small, but this should prevent any blocking migrations nonetheless. * Fix up migration things * Remove /api/v2/mutes
6 years ago
Optional notification muting (#5087) * Add a hide_notifications column to mutes * Add muting_notifications? and a notifications argument to mute! * block notifications in notify_service from hard muted accounts * Add specs for how mute! interacts with muting_notifications? * specs testing that hide_notifications in mutes actually hides notifications * Add support for muting notifications in MuteService * API support for muting notifications (and specs) * Less gross passing of notifications flag * Break out a separate mute modal with a hide-notifications checkbox. * Convert profile header mute to use mute modal * Satisfy eslint. * specs for MuteService notifications params * add trailing newlines to files for Pork :) * Put the label for the hide notifications checkbox in a label element. * Add a /api/v1/mutes/details route that just returns the array of mutes. * Define a serializer for /api/v1/mutes/details * Add more specs for the /api/v1/mutes/details endpoint * Expose whether a mute hides notifications in the api/v1/relationships endpoint * Show whether muted users' notifications are muted in account lists * Allow modifying the hide_notifications of a mute with the /api/v1/accounts/:id/mute endpoint * make the hide/unhide notifications buttons work * satisfy eslint * In probably dead code, replace a dispatch of muteAccount that was skipping the modal with launching the mute modal. * fix a missing import * add an explanatory comment to AccountInteractions * Refactor handling of default params for muting to make code cleaner * minor code style fixes oops * Fixed a typo that was breaking the account mute API endpoint * Apply white-space: nowrap to account relationships icons * Fix code style issues * Remove superfluous blank line * Rename /api/v1/mutes/details -> /api/v2/mutes * Don't serialize "account" in MuteSerializer Doing so is somewhat unnecessary since it's always the current user's account. * Fix wrong variable name in api/v2/mutes * Use Toggle in place of checkbox in the mute modal. * Make the Toggle in the mute modal look better * Code style changes in specs and removed an extra space * Code review suggestions from akihikodaki Also fixed a syntax error in tests for AccountInteractions. * Make AddHideNotificationsToMute Concurrent It's not clear how much this will benefit instances in practice, as the number of mutes tends to be pretty small, but this should prevent any blocking migrations nonetheless. * Fix up migration things * Remove /api/v2/mutes
6 years ago
Optional notification muting (#5087) * Add a hide_notifications column to mutes * Add muting_notifications? and a notifications argument to mute! * block notifications in notify_service from hard muted accounts * Add specs for how mute! interacts with muting_notifications? * specs testing that hide_notifications in mutes actually hides notifications * Add support for muting notifications in MuteService * API support for muting notifications (and specs) * Less gross passing of notifications flag * Break out a separate mute modal with a hide-notifications checkbox. * Convert profile header mute to use mute modal * Satisfy eslint. * specs for MuteService notifications params * add trailing newlines to files for Pork :) * Put the label for the hide notifications checkbox in a label element. * Add a /api/v1/mutes/details route that just returns the array of mutes. * Define a serializer for /api/v1/mutes/details * Add more specs for the /api/v1/mutes/details endpoint * Expose whether a mute hides notifications in the api/v1/relationships endpoint * Show whether muted users' notifications are muted in account lists * Allow modifying the hide_notifications of a mute with the /api/v1/accounts/:id/mute endpoint * make the hide/unhide notifications buttons work * satisfy eslint * In probably dead code, replace a dispatch of muteAccount that was skipping the modal with launching the mute modal. * fix a missing import * add an explanatory comment to AccountInteractions * Refactor handling of default params for muting to make code cleaner * minor code style fixes oops * Fixed a typo that was breaking the account mute API endpoint * Apply white-space: nowrap to account relationships icons * Fix code style issues * Remove superfluous blank line * Rename /api/v1/mutes/details -> /api/v2/mutes * Don't serialize "account" in MuteSerializer Doing so is somewhat unnecessary since it's always the current user's account. * Fix wrong variable name in api/v2/mutes * Use Toggle in place of checkbox in the mute modal. * Make the Toggle in the mute modal look better * Code style changes in specs and removed an extra space * Code review suggestions from akihikodaki Also fixed a syntax error in tests for AccountInteractions. * Make AddHideNotificationsToMute Concurrent It's not clear how much this will benefit instances in practice, as the number of mutes tends to be pretty small, but this should prevent any blocking migrations nonetheless. * Fix up migration things * Remove /api/v2/mutes
6 years ago
Optional notification muting (#5087) * Add a hide_notifications column to mutes * Add muting_notifications? and a notifications argument to mute! * block notifications in notify_service from hard muted accounts * Add specs for how mute! interacts with muting_notifications? * specs testing that hide_notifications in mutes actually hides notifications * Add support for muting notifications in MuteService * API support for muting notifications (and specs) * Less gross passing of notifications flag * Break out a separate mute modal with a hide-notifications checkbox. * Convert profile header mute to use mute modal * Satisfy eslint. * specs for MuteService notifications params * add trailing newlines to files for Pork :) * Put the label for the hide notifications checkbox in a label element. * Add a /api/v1/mutes/details route that just returns the array of mutes. * Define a serializer for /api/v1/mutes/details * Add more specs for the /api/v1/mutes/details endpoint * Expose whether a mute hides notifications in the api/v1/relationships endpoint * Show whether muted users' notifications are muted in account lists * Allow modifying the hide_notifications of a mute with the /api/v1/accounts/:id/mute endpoint * make the hide/unhide notifications buttons work * satisfy eslint * In probably dead code, replace a dispatch of muteAccount that was skipping the modal with launching the mute modal. * fix a missing import * add an explanatory comment to AccountInteractions * Refactor handling of default params for muting to make code cleaner * minor code style fixes oops * Fixed a typo that was breaking the account mute API endpoint * Apply white-space: nowrap to account relationships icons * Fix code style issues * Remove superfluous blank line * Rename /api/v1/mutes/details -> /api/v2/mutes * Don't serialize "account" in MuteSerializer Doing so is somewhat unnecessary since it's always the current user's account. * Fix wrong variable name in api/v2/mutes * Use Toggle in place of checkbox in the mute modal. * Make the Toggle in the mute modal look better * Code style changes in specs and removed an extra space * Code review suggestions from akihikodaki Also fixed a syntax error in tests for AccountInteractions. * Make AddHideNotificationsToMute Concurrent It's not clear how much this will benefit instances in practice, as the number of mutes tends to be pretty small, but this should prevent any blocking migrations nonetheless. * Fix up migration things * Remove /api/v2/mutes
6 years ago
Optional notification muting (#5087) * Add a hide_notifications column to mutes * Add muting_notifications? and a notifications argument to mute! * block notifications in notify_service from hard muted accounts * Add specs for how mute! interacts with muting_notifications? * specs testing that hide_notifications in mutes actually hides notifications * Add support for muting notifications in MuteService * API support for muting notifications (and specs) * Less gross passing of notifications flag * Break out a separate mute modal with a hide-notifications checkbox. * Convert profile header mute to use mute modal * Satisfy eslint. * specs for MuteService notifications params * add trailing newlines to files for Pork :) * Put the label for the hide notifications checkbox in a label element. * Add a /api/v1/mutes/details route that just returns the array of mutes. * Define a serializer for /api/v1/mutes/details * Add more specs for the /api/v1/mutes/details endpoint * Expose whether a mute hides notifications in the api/v1/relationships endpoint * Show whether muted users' notifications are muted in account lists * Allow modifying the hide_notifications of a mute with the /api/v1/accounts/:id/mute endpoint * make the hide/unhide notifications buttons work * satisfy eslint * In probably dead code, replace a dispatch of muteAccount that was skipping the modal with launching the mute modal. * fix a missing import * add an explanatory comment to AccountInteractions * Refactor handling of default params for muting to make code cleaner * minor code style fixes oops * Fixed a typo that was breaking the account mute API endpoint * Apply white-space: nowrap to account relationships icons * Fix code style issues * Remove superfluous blank line * Rename /api/v1/mutes/details -> /api/v2/mutes * Don't serialize "account" in MuteSerializer Doing so is somewhat unnecessary since it's always the current user's account. * Fix wrong variable name in api/v2/mutes * Use Toggle in place of checkbox in the mute modal. * Make the Toggle in the mute modal look better * Code style changes in specs and removed an extra space * Code review suggestions from akihikodaki Also fixed a syntax error in tests for AccountInteractions. * Make AddHideNotificationsToMute Concurrent It's not clear how much this will benefit instances in practice, as the number of mutes tends to be pretty small, but this should prevent any blocking migrations nonetheless. * Fix up migration things * Remove /api/v2/mutes
6 years ago
  1. require 'rails_helper'
  2. RSpec.describe Api::V1::AccountsController, type: :controller do
  3. render_views
  4. let(:user) { Fabricate(:user, account: Fabricate(:account, username: 'alice')) }
  5. let(:scopes) { '' }
  6. let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
  7. before do
  8. allow(controller).to receive(:doorkeeper_token) { token }
  9. end
  10. shared_examples 'forbidden for wrong scope' do |wrong_scope|
  11. let(:scopes) { wrong_scope }
  12. it 'returns http forbidden' do
  13. expect(response).to have_http_status(403)
  14. end
  15. end
  16. describe 'POST #create' do
  17. let(:app) { Fabricate(:application) }
  18. let(:token) { Doorkeeper::AccessToken.find_or_create_for(application: app, resource_owner: nil, scopes: 'read write', use_refresh_token: false) }
  19. let(:agreement) { nil }
  20. before do
  21. post :create, params: { username: 'test', password: '12345678', email: 'hello@world.tld', agreement: agreement }
  22. end
  23. context 'given truthy agreement' do
  24. let(:agreement) { 'true' }
  25. it 'returns http success' do
  26. expect(response).to have_http_status(200)
  27. end
  28. it 'returns a new access token as JSON' do
  29. expect(body_as_json[:access_token]).to_not be_blank
  30. end
  31. it 'creates a user' do
  32. user = User.find_by(email: 'hello@world.tld')
  33. expect(user).to_not be_nil
  34. expect(user.created_by_application_id).to eq app.id
  35. end
  36. end
  37. context 'given no agreement' do
  38. it 'returns http unprocessable entity' do
  39. expect(response).to have_http_status(422)
  40. end
  41. end
  42. end
  43. describe 'GET #show' do
  44. let(:scopes) { 'read:accounts' }
  45. before do
  46. get :show, params: { id: user.account.id }
  47. end
  48. it 'returns http success' do
  49. expect(response).to have_http_status(200)
  50. end
  51. it_behaves_like 'forbidden for wrong scope', 'write:statuses'
  52. end
  53. describe 'POST #follow' do
  54. let(:scopes) { 'write:follows' }
  55. let(:other_account) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob', locked: locked)).account }
  56. context do
  57. before do
  58. post :follow, params: { id: other_account.id }
  59. end
  60. context 'with unlocked account' do
  61. let(:locked) { false }
  62. it 'returns http success' do
  63. expect(response).to have_http_status(200)
  64. end
  65. it 'returns JSON with following=true and requested=false' do
  66. json = body_as_json
  67. expect(json[:following]).to be true
  68. expect(json[:requested]).to be false
  69. end
  70. it 'creates a following relation between user and target user' do
  71. expect(user.account.following?(other_account)).to be true
  72. end
  73. it_behaves_like 'forbidden for wrong scope', 'read:accounts'
  74. end
  75. context 'with locked account' do
  76. let(:locked) { true }
  77. it 'returns http success' do
  78. expect(response).to have_http_status(200)
  79. end
  80. it 'returns JSON with following=false and requested=true' do
  81. json = body_as_json
  82. expect(json[:following]).to be false
  83. expect(json[:requested]).to be true
  84. end
  85. it 'creates a follow request relation between user and target user' do
  86. expect(user.account.requested?(other_account)).to be true
  87. end
  88. it_behaves_like 'forbidden for wrong scope', 'read:accounts'
  89. end
  90. end
  91. context 'modifying follow options' do
  92. let(:locked) { false }
  93. before do
  94. user.account.follow!(other_account, reblogs: false, notify: false)
  95. end
  96. it 'changes reblogs option' do
  97. post :follow, params: { id: other_account.id, reblogs: true }
  98. json = body_as_json
  99. expect(json[:following]).to be true
  100. expect(json[:showing_reblogs]).to be true
  101. expect(json[:notifying]).to be false
  102. end
  103. it 'changes notify option' do
  104. post :follow, params: { id: other_account.id, notify: true }
  105. json = body_as_json
  106. expect(json[:following]).to be true
  107. expect(json[:showing_reblogs]).to be false
  108. expect(json[:notifying]).to be true
  109. end
  110. end
  111. end
  112. describe 'POST #unfollow' do
  113. let(:scopes) { 'write:follows' }
  114. let(:other_account) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob')).account }
  115. before do
  116. user.account.follow!(other_account)
  117. post :unfollow, params: { id: other_account.id }
  118. end
  119. it 'returns http success' do
  120. expect(response).to have_http_status(200)
  121. end
  122. it 'removes the following relation between user and target user' do
  123. expect(user.account.following?(other_account)).to be false
  124. end
  125. it_behaves_like 'forbidden for wrong scope', 'read:accounts'
  126. end
  127. describe 'POST #block' do
  128. let(:scopes) { 'write:blocks' }
  129. let(:other_account) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob')).account }
  130. before do
  131. user.account.follow!(other_account)
  132. post :block, params: { id: other_account.id }
  133. end
  134. it 'returns http success' do
  135. expect(response).to have_http_status(200)
  136. end
  137. it 'removes the following relation between user and target user' do
  138. expect(user.account.following?(other_account)).to be false
  139. end
  140. it 'creates a blocking relation' do
  141. expect(user.account.blocking?(other_account)).to be true
  142. end
  143. it_behaves_like 'forbidden for wrong scope', 'read:accounts'
  144. end
  145. describe 'POST #unblock' do
  146. let(:scopes) { 'write:blocks' }
  147. let(:other_account) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob')).account }
  148. before do
  149. user.account.block!(other_account)
  150. post :unblock, params: { id: other_account.id }
  151. end
  152. it 'returns http success' do
  153. expect(response).to have_http_status(200)
  154. end
  155. it 'removes the blocking relation between user and target user' do
  156. expect(user.account.blocking?(other_account)).to be false
  157. end
  158. it_behaves_like 'forbidden for wrong scope', 'read:accounts'
  159. end
  160. describe 'POST #mute' do
  161. let(:scopes) { 'write:mutes' }
  162. let(:other_account) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob')).account }
  163. before do
  164. user.account.follow!(other_account)
  165. post :mute, params: { id: other_account.id }
  166. end
  167. it 'returns http success' do
  168. expect(response).to have_http_status(200)
  169. end
  170. it 'does not remove the following relation between user and target user' do
  171. expect(user.account.following?(other_account)).to be true
  172. end
  173. it 'creates a muting relation' do
  174. expect(user.account.muting?(other_account)).to be true
  175. end
  176. it 'mutes notifications' do
  177. expect(user.account.muting_notifications?(other_account)).to be true
  178. end
  179. it_behaves_like 'forbidden for wrong scope', 'read:accounts'
  180. end
  181. describe 'POST #mute with notifications set to false' do
  182. let(:scopes) { 'write:mutes' }
  183. let(:other_account) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob')).account }
  184. before do
  185. user.account.follow!(other_account)
  186. post :mute, params: { id: other_account.id, notifications: false }
  187. end
  188. it 'returns http success' do
  189. expect(response).to have_http_status(200)
  190. end
  191. it 'does not remove the following relation between user and target user' do
  192. expect(user.account.following?(other_account)).to be true
  193. end
  194. it 'creates a muting relation' do
  195. expect(user.account.muting?(other_account)).to be true
  196. end
  197. it 'does not mute notifications' do
  198. expect(user.account.muting_notifications?(other_account)).to be false
  199. end
  200. it_behaves_like 'forbidden for wrong scope', 'read:accounts'
  201. end
  202. describe 'POST #unmute' do
  203. let(:scopes) { 'write:mutes' }
  204. let(:other_account) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob')).account }
  205. before do
  206. user.account.mute!(other_account)
  207. post :unmute, params: { id: other_account.id }
  208. end
  209. it 'returns http success' do
  210. expect(response).to have_http_status(200)
  211. end
  212. it 'removes the muting relation between user and target user' do
  213. expect(user.account.muting?(other_account)).to be false
  214. end
  215. it_behaves_like 'forbidden for wrong scope', 'read:accounts'
  216. end
  217. end