mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
DEV: Convert allow_uploaded_avatars to groups (#24810)
This change converts the allow_uploaded_avatars site setting to uploaded_avatars_allowed_groups. See: https://meta.discourse.org/t/283408 Hides the old setting Adds the new site setting Adds a deprecation warning Updates to use the new setting Adds a migration to fill in the new setting if the old setting was changed Adds an entry to the site_setting.keywords section Updates tests to account for the new change After a couple of months, we will remove the allow_uploaded_avatars setting entirely. Internal ref: /t/117248
This commit is contained in:
committed by
GitHub
parent
8355664c82
commit
1017820012
@@ -100,7 +100,7 @@ RSpec.describe ComposerMessagesFinder do
|
||||
|
||||
describe ".check_avatar_notification" do
|
||||
let(:finder) { ComposerMessagesFinder.new(user, composer_action: "createTopic") }
|
||||
fab!(:user)
|
||||
fab!(:user) { Fabricate(:user, refresh_auto_groups: true) }
|
||||
|
||||
context "with success" do
|
||||
let!(:message) { finder.check_avatar_notification }
|
||||
@@ -143,8 +143,15 @@ RSpec.describe ComposerMessagesFinder do
|
||||
end
|
||||
|
||||
it "doesn't notify users if 'allow_uploaded_avatars' setting is disabled" do
|
||||
SiteSetting.allow_uploaded_avatars = "disabled"
|
||||
user.update!(trust_level: 3)
|
||||
Group.refresh_automatic_groups!
|
||||
user.reload
|
||||
|
||||
SiteSetting.uploaded_avatars_allowed_groups = ""
|
||||
expect(finder.check_avatar_notification).to be_blank
|
||||
|
||||
SiteSetting.uploaded_avatars_allowed_groups = "13"
|
||||
expect(finder.check_avatar_notification).to be_present
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -185,7 +185,7 @@ RSpec.describe "users" do
|
||||
response "200", "avatar updated" do
|
||||
expected_response_schema = load_spec_schema("success_ok_response")
|
||||
|
||||
let(:user) { Fabricate(:user) }
|
||||
let(:user) { Fabricate(:user, refresh_auto_groups: true) }
|
||||
let(:username) { user.username }
|
||||
let(:upload) { Fabricate(:upload, user: user) }
|
||||
let(:params) { { "upload_id" => upload.id, "type" => "uploaded" } }
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
RSpec.describe UploadsController do
|
||||
fab!(:user)
|
||||
fab!(:user) { Fabricate(:user, refresh_auto_groups: true) }
|
||||
|
||||
describe "#create" do
|
||||
it "requires you to be logged in" do
|
||||
@@ -132,10 +132,15 @@ RSpec.describe UploadsController do
|
||||
)
|
||||
end
|
||||
|
||||
it "ensures allow_uploaded_avatars is enabled when uploading an avatar" do
|
||||
SiteSetting.allow_uploaded_avatars = "disabled"
|
||||
it "ensures user belongs to uploaded_avatars_allowed_groups when uploading an avatar" do
|
||||
SiteSetting.uploaded_avatars_allowed_groups = "13"
|
||||
post "/uploads.json", params: { file: logo, type: "avatar" }
|
||||
expect(response.status).to eq(422)
|
||||
|
||||
user.update!(trust_level: 3)
|
||||
Group.refresh_automatic_groups!
|
||||
post "/uploads.json", params: { file: logo, type: "avatar" }
|
||||
expect(response.status).to eq(200)
|
||||
end
|
||||
|
||||
it "ensures discourse_connect_overrides_avatar is not enabled when uploading an avatar" do
|
||||
@@ -144,14 +149,6 @@ RSpec.describe UploadsController do
|
||||
expect(response.status).to eq(422)
|
||||
end
|
||||
|
||||
it "always allows admins to upload avatars" do
|
||||
sign_in(Fabricate(:admin))
|
||||
SiteSetting.allow_uploaded_avatars = "disabled"
|
||||
|
||||
post "/uploads.json", params: { file: logo, type: "avatar" }
|
||||
expect(response.status).to eq(200)
|
||||
end
|
||||
|
||||
it "allows staff to upload any file in PM" do
|
||||
SiteSetting.authorized_extensions = "jpg"
|
||||
SiteSetting.allow_staff_to_upload_any_file_in_pm = true
|
||||
|
||||
@@ -3342,8 +3342,8 @@ RSpec.describe UsersController do
|
||||
expect(response.status).to eq(422)
|
||||
end
|
||||
|
||||
it "raises an error when selecting the custom/uploaded avatar and allow_uploaded_avatars is disabled" do
|
||||
SiteSetting.allow_uploaded_avatars = "disabled"
|
||||
it "raises an error when selecting the custom/uploaded avatar and uploaded_avatars_allowed_groups is disabled" do
|
||||
SiteSetting.uploaded_avatars_allowed_groups = ""
|
||||
put "/u/#{user1.username}/preferences/avatar/pick.json",
|
||||
params: {
|
||||
upload_id: upload.id,
|
||||
@@ -3353,8 +3353,8 @@ RSpec.describe UsersController do
|
||||
expect(response.status).to eq(422)
|
||||
end
|
||||
|
||||
it "raises an error when selecting the custom/uploaded avatar and allow_uploaded_avatars is admin" do
|
||||
SiteSetting.allow_uploaded_avatars = "admin"
|
||||
it "raises an error when selecting the custom/uploaded avatar and uploaded_avatars_allowed_groups is admin" do
|
||||
SiteSetting.uploaded_avatars_allowed_groups = "1"
|
||||
put "/u/#{user1.username}/preferences/avatar/pick.json",
|
||||
params: {
|
||||
upload_id: upload.id,
|
||||
@@ -3363,6 +3363,7 @@ RSpec.describe UsersController do
|
||||
expect(response.status).to eq(422)
|
||||
|
||||
user1.update!(admin: true)
|
||||
Group.refresh_automatic_groups!
|
||||
put "/u/#{user1.username}/preferences/avatar/pick.json",
|
||||
params: {
|
||||
upload_id: upload.id,
|
||||
@@ -3371,8 +3372,8 @@ RSpec.describe UsersController do
|
||||
expect(response.status).to eq(200)
|
||||
end
|
||||
|
||||
it "raises an error when selecting the custom/uploaded avatar and allow_uploaded_avatars is staff" do
|
||||
SiteSetting.allow_uploaded_avatars = "staff"
|
||||
it "raises an error when selecting the custom/uploaded avatar and uploaded_avatars_allowed_groups is staff" do
|
||||
SiteSetting.uploaded_avatars_allowed_groups = "3"
|
||||
put "/u/#{user1.username}/preferences/avatar/pick.json",
|
||||
params: {
|
||||
upload_id: upload.id,
|
||||
@@ -3381,6 +3382,7 @@ RSpec.describe UsersController do
|
||||
expect(response.status).to eq(422)
|
||||
|
||||
user1.update!(moderator: true)
|
||||
Group.refresh_automatic_groups!
|
||||
put "/u/#{user1.username}/preferences/avatar/pick.json",
|
||||
params: {
|
||||
upload_id: upload.id,
|
||||
@@ -3389,8 +3391,8 @@ RSpec.describe UsersController do
|
||||
expect(response.status).to eq(200)
|
||||
end
|
||||
|
||||
it "raises an error when selecting the custom/uploaded avatar and allow_uploaded_avatars is a trust level" do
|
||||
SiteSetting.allow_uploaded_avatars = "3"
|
||||
it "raises an error when selecting the custom/uploaded avatar and uploaded_avatars_allowed_groups is a trust level" do
|
||||
SiteSetting.uploaded_avatars_allowed_groups = "13"
|
||||
put "/u/#{user1.username}/preferences/avatar/pick.json",
|
||||
params: {
|
||||
upload_id: upload.id,
|
||||
@@ -3399,6 +3401,7 @@ RSpec.describe UsersController do
|
||||
expect(response.status).to eq(422)
|
||||
|
||||
user1.update!(trust_level: 3)
|
||||
Group.refresh_automatic_groups!
|
||||
put "/u/#{user1.username}/preferences/avatar/pick.json",
|
||||
params: {
|
||||
upload_id: upload.id,
|
||||
@@ -3408,7 +3411,7 @@ RSpec.describe UsersController do
|
||||
end
|
||||
|
||||
it "ignores the upload if picking a system avatar" do
|
||||
SiteSetting.allow_uploaded_avatars = "disabled"
|
||||
SiteSetting.uploaded_avatars_allowed_groups = ""
|
||||
another_upload = Fabricate(:upload)
|
||||
|
||||
put "/u/#{user1.username}/preferences/avatar/pick.json",
|
||||
@@ -3422,7 +3425,7 @@ RSpec.describe UsersController do
|
||||
end
|
||||
|
||||
it "raises an error if the type is invalid" do
|
||||
SiteSetting.allow_uploaded_avatars = "disabled"
|
||||
SiteSetting.uploaded_avatars_allowed_groups = ""
|
||||
another_upload = Fabricate(:upload)
|
||||
|
||||
put "/u/#{user1.username}/preferences/avatar/pick.json",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
describe "User preferences for Account", type: :system do
|
||||
fab!(:user)
|
||||
fab!(:user) { Fabricate(:user, refresh_auto_groups: true) }
|
||||
let(:user_account_preferences_page) { PageObjects::Pages::UserPreferencesAccount.new }
|
||||
let(:avatar_selector_modal) { PageObjects::Modals::AvatarSelector.new }
|
||||
before { sign_in(user) }
|
||||
|
||||
Reference in New Issue
Block a user