User card settings (#10302)

User card settings (#10302)

  • settings implemented

  • prettier

  • settings updated

  • rubocop

  • prettier

  • Revert “rubocop”

This reverts commit 7805145a7dc1dbccd9a4378bec3626a81ebaa659.

  • Revert “prettier”

This reverts commit 2c53f4fa127a00ee9b3c3ab5b1182036089c286b.

  • settings updated and changed

  • rubocop

  • changes applied

  • final changes done

  • Server side feature added

  • spec changed

  • changed user_updater and profile file

  • Fix user card specs

  • web hook serializer solved

  • site-setting changed

Co-authored-by: Mark VanLandingham markvanlan@gmail.com

diff --git a/app/assets/javascripts/discourse/app/controllers/preferences/profile.js b/app/assets/javascripts/discourse/app/controllers/preferences/profile.js
index 88ec0ee..54941de 100644
--- a/app/assets/javascripts/discourse/app/controllers/preferences/profile.js
+++ b/app/assets/javascripts/discourse/app/controllers/preferences/profile.js
@@ -7,11 +7,11 @@ import { popupAjaxError } from "discourse/lib/ajax-error";
 import { cookAsync } from "discourse/lib/text";
 import { ajax } from "discourse/lib/ajax";
 import showModal from "discourse/lib/show-modal";
+import { readOnly } from "@ember/object/computed";
 
 export default Controller.extend({
   init() {
     this._super(...arguments);
-
     this.saveAttrNames = [
       "bio_raw",
       "website",
@@ -44,20 +44,17 @@ export default Controller.extend({
     }
   },
 
-  @discourseComputed("model.can_change_bio")
-  canChangeBio(canChangeBio) {
-    return canChangeBio;
-  },
+  canChangeBio: readOnly("model.can_change_bio"),
 
-  @discourseComputed("model.can_change_location")
-  canChangeLocation(canChangeLocation) {
-    return canChangeLocation;
-  },
+  canChangeLocation: readOnly("model.can_change_location"),
 
-  @discourseComputed("model.can_change_website")
-  canChangeWebsite(canChangeWebsite) {
-    return canChangeWebsite;
-  },
+  canChangeWebsite: readOnly("model.can_change_website"),
+
+  canUploadProfileHeader: readOnly("model.can_upload_profile_header"),
+
+  canUploadUserCardBackground: readOnly(
+    "model.can_upload_user_card_background"
+  ),
 
   actions: {
     showFeaturedTopicModal() {
diff --git a/app/assets/javascripts/discourse/app/templates/preferences/profile.hbs b/app/assets/javascripts/discourse/app/templates/preferences/profile.hbs
index fb3d780..66e2a81 100644
--- a/app/assets/javascripts/discourse/app/templates/preferences/profile.hbs
+++ b/app/assets/javascripts/discourse/app/templates/preferences/profile.hbs
@@ -43,27 +43,30 @@
 <div class="clearfix"></div>
 
 {{#if siteSettings.allow_profile_backgrounds}}
-  <div class="control-group pref-profile-bg">
-    <label class="control-label">{{i18n "user.change_profile_background.title"}}</label>
-    <div class="controls">
-      {{image-uploader imageUrl=model.profile_background_upload_url
-                       type="profile_background"}}
+  {{#if canUploadProfileHeader}}
+    <div class="control-group pref-profile-bg">
+      <label class="control-label">{{i18n "user.change_profile_background.title"}}</label>
+      <div class="controls">
+        {{image-uploader imageUrl=model.profile_background_upload_url
+          type="profile_background"}}
+      </div>
+      <div class="instructions">
+        {{i18n "user.change_profile_background.instructions"}}
+      </div>
     </div>
-    <div class="instructions">
-      {{i18n "user.change_profile_background.instructions"}}
+  {{/if}}
+  {{#if canUploadUserCardBackground}}
+    <div class="control-group pref-profile-bg">
+      <label class="control-label">{{i18n "user.change_card_background.title"}}</label>
+      <div class="controls">
+        {{image-uploader imageUrl=model.card_background_upload_url
+          type="card_background"}}
+      </div>
+      <div class="instructions">
+        {{i18n "user.change_card_background.instructions"}}
+      </div>
     </div>
-  </div>
-
-  <div class="control-group pref-profile-bg">
-    <label class="control-label">{{i18n "user.change_card_background.title"}}</label>
-    <div class="controls">
-      {{image-uploader imageUrl=model.card_background_upload_url
-                       type="card_background"}}
-    </div>
-    <div class="instructions">
-      {{i18n "user.change_card_background.instructions"}}
-    </div>
-  </div>
+  {{/if}}
 {{/if}}
 
 {{#if siteSettings.allow_featured_topic_on_user_profiles}}
@@ -101,4 +104,4 @@
 
 {{plugin-outlet name="user-custom-controls" args=(hash model=model)}}
 
-{{save-controls model=model action=(action "save") saved=saved}}
+{{save-controls model=model action=(action "save") saved=saved}}
\ No newline at end of file
diff --git a/app/serializers/user_serializer.rb b/app/serializers/user_serializer.rb
index f78e9f8..0192d19 100644
--- a/app/serializers/user_serializer.rb
+++ b/app/serializers/user_serializer.rb
@@ -16,7 +16,9 @@ class UserSerializer < UserCardSerializer
              :second_factor_backup_enabled,
              :second_factor_remaining_backup_codes,
              :associated_accounts,
-             :profile_background_upload_url
+             :profile_background_upload_url,
+             :can_upload_profile_header,
+             :can_upload_user_card_background
 
   has_one :invited_by, embed: :object, serializer: BasicUserSerializer
   has_many :groups, embed: :object, serializer: BasicGroupSerializer
@@ -170,6 +172,14 @@ class UserSerializer < UserCardSerializer
     scope.can_edit_name?(object)
   end
 
+  def can_upload_profile_header
+    scope.can_upload_profile_header?(object)
+  end
+
+  def can_upload_user_card_background
+    scope.can_upload_user_card_background?(object)
+  end
+
   ###
   ### STAFF ATTRIBUTES
   ###
diff --git a/app/services/user_updater.rb b/app/services/user_updater.rb
index 8c0149b..50e2e00 100644
--- a/app/services/user_updater.rb
+++ b/app/services/user_updater.rb
@@ -68,13 +68,13 @@ class UserUpdater
       user_profile.website = format_url(attributes.fetch(:website) { user_profile.website })
     end
 
-    if attributes[:profile_background_upload_url] == ""
+    if attributes[:profile_background_upload_url] == "" || !guardian.can_upload_profile_header?(user)
       user_profile.profile_background_upload_id = nil
     elsif upload = Upload.get_from_url(attributes[:profile_background_upload_url])
       user_profile.profile_background_upload_id = upload.id
     end
 
-    if attributes[:card_background_upload_url] == ""
+    if attributes[:card_background_upload_url] == "" || !guardian.can_upload_user_card_background?(user)
       user_profile.card_background_upload_id = nil
     elsif upload = Upload.get_from_url(attributes[:card_background_upload_url])
       user_profile.card_background_upload_id = upload.id
diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml
index ee30f95..e2f69d3 100644
--- a/config/locales/server.en.yml
+++ b/config/locales/server.en.yml
@@ -1804,7 +1804,8 @@ en:
     min_trust_to_flag_posts: "The minimum trust level required to flag posts"
     min_trust_to_post_links: "The minimum trust level required to include links in posts"
     min_trust_to_post_embedded_media: "The minimum trust level required to embed media items in a post"
-
+    min_trust_level_to_allow_profile_background: "The minimum trust level required to upload a profile background"
+    min_trust_level_to_allow_user_card_background: "The minimum trust level required to upload a user card background"
     allowed_link_domains: "Domains that users may link to even if they don't have the appropriate trust level to post links"
 
     newuser_max_links: "How many links a new user can add to a post."
diff --git a/config/site_settings.yml b/config/site_settings.yml
index 4a828f2..17ff664 100644
--- a/config/site_settings.yml
+++ b/config/site_settings.yml
@@ -1354,6 +1354,14 @@ trust:
   min_trust_to_post_embedded_media:
     default: 0
     enum: "TrustLevelSetting"
+  min_trust_level_to_allow_profile_background:
+    default: 0
+    client: true
+    enum: "TrustLevelSetting"
+  min_trust_level_to_allow_user_card_background:
+    default: 0
+    client: true
+    enum: "TrustLevelSetting"
   allow_flagging_staff: true
   send_tl1_welcome_message: true
   tl1_requires_topics_entered: 5
diff --git a/lib/guardian/user_guardian.rb b/lib/guardian/user_guardian.rb
index d19bd2a..aa91779 100644
--- a/lib/guardian/user_guardian.rb
+++ b/lib/guardian/user_guardian.rb
@@ -158,4 +158,13 @@ module UserGuardian
   def can_see_summary_stats?(target_user)
     true
   end
+
+  def can_upload_profile_header?(user)

[... diff too long, it was truncated ...]

GitHub sha: 65649eae

This commit appears in #10302 which was approved by eviltrout. It was merged by eviltrout.