Skip to content

Commit

Permalink
FEATURE: allow users to edit avatars if dinopark avatars are disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
LeoMcA committed Jun 5, 2019
1 parent cf00a5e commit 1ce2c35
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 13 deletions.
Expand Up @@ -2,14 +2,12 @@
<style>
.pref-username,
.pref-name,
.pref-avatar,
.pref-title {
display: none;
}
.pref-dinopark-username,
.pref-dinopark-name,
.pref-dinopark-avatar,
.pref-dinopark-title {
display: block;
}
Expand Down Expand Up @@ -38,15 +36,27 @@
</div>
</div>

<div class="control-group pref-avatar pref-dinopark-avatar">
<label class="control-label" id="profile-picture">
{{i18n 'user.avatar.title'}}
{{dinopark-edit}}
</label>
<div class="controls">
{{bound-avatar model "huge"}}
{{#if siteSettings.dinopark_avatars_enabled}}
<style>
.pref-avatar {
display: none;
}
.pref-dinopark-avatar {
display: block;
}
</style>

<div class="control-group pref-avatar pref-dinopark-avatar">
<label class="control-label" id="profile-picture">
{{i18n 'user.avatar.title'}}
{{dinopark-edit}}
</label>
<div class="controls">
{{bound-avatar model "huge"}}
</div>
</div>
</div>
{{/if}}

<div class="control-group pref-title pref-dinopark-title">
<label class="control-label">
Expand Down
1 change: 1 addition & 0 deletions config/settings.yml
Expand Up @@ -27,6 +27,7 @@ mozilla_iam:
client: true
dinopark_avatars_enabled:
default: true
client: true
dinopark_authorized_groups:
default: "mozilliansorg_dinopark-preview-access"
type: list
Expand Down
2 changes: 1 addition & 1 deletion lib/mozilla_iam/users_controller_extensions.rb
Expand Up @@ -37,7 +37,7 @@ def username
end

def pick_avatar
if Profile.for(fetch_user_from_params)&.dinopark_enabled?
if SiteSetting.dinopark_avatars_enabled && Profile.for(fetch_user_from_params)&.dinopark_enabled?
render_json_error(I18n.t("dinopark.update_avatar"))
else
super
Expand Down
2 changes: 1 addition & 1 deletion plugin.rb
@@ -1,6 +1,6 @@
# name: mozilla-iam
# about: A plugin to integrate Discourse with Mozilla's Identity and Access Management (IAM) system
# version: 1.2.0-alpha.27
# version: 1.2.0-alpha.28
# authors: Leo McArdle
# url: https://github.com/mozilla/discourse-mozilla-iam

Expand Down
14 changes: 13 additions & 1 deletion spec/requests/users_controller_spec.rb
Expand Up @@ -84,7 +84,7 @@
describe '#pick_avatar' do
let(:upload) { Fabricate(:upload, user: user) }

context "without dinopark_enabled" do
shared_examples "allows update to avatar" do
it "allows update to avatar" do
put "/u/#{user.username}/preferences/avatar/pick.json", params: {
upload_id: upload.id, type: "custom"
Expand All @@ -95,6 +95,10 @@
end
end

context "without dinopark_enabled" do
include_examples "allows update to avatar"
end

context "with dinopark_enabled" do
before do
profile.dinopark_enabled = true
Expand All @@ -108,6 +112,14 @@
expect(response.status).to eq(422)
expect(user.reload.uploaded_avatar_id).to_not eq(upload.id)
end

context "with dinopark avatars disabled" do
before do
SiteSetting.dinopark_avatars_enabled = false
end

include_examples "allows update to avatar"
end
end
end

Expand Down

0 comments on commit 1ce2c35

Please sign in to comment.