Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FEATURE: add dinopark_enabled? profile flag
shows in admin user details mozilla/discourse#181
- Loading branch information
Showing
7 changed files
with
130 additions
and
1 deletion.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
assets/javascripts/discourse/connectors/admin-user-details/mozilla-iam.js.es6
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,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 | ||
} | ||
} | ||
} | ||
} |
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,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 |
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
23 changes: 23 additions & 0 deletions
23
spec/components/mozilla_iam/profile/dinopark_enabled_spec.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,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
64
test/javascripts/acceptance/user-preferences-account-test.js.es6
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,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") | ||
}) |