forked from projectcaluma/ember-emeis
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(user): add acl edit and create views
- Loading branch information
Showing
8 changed files
with
269 additions
and
0 deletions.
There are no files selected for viewing
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,48 @@ | ||
import { inject as service } from "@ember/service"; | ||
import { tracked } from "@glimmer/tracking"; | ||
import { task } from "ember-concurrency-decorators"; | ||
|
||
import PaginationController from "ember-emeis/controllers/pagination"; | ||
import handleModelErrors from "ember-emeis/decorators/handle-model-errors"; | ||
|
||
export default class UsersEditAclController extends PaginationController { | ||
@service intl; | ||
@service notification; | ||
@service store; | ||
|
||
get queryParamsfilter() { | ||
return { user: this.model.id }; | ||
} | ||
|
||
@tracked showAclWizzard = false; | ||
|
||
@task | ||
@handleModelErrors({ errorMessage: "emeis.form.save-error" }) | ||
*createEntry(aclProperties) { | ||
const aclEntry = this.store.createRecord("acl", { ...aclProperties }); | ||
|
||
try { | ||
yield aclEntry.save(); | ||
this.notification.success(this.intl.t("emeis.form.save-success")); | ||
this.showAclWizzard = false; | ||
} catch (exception) { | ||
if ( | ||
exception.isAdapterError && | ||
exception.errors[0].status === "400" && | ||
exception.errors[0].code === "unique" | ||
) { | ||
this.notification.danger(this.intl.t("emeis.acl-wizzard.duplicate")); | ||
} else { | ||
throw exception; | ||
} | ||
} | ||
} | ||
|
||
@task | ||
@handleModelErrors({ errorMessage: "emeis.form.delete-error" }) | ||
*deleteEntry(aclEntry, refreshDataTable) { | ||
yield aclEntry.destroyRecord(); | ||
this.notification.success(this.intl.t("emeis.form.delete-success")); | ||
refreshDataTable(); | ||
} | ||
} |
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,7 @@ | ||
import Route from "@ember/routing/route"; | ||
|
||
export default class UsersEditAclRoute extends Route { | ||
model() { | ||
return this.modelFor("users.edit"); | ||
} | ||
} |
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,63 @@ | ||
{{#if this.showAclWizzard}} | ||
<span class="uk-flex uk-flex-left"> | ||
<UkButton data-test-back {{on "click" (set this.showAclWizzard false)}}> | ||
<UkIcon @icon="arrow-left" @ratio="1.5" /> | ||
{{t "emeis.form.back"}} | ||
</UkButton> | ||
</span> | ||
<AclWizzard @createAclEntry={{perform this.createEntry}} @user={{@model}} /> | ||
{{else}} | ||
<DataTable | ||
@modelName="acl" | ||
@filter={{this.queryParamsfilter}} | ||
@include="user,role,scope" | ||
@page={{this.page}} | ||
@search={{this.search}} | ||
@updatePage={{fn this.updateQueryParam "page"}} | ||
@updateSearch={{fn this.updateQueryParam "search"}} as |table| | ||
> | ||
<table.head> | ||
<th> | ||
{{t "emeis.acl-table.headings.role"}} | ||
</th> | ||
|
||
<th> | ||
{{t "emeis.acl-table.headings.scope"}} | ||
</th> | ||
<th class="uk-table-shrink uk-text-nowrap"> | ||
<UkButton | ||
data-test-add-acl | ||
@color="primary" | ||
{{on "click" (fn (set this.showAclWizzard true))}} | ||
> | ||
{{t "emeis.acl-table.headings.add-entry"}} | ||
</UkButton> | ||
</th> | ||
</table.head> | ||
<table.body as |body|> | ||
<body.row> | ||
{{#with body.model as |aclEntry|}} | ||
<td data-test-acl-role={{aclEntry.id}}> | ||
{{aclEntry.role.name}} | ||
</td> | ||
|
||
<td data-test-acl-scope={{aclEntry.id}}> | ||
{{aclEntry.scope.name}} | ||
</td> | ||
|
||
<td data-test-acl-delete={{aclEntry.id}}> | ||
<span class="uk-flex uk-flex-center"> | ||
<button | ||
type="button" | ||
class="uk-icon-button uk-margin-small-right" | ||
uk-icon="trash" | ||
tooltip="hey there" | ||
{{on "click" (perform this.deleteEntry aclEntry table.refresh)}} | ||
></button> | ||
</span> | ||
</td> | ||
{{/with}} | ||
</body.row> | ||
</table.body> | ||
</DataTable> | ||
{{/if}} |
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 @@ | ||
export { default } from "ember-emeis/controllers/users/edit/acl"; |
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 @@ | ||
export { default } from "ember-emeis/routes/users/edit/acl"; |
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 @@ | ||
export { default } from "ember-emeis/templates/users/edit/acl"; |
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,47 @@ | ||
import { setupMirage } from "ember-cli-mirage/test-support"; | ||
import { setupTest } from "ember-qunit"; | ||
import { module, test } from "qunit"; | ||
|
||
import setupRequestAssertions from "./../../../../helpers/assert-request"; | ||
module("Unit | Controller | users/edit/acl", function (hooks) { | ||
setupTest(hooks); | ||
setupMirage(hooks); | ||
setupRequestAssertions(hooks); | ||
|
||
test("queryParamsfilter", function (assert) { | ||
const controller = this.owner.lookup("controller:users/edit/acl"); | ||
assert.ok(controller); | ||
|
||
controller.model = { id: 1 }; | ||
assert.deepEqual(controller.queryParamsfilter, { "user": 1 }); | ||
}); | ||
|
||
test("createEntry", async function (assert) { | ||
assert.expect(3); | ||
const controller = this.owner.lookup("controller:users/edit/acl"); | ||
assert.ok(controller); | ||
|
||
this.assertRequest("POST", "/api/v1/acls", (request) => { | ||
const relationships = JSON.parse(request.requestBody).data.relationships; | ||
assert.ok(relationships.role); | ||
assert.ok(relationships.scope); | ||
}); | ||
await controller.createEntry.perform({ role: 1, scope: 2 }); | ||
}); | ||
|
||
test("createEntry", async function (assert) { | ||
assert.expect(3); | ||
const controller = this.owner.lookup("controller:users/edit/acl"); | ||
assert.ok(controller); | ||
const refresh = () => { | ||
assert.ok(true); | ||
}; | ||
const model = { | ||
destroyRecord() { | ||
assert.ok(true); | ||
}, | ||
}; | ||
|
||
await controller.deleteEntry.perform(model, refresh); | ||
}); | ||
}); |