FEATURE: add dinopark_enabled? profile flag

shows in admin user details

https://github.com/mozilla/discourse/issues/181
This commit is contained in:
Leo McArdle 2019-03-22 11:41:01 +00:00
Родитель 7b36d1ff86
Коммит b1d67c450d
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 8262833620A64C3F
7 изменённых файлов: 130 добавлений и 1 удалений

Просмотреть файл

@ -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
}
}
}
}

Просмотреть файл

@ -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>

Просмотреть файл

@ -103,3 +103,4 @@ require_relative "profile/update_groups"
require_relative "profile/update_emails"
require_relative "profile/duplicate_accounts"
require_relative "profile/is_aal_enough"
require_relative "profile/dinopark_enabled"

Просмотреть файл

@ -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

Просмотреть файл

@ -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-alpha.1
# authors: Leo McArdle
# url: https://github.com/mozilla/discourse-mozilla-iam

Просмотреть файл

@ -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

Просмотреть файл

@ -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")
})