@@ -13,11 +13,11 @@ import { getAuthenticatedParty, httpActions, signIn as signIn$1, signOut as sign
1313import { pluralize , singularize } from 'inflection' ;
1414import upperFirst from 'lodash/upperFirst' ;
1515import camelCase from 'lodash/camelCase' ;
16+ import map from 'lodash/map' ;
1617import cloneDeep from 'lodash/cloneDeep' ;
1718import isEmpty from 'lodash/isEmpty' ;
1819import lowerFirst from 'lodash/lowerFirst' ;
1920import pick from 'lodash/pick' ;
20- import { isFunction as isFunction$1 } from 'lodash' ;
2121
2222/**
2323 * @function
@@ -139,6 +139,20 @@ function normalizeError(error) {
139139
140140 return normalizedError ;
141141}
142+ /**
143+ * @function
144+ * @name getPartyPermissionsWildcards
145+ * @description Extract wildcards from party permissions
146+ * @param {object } party Authenticated party
147+ * @returns {string[] } Wildcards extracted from permissions
148+ * @version 0.1.0
149+ * @since 0.30.0
150+ */
151+
152+ function getPartyPermissionsWildcards ( party ) {
153+ const permissions = get ( party , 'role.relations.permissions' , [ ] ) ;
154+ return map ( permissions , 'wildcard' ) ;
155+ }
142156
143157/**
144158 * @function
@@ -371,7 +385,8 @@ const appDefaultState = {
371385 loading : false ,
372386 signing : false ,
373387 error : null ,
374- party : getAuthenticatedParty ( )
388+ party : getAuthenticatedParty ( ) ,
389+ permissions : getPartyPermissionsWildcards ( getAuthenticatedParty ( ) )
375390} ;
376391/**
377392 * @function
@@ -420,7 +435,7 @@ function createReportsSlices(reports) {
420435 * @param {object } action dispatched action object
421436 * @returns {object } updated app state
422437 *
423- * @version 0.1 .0
438+ * @version 0.2 .0
424439 * @since 0.1.0
425440 */
426441
@@ -449,7 +464,8 @@ function app(state = appDefaultState, action) {
449464
450465 case SIGNIN_APP_SUCCESS :
451466 return { ...state ,
452- party : action . payload ,
467+ party : action . payload . party ,
468+ permissions : action . payload . permissions ,
453469 signing : false
454470 } ;
455471
@@ -472,16 +488,19 @@ function app(state = appDefaultState, action) {
472488
473489const resources = [ 'administrativeArea' , 'administrativeLevel' , 'agency' , 'campaign' , 'changelog' , 'dispatch' , 'event' , 'eventAction' , 'eventActionCatalogue' , 'eventFunction' , 'eventGroup' , 'eventIndicator' , 'eventLevel' , 'eventSeverity' , 'eventCertainty' , 'eventStatus' , 'eventUrgency' , 'eventResponse' , 'eventQuestion' , 'eventTopic' , 'eventType' , 'feature' , 'featureType' , 'focalPerson' , 'notificationTemplate' , 'partyGender' , 'partyGroup' , 'partyOwnership' , 'partyRole' , 'partyOccupation' , 'partyNationality' , 'permission' , 'priority' , 'unit' , 'vehicle' , 'vehicleModel' , 'vehicleMake' , 'vehicleStatus' , 'vehicleType' , 'case' , 'caseStage' , 'caseSeverity' ] ; // Exposed reports by the API
474490
475- const REPORTS = [ 'action' , 'alert' , 'case' , 'dispatch' , 'effect' , 'event' , 'indicator' , 'need' , 'overview' , 'party' , 'resource' , 'risk' ] ;
476- const slices = createResourcesSlices ( resources ) ;
477- const reportSlices = createReportsSlices ( REPORTS ) ;
491+ const REPORTS = [ 'action' , 'alert' , 'case' , 'dispatch' , 'effect' , 'event' , 'indicator' , 'need' , 'overview' , 'party' , 'resource' , 'risk' ] ; // create crud resources slices
492+
493+ const slices = createResourcesSlices ( resources ) ; // create reports slices
494+
495+ const reportSlices = createReportsSlices ( REPORTS ) ; // merge reducers
496+
478497const reducers = merge ( { } , extractReducers ( resources , slices ) , extractReportReducers ( REPORTS , reportSlices ) , {
479498 app
480499} ) ;
481500const rootReducer = combineReducers ( reducers ) ;
482501const store = configureStore ( {
483502 reducer : rootReducer ,
484- devTools : true
503+ devTools : process . env . NODE_ENV === 'development'
485504} ) ;
486505const actions = { ...extractActions ( resources , slices ) ,
487506 ...extractActions ( REPORTS , reportSlices , true )
@@ -1152,13 +1171,10 @@ function initializeAppFailure(error) {
11521171 } ;
11531172}
11541173/**
1155- * Action dispatched when user start to signIng into the system
1156- *
11571174 * @function
11581175 * @name signInStart
1159- *
1176+ * @description Action dispatched when user start to signIng into the system
11601177 * @returns {object } redux action
1161- *
11621178 * @version 0.1.0
11631179 * @since 0.10.3
11641180 */
@@ -1169,30 +1185,29 @@ function signInStart() {
11691185 } ;
11701186}
11711187/**
1172- * Action dispatched when user successfully signed In into the system
1173- *
11741188 * @function
11751189 * @name signInSuccess
1176- *
1177- * @param {object } party signed In user/party
1190+ * @description Action dispatched when user successfully signed In
1191+ * into the system
1192+ * @param {object } data signed In user/party and extracted
1193+ * permissions wildcards
11781194 * @returns {object } redux action
1179- *
1180- * @version 0.1.0
1195+ * @version 0.2.0
11811196 * @since 0.10.3
11821197 */
11831198
1184- function signInSuccess ( party ) {
1199+ function signInSuccess ( data ) {
11851200 return {
11861201 type : SIGNIN_APP_SUCCESS ,
1187- payload : party
1202+ payload : data
11881203 } ;
11891204}
11901205/**
1191- * Action dispatched when user signing In fails
1192- *
1206+ * @function
1207+ * @name signInFailure
1208+ * @description Action dispatched when user signing In fails
11931209 * @param {object } error Error instance
11941210 * @returns {object } redux action
1195- *
11961211 * @version 0.1.0
11971212 * @since 0.10.3
11981213 */
@@ -1204,13 +1219,10 @@ function signInFailure(error) {
12041219 } ;
12051220}
12061221/**
1207- * Action dispatched when user signOut
1208- *
12091222 * @function
12101223 * @name signOut
1211- *
1224+ * @description Action dispatched when user signOut
12121225 * @returns {object } Redux action
1213- *
12141226 * @version 0.1.0
12151227 * @since 0.10.3
12161228 */
@@ -1221,14 +1233,11 @@ function signOut() {
12211233 } ;
12221234}
12231235/**
1224- * Action dispatched when application is started. It will load up all schema
1225- * need for in the application
1226- *
12271236 * @function
12281237 * @name initializeApp
1229- *
1230- * @returns { Function } thunk function
1231- *
1238+ * @description Action dispatched when application is started.
1239+ * It will load up all schema need for in the application
1240+ * @returns { Promise } thunk function
12321241 * @version 0.1.0
12331242 * @since 0.1.0
12341243 */
@@ -1290,17 +1299,15 @@ function initializeApp() {
12901299 } ;
12911300}
12921301/**
1293- * Thunk action to signIn user/party
12941302 *
12951303 * @function
12961304 * @name signIn
1297- *
1298- * @param {object } credentials - Email and password
1299- * @param {Function } onSuccess - Callback for successfully signIn
1300- * @param {Function } onError - Callback for failed signIn
1305+ * @description Thunk action to signIn user/party
1306+ * @param {object } credentials Email and password
1307+ * @param {Function } onSuccess Callback for successfully signIn
1308+ * @param {Function } onError Callback for failed signIn
13011309 * @returns {Promise } redux thunk
1302- *
1303- * @version 0.1.0
1310+ * @version 0.2.0
13041311 * @since 0.10.3
13051312 */
13061313
@@ -1311,27 +1318,30 @@ function signIn(credentials, onSuccess, onError) {
13111318 const {
13121319 party
13131320 } = results ;
1314- dispatch ( signInSuccess ( party ) ) ;
1321+ const permissions = getPartyPermissionsWildcards ( party ) ;
1322+ dispatch ( signInSuccess ( {
1323+ party,
1324+ permissions
1325+ } ) ) ;
13151326
1316- if ( isFunction$1 ( onSuccess ) ) {
1327+ if ( isFunction ( onSuccess ) ) {
13171328 onSuccess ( party ) ;
13181329 }
13191330 } ) . catch ( error => {
13201331 dispatch ( signInFailure ( error ) ) ;
13211332
1322- if ( isFunction$1 ( onError ) ) {
1333+ if ( isFunction ( onError ) ) {
13231334 onError ( error ) ;
13241335 }
13251336 } ) ;
13261337 } ;
13271338}
13281339/**
1329- * Wrapped initialize app thunk
13301340 *
13311341 * @function
13321342 * @name wrappedInitializeApp
1343+ * @description Wrapped initialize app thunk
13331344 * @returns {Promise } - dispatched initialize app thunk
1334- *
13351345 * @version 0.1.0
13361346 * @since 0.3.2
13371347 */
@@ -1340,16 +1350,13 @@ function wrappedInitializeApp() {
13401350 return dispatch ( initializeApp ( ) ) ;
13411351}
13421352/**
1343- * Wrapped signIng thunk
1344- *
13451353 * @function
13461354 * @name wrappedSignIn
1347- *
1348- * @param {object } credentials - email and password provided by user
1349- * @param {Function } onSuccess - Callback for successfully signIn
1350- * @param {Function } onError - Callback for failed signIn
1351- * @returns {Promise } - dispatched signIng thunk
1352- *
1355+ * @description Wrapped signIng thunk
1356+ * @param {object } credentials email and password provided by user
1357+ * @param {Function } onSuccess Callback for successfully signIn
1358+ * @param {Function } onError Callback for failed signIn
1359+ * @returns {Promise } dispatched signIng thunk
13531360 * @version 0.1.0
13541361 * @since 0.10.3
13551362 */
@@ -1358,13 +1365,10 @@ function wrappedSignIn(credentials, onSuccess, onError) {
13581365 return dispatch ( signIn ( credentials , onSuccess , onError ) ) ;
13591366}
13601367/**
1361- * Wrapped signOut action
1362- *
13631368 * @function
13641369 * @name wrappedSignOut
1365- *
1370+ * @description Wrapped signOut action
13661371 * @returns {undefined }
1367- *
13681372 * @version 0.2.0
13691373 * @since 0.10.3
13701374 */
0 commit comments