Skip to content

Commit

Permalink
Refactors dashboard state resolve to return true on failed query
Browse files Browse the repository at this point in the history
If anything other than a truthy value is returned, ui-router's resolve flips out and throws a state change error.  SUI has state change errors written to then flipout and kick users outta da app.

So when the rbac doesn't match, the query wont be made, the 403 won't ever prevent the state from resolving.

Long term fix, this needs to be rewritten sans resolve
  • Loading branch information
AllenBW committed Jan 25, 2018
1 parent 8bc4411 commit 1fd17c0
Showing 1 changed file with 23 additions and 22 deletions.
45 changes: 23 additions & 22 deletions client/app/states/dashboard/dashboard.state.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function getStates () {

function resolveAllRequests (CollectionsApi, RBAC) {
if (!RBAC.has('miq_request_view')) {
return undefined
return true
}

return [
Expand Down Expand Up @@ -94,41 +94,42 @@ function deniedRequestsForServiceReconfigureRequest (CollectionsApi) {

/** @ngInject */
function resolveExpiringServices (CollectionsApi, RBAC) {
if (!RBAC.has(RBAC.FEATURES.SERVICES.VIEW)) {
return undefined
if (RBAC.has('service_view') && RBAC.has(RBAC.FEATURES.SERVICES.VIEW)) {
const currentDate = new Date()
const date1 = 'retires_on>' + currentDate.toISOString()
const days30 = currentDate.setDate(currentDate.getDate() + 30)
const date2 = 'retires_on<' + new Date(days30).toISOString()
const options = {hide: 'resources', filter: ['retired=false', date1, date2]}

return CollectionsApi.query('services', options)
}
var currentDate = new Date()
var date1 = 'retires_on>' + currentDate.toISOString()
var days30 = currentDate.setDate(currentDate.getDate() + 30)
var date2 = 'retires_on<' + new Date(days30).toISOString()
var options = {hide: 'resources', filter: ['retired=false', date1, date2]}

return CollectionsApi.query('services', options)
return true
}

/** @ngInject */
function resolveRetiredServices (CollectionsApi, RBAC) {
if (!RBAC.has(RBAC.FEATURES.SERVICES.VIEW)) {
return undefined
}
var options = {hide: 'resources', filter: ['service_id=nil', 'retired=true']}
if (RBAC.has('service_view') && RBAC.has(RBAC.FEATURES.SERVICES.VIEW)) {
const options = {hide: 'resources', filter: ['service_id=nil', 'retired=true']}

return CollectionsApi.query('services', options)
return CollectionsApi.query('services', options)
}
return true
}

/** @ngInject */
function resolveServicesWithDefinedServiceIds (CollectionsApi, RBAC) {
if (!RBAC.has(RBAC.FEATURES.SERVICES.VIEW)) {
return undefined
}
if (RBAC.has('service_view') && RBAC.has(RBAC.FEATURES.SERVICES.VIEW)) {
const options = {
expand: 'resources',
filter: ['service_id=nil'],
attributes: ['chargeback_report']
}

var options = {
expand: 'resources',
filter: ['service_id=nil'],
attributes: ['chargeback_report']
return CollectionsApi.query('services', options)
}

return CollectionsApi.query('services', options)
return true
}

/** @ngInject */
Expand Down

0 comments on commit 1fd17c0

Please sign in to comment.