Skip to content

Commit

Permalink
Models and adapters
Browse files Browse the repository at this point in the history
  • Loading branch information
philrenaud committed Jun 29, 2023
1 parent 3dd6977 commit 4c33fd6
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
11 changes: 11 additions & 0 deletions ui/app/adapters/role.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/

// @ts-check
import { default as ApplicationAdapter, namespace } from './application';

export default class RoleAdapter extends ApplicationAdapter {
namespace = namespace + '/acl';
}
14 changes: 14 additions & 0 deletions ui/app/models/role.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/

// @ts-check
import Model from '@ember-data/model';
import { attr, hasMany } from '@ember-data/model';

export default class Role extends Model {
@attr('string') name;
@attr('string') description;
@hasMany('policy', { defaultValue: () => [] }) policies;
}
1 change: 1 addition & 0 deletions ui/app/models/token.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export default class Token extends Model {
@attr('date') createTime;
@attr('string') type;
@hasMany('policy') policies;
@hasMany('role') roles;
@attr() policyNames;
@attr('date') expirationTime;

Expand Down
2 changes: 2 additions & 0 deletions ui/app/serializers/token.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ export default class TokenSerializer extends ApplicationSerializer {
normalize(typeHash, hash) {
hash.PolicyIDs = hash.Policies;
hash.PolicyNames = copy(hash.Policies);
hash.Roles = hash.Roles || [];
hash.RoleIDs = hash.Roles.map((role) => role.ID);
return super.normalize(typeHash, hash);
}
}

0 comments on commit 4c33fd6

Please sign in to comment.