This repository has been archived by the owner on May 27, 2022. It is now read-only.
forked from discourse/discourse
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FEATURE: Make allow_uploaded_avatars accept TL (discourse#14091)
This gives admins more control over who can upload custom profile pictures.
- Loading branch information
Showing
12 changed files
with
122 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# frozen_string_literal: true | ||
|
||
class TrustLevelAndStaffAndDisabledSetting < TrustLevelAndStaffSetting | ||
def self.valid_value?(val) | ||
valid_values.include?(val) || (val.to_i.to_s == val.to_s && valid_values.include?(val.to_i)) | ||
end | ||
|
||
def self.valid_values | ||
['disabled'] + TrustLevel.valid_range.to_a + special_groups | ||
end | ||
|
||
def self.translation(value) | ||
if value == 'disabled' | ||
I18n.t('site_settings.disabled') | ||
else | ||
super | ||
end | ||
end | ||
|
||
def self.matches?(value, user) | ||
case value | ||
when 'disabled' | ||
false | ||
when 'staff' | ||
user.staff? | ||
when 'admin' | ||
user.admin? | ||
else | ||
user.has_trust_level?(value.to_i) || user.staff? | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
db/migrate/20210819152920_change_allow_uploaded_avatars.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# frozen_string_literal: true | ||
|
||
class ChangeAllowUploadedAvatars < ActiveRecord::Migration[6.1] | ||
def up | ||
execute <<~SQL | ||
UPDATE site_settings | ||
SET data_type = 7, value = (CASE WHEN value = 'f' THEN 'disabled' ELSE '0' END) | ||
WHERE name = 'allow_uploaded_avatars' | ||
SQL | ||
end | ||
|
||
def down | ||
execute <<~SQL | ||
UPDATE site_settings | ||
SET data_type = 5, value = (CASE WHEN value = 'disabled' THEN 'f' ELSE 't' END) | ||
WHERE name = 'allow_uploaded_avatars' | ||
SQL | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters