-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ui: Integrate new roles and policies
- Loading branch information
John Cowen
committed
Aug 23, 2019
1 parent
a6ade42
commit 2200072
Showing
10 changed files
with
149 additions
and
179 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 |
---|---|---|
@@ -1,72 +1,39 @@ | ||
import Adapter, { | ||
REQUEST_CREATE, | ||
REQUEST_UPDATE, | ||
DATACENTER_QUERY_PARAM as API_DATACENTER_KEY, | ||
} from './application'; | ||
import Adapter, { DATACENTER_QUERY_PARAM as API_DATACENTER_KEY } from './application'; | ||
|
||
import { PRIMARY_KEY, SLUG_KEY } from 'consul-ui/models/role'; | ||
import { SLUG_KEY } from 'consul-ui/models/role'; | ||
import { FOREIGN_KEY as DATACENTER_KEY } from 'consul-ui/models/dc'; | ||
import { OK as HTTP_OK } from 'consul-ui/utils/http/status'; | ||
import { PUT as HTTP_PUT } from 'consul-ui/utils/http/method'; | ||
|
||
import WithPolicies from 'consul-ui/mixins/policy/as-many'; | ||
export default Adapter.extend({ | ||
requestForQuery: function(request, { dc, index, id }) { | ||
return request` | ||
GET /v1/acl/roles?${{ dc }} | ||
export default Adapter.extend(WithPolicies, { | ||
urlForQuery: function(query, modelName) { | ||
return this.appendURL('acl/roles', [], this.cleanQuery(query)); | ||
${{ index }} | ||
`; | ||
}, | ||
urlForQueryRecord: function(query, modelName) { | ||
if (typeof query.id === 'undefined') { | ||
requestForQueryRecord: function(request, { dc, index, id }) { | ||
if (typeof id === 'undefined') { | ||
throw new Error('You must specify an id'); | ||
} | ||
return this.appendURL('acl/role', [query.id], this.cleanQuery(query)); | ||
}, | ||
urlForCreateRecord: function(modelName, snapshot) { | ||
return this.appendURL('acl/role', [], { | ||
[API_DATACENTER_KEY]: snapshot.attr(DATACENTER_KEY), | ||
}); | ||
}, | ||
urlForUpdateRecord: function(id, modelName, snapshot) { | ||
return this.appendURL('acl/role', [snapshot.attr(SLUG_KEY)], { | ||
[API_DATACENTER_KEY]: snapshot.attr(DATACENTER_KEY), | ||
}); | ||
}, | ||
urlForDeleteRecord: function(id, modelName, snapshot) { | ||
return this.appendURL('acl/role', [snapshot.attr(SLUG_KEY)], { | ||
[API_DATACENTER_KEY]: snapshot.attr(DATACENTER_KEY), | ||
}); | ||
}, | ||
handleResponse: function(status, headers, payload, requestData) { | ||
let response = payload; | ||
if (status === HTTP_OK) { | ||
const url = this.parseURL(requestData.url); | ||
switch (true) { | ||
case response === true: | ||
response = this.handleBooleanResponse(url, response, PRIMARY_KEY, SLUG_KEY); | ||
break; | ||
case Array.isArray(response): | ||
response = this.handleBatchResponse(url, response, PRIMARY_KEY, SLUG_KEY); | ||
break; | ||
default: | ||
response = this.handleSingleResponse(url, response, PRIMARY_KEY, SLUG_KEY); | ||
} | ||
} | ||
return this._super(status, headers, response, requestData); | ||
}, | ||
methodForRequest: function(params) { | ||
switch (params.requestType) { | ||
case REQUEST_CREATE: | ||
return HTTP_PUT; | ||
} | ||
return this._super(...arguments); | ||
}, | ||
dataForRequest: function(params) { | ||
const data = this._super(...arguments); | ||
switch (params.requestType) { | ||
case REQUEST_UPDATE: | ||
case REQUEST_CREATE: | ||
return data.role; | ||
} | ||
return data; | ||
return request` | ||
GET /v1/acl/role/${id}?${{ dc }} | ||
${{ index }} | ||
`; | ||
}, | ||
requestForCreateRecord: function(request, data) { | ||
return request` | ||
PUT /v1/acl/role?${{ [API_DATACENTER_KEY]: data[DATACENTER_KEY] }} | ||
`; | ||
}, | ||
requestForUpdateRecord: function(request, data) { | ||
return request` | ||
PUT /v1/acl/role/${data[SLUG_KEY]}?${{ [API_DATACENTER_KEY]: data[DATACENTER_KEY] }} | ||
`; | ||
}, | ||
requestForDeleteRecord: function(request, data) { | ||
return request` | ||
DELETE /v1/acl/role/${data[SLUG_KEY]}?${{ [API_DATACENTER_KEY]: data[DATACENTER_KEY] }} | ||
`; | ||
}, | ||
}); |
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
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 |
---|---|---|
@@ -1,28 +1,33 @@ | ||
import { REQUEST_CREATE, REQUEST_UPDATE } from 'consul-ui/adapters/application'; | ||
|
||
import Mixin from '@ember/object/mixin'; | ||
|
||
import minimizeModel from 'consul-ui/utils/minimizeModel'; | ||
|
||
export default Mixin.create({ | ||
handleSingleResponse: function(url, response, primary, slug) { | ||
['Roles'].forEach(function(prop) { | ||
if (typeof response[prop] === 'undefined' || response[prop] === null) { | ||
response[prop] = []; | ||
} | ||
}); | ||
return this._super(url, response, primary, slug); | ||
// TODO: what about update and create? | ||
respondForQueryRecord: function(respond, query) { | ||
return this._super(function(cb) { | ||
return respond((headers, body) => { | ||
body.Roles = typeof body.Roles === 'undefined' || body.Roles === null ? [] : body.Roles; | ||
return cb(headers, body); | ||
}); | ||
}, query); | ||
}, | ||
respondForQuery: function(respond, query) { | ||
return this._super(function(cb) { | ||
return respond(function(headers, body) { | ||
return cb( | ||
headers, | ||
body.map(function(item) { | ||
item.Roles = typeof item.Roles === 'undefined' || item.Roles === null ? [] : item.Roles; | ||
return item; | ||
}) | ||
); | ||
}); | ||
}, query); | ||
}, | ||
dataForRequest: function(params) { | ||
const name = params.type.modelName; | ||
serialize: function(snapshot, options) { | ||
const data = this._super(...arguments); | ||
switch (params.requestType) { | ||
case REQUEST_UPDATE: | ||
// falls through | ||
case REQUEST_CREATE: | ||
data[name].Roles = minimizeModel(data[name].Roles); | ||
break; | ||
} | ||
data.Roles = minimizeModel(data.Roles); | ||
return data; | ||
}, | ||
}); |
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 |
---|---|---|
@@ -1,5 +1,7 @@ | ||
import Serializer from './application'; | ||
import { PRIMARY_KEY } from 'consul-ui/models/role'; | ||
export default Serializer.extend({ | ||
import { PRIMARY_KEY, SLUG_KEY } from 'consul-ui/models/role'; | ||
import WithPolicies from 'consul-ui/mixins/policy/as-many'; | ||
export default Serializer.extend(WithPolicies, { | ||
primaryKey: PRIMARY_KEY, | ||
slugKey: SLUG_KEY, | ||
}); |
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
Oops, something went wrong.