Skip to content

Commit

Permalink
FEATURE: add dinopark_enabled? profile flag
Browse files Browse the repository at this point in the history
shows in admin user details

mozilla/discourse#181
  • Loading branch information
LeoMcA committed Mar 22, 2019
1 parent 7b36d1f commit 5003b80
Show file tree
Hide file tree
Showing 7 changed files with 130 additions and 1 deletion.
@@ -0,0 +1,13 @@
export default {
setupComponent(args, component) {
var custom_fields = args.model.mozilla_iam
if (custom_fields) {
var dinopark_enabled = custom_fields.dinopark_enabled
if (dinopark_enabled === true || dinopark_enabled === "t") {
args.model.mozilla_iam.dinopark_enabled = true
} else {
args.model.mozilla_iam.dinopark_enabled = false
}
}
}
}
Expand Up @@ -43,4 +43,16 @@
</div>
</div>

<div class='display-row dinopark-enabled'>
<div class='field'>Linked to DinoPark?</div>

<div class='value'>
{{#if model.mozilla_iam.dinopark_enabled}}
True
{{else}}
False
{{/if}}
</div>
</div>

</section>
1 change: 1 addition & 0 deletions lib/mozilla_iam/profile.rb
Expand Up @@ -103,3 +103,4 @@ def set(key, value)
require_relative "profile/update_emails"
require_relative "profile/duplicate_accounts"
require_relative "profile/is_aal_enough"
require_relative "profile/dinopark_enabled"
16 changes: 16 additions & 0 deletions lib/mozilla_iam/profile/dinopark_enabled.rb
@@ -0,0 +1,16 @@
module MozillaIAM
Profile.class_eval do
def dinopark_enabled?
if get("dinopark_enabled") === "t" ||
get("dinopark_enabled") === true
return true
else
return false
end
end

def dinopark_enabled=(enabled)
set("dinopark_enabled", enabled)
end
end
end
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.1.2
# version: 1.2.0
# authors: Leo McArdle
# url: https://github.com/mozilla/discourse-mozilla-iam

Expand Down
23 changes: 23 additions & 0 deletions spec/components/mozilla_iam/profile/dinopark_enabled_spec.rb
@@ -0,0 +1,23 @@
require_relative '../../../iam_helper'

describe MozillaIAM::Profile do
describe "#dinopark_enabled" do
let(:user) { Fabricate(:user) }
let(:profile) { MozillaIAM::Profile.new(user, "uid") }

it "defaults to false" do
expect(profile.dinopark_enabled?).to eq false
end

it "can be set to true" do
profile.dinopark_enabled = true
expect(profile.dinopark_enabled?).to eq true
end

it "returns false if set to anything but true" do
profile.dinopark_enabled = "blah"
expect(profile.dinopark_enabled?).to eq false
end

end
end
64 changes: 64 additions & 0 deletions test/javascripts/acceptance/user-preferences-account-test.js.es6
@@ -0,0 +1,64 @@
import { acceptance } from "helpers/qunit-helpers"

acceptance("Mozilla IAM - Admin User Details", {
loggedIn: true
})

const response = (server, mozilla_iam) => {
server.get("/admin/users/1.json", () => [
200,
{ "Content-Type": "application/json" },
{
id: 1,
username: "eviltrout",
email: "eviltrout@example.com",
mozilla_iam
}
])
}

const assert_dinopark = (assert, value) => {
assert.equal(
find(".mozilla-iam.admin-user-details-outlet .dinopark-enabled .value").text().trim(),
value,
`dinopark enabled should show ${value}`
)
}

QUnit.test("viewing profile with dinopark_enabled undefined", async assert => {
response(server, {})

await visit("/admin/users/1/eviltrout")

assert_dinopark(assert, "False")
})

QUnit.test("viewing profile with dinopark_enabled set to anything but true", async assert => {
response(server, {
dinopark_enabled: "foo"
})

await visit("/admin/users/1/eviltrout")

assert_dinopark(assert, "False")
})

QUnit.test("viewing profile with dinopark_enabled set to true", async assert => {
response(server, {
dinopark_enabled: true
})

await visit("/admin/users/1/eviltrout")

assert_dinopark(assert, "True")
})

QUnit.test("viewing profile with dinopark_enabled set to 't'", async assert => {
response(server, {
dinopark_enabled: "t"
})

await visit("/admin/users/1/eviltrout")

assert_dinopark(assert, "True")
})

0 comments on commit 5003b80

Please sign in to comment.