@@ -264,96 +264,124 @@ protected[core] abstract class EntitlementProvider(
264
264
}
265
265
.getOrElse(Future .successful(()))
266
266
} else if (operation == " update" ) {
267
- get(entityStore, entityName.toDocId, DocRevision .empty, true ).flatMap { whiskAction =>
268
- val currentPermissions = whiskAction.annotations
269
- .get(WhiskAction .permissionsFieldName)
270
- .map(value => value.convertTo[String ])
271
- .getOrElse(WhiskAction .defaultPermissions)
272
-
273
- val errorInfo = s " have no permission to ${operation} this action "
274
- permissions match {
275
- case Some (value) =>
276
- if (! WhiskAction .permissionList.contains(value)) {
277
- val errorInfo =
278
- s " give error permission code: ${value}, available permission is in ${WhiskAction .permissionList}"
279
- Future .failed(RejectRequest (Forbidden , Some (ErrorResponse (errorInfo, transid))))
280
- } else {
281
- val passedUpdatePermission = value.charAt(1 )
282
- if (passedUpdatePermission == 'w' ) { // make it to modifiable
283
- Future .successful(())
267
+ get(entityStore, entityName.toDocId, DocRevision .empty, true )
268
+ .flatMap { whiskAction =>
269
+ val currentPermissions = whiskAction.annotations
270
+ .get(WhiskAction .permissionsFieldName)
271
+ .map(value => value.convertTo[String ])
272
+ .getOrElse(WhiskAction .defaultPermissions)
273
+
274
+ val errorInfo = s " have no permission to ${operation} this action "
275
+ permissions match {
276
+ case Some (value) =>
277
+ if (! WhiskAction .permissionList.contains(value)) {
278
+ val errorInfo =
279
+ s " give error permission code: ${value}, available permission is in ${WhiskAction .permissionList}"
280
+ Future .failed(RejectRequest (Forbidden , Some (ErrorResponse (errorInfo, transid))))
284
281
} else {
285
- val currentUpdatePermission = currentPermissions.charAt(1 )
286
- if (currentUpdatePermission == '-' ) {
287
- Future .failed(RejectRequest (Forbidden , Some (ErrorResponse (errorInfo, transid))))
288
- } else {
282
+ val passedUpdatePermission = value.charAt(1 )
283
+ if (passedUpdatePermission == 'w' ) { // make it to modifiable
289
284
Future .successful(())
285
+ } else {
286
+ val currentUpdatePermission = currentPermissions.charAt(1 )
287
+ if (currentUpdatePermission == '-' ) {
288
+ Future .failed(RejectRequest (Forbidden , Some (ErrorResponse (errorInfo, transid))))
289
+ } else {
290
+ Future .successful(())
291
+ }
290
292
}
291
293
}
292
- }
293
- case None =>
294
- val currentUpdatePermission = currentPermissions.charAt(1 )
295
- if (currentUpdatePermission == '-' ) {
296
- Future .failed(RejectRequest (Forbidden , Some (ErrorResponse (errorInfo, transid))))
297
- } else {
298
- Future .successful(())
299
- }
294
+ case None =>
295
+ val currentUpdatePermission = currentPermissions.charAt(1 )
296
+ if (currentUpdatePermission == '-' ) {
297
+ Future .failed(RejectRequest (Forbidden , Some (ErrorResponse (errorInfo, transid))))
298
+ } else {
299
+ Future .successful(())
300
+ }
301
+ }
302
+ }
303
+ .recoverWith {
304
+ case t : RejectRequest =>
305
+ Future .failed(t)
306
+ case _ =>
307
+ Future .successful(())
300
308
}
301
- }
302
309
} else if (operation == " remove" ) {
303
- get(entityStore, entityName.toDocId, DocRevision .empty, true ).flatMap { whiskAction =>
304
- val currentPermissions = whiskAction.annotations
305
- .get(WhiskAction .permissionsFieldName)
306
- .map(value => value.convertTo[String ])
307
- .getOrElse(WhiskAction .defaultPermissions)
308
-
309
- val currentUpdatePermission = currentPermissions.charAt(1 )
310
- if (currentUpdatePermission == '-' ) {
311
- val errorInfo = s " have no permission to ${operation} this action "
312
- Future .failed(RejectRequest (Forbidden , Some (ErrorResponse (errorInfo, transid))))
313
- } else {
314
- Future .successful(())
310
+ get(entityStore, entityName.toDocId, DocRevision .empty, true )
311
+ .flatMap { whiskAction =>
312
+ val currentPermissions = whiskAction.annotations
313
+ .get(WhiskAction .permissionsFieldName)
314
+ .map(value => value.convertTo[String ])
315
+ .getOrElse(WhiskAction .defaultPermissions)
316
+
317
+ val currentUpdatePermission = currentPermissions.charAt(1 )
318
+ if (currentUpdatePermission == '-' ) {
319
+ val errorInfo = s " have no permission to ${operation} this action "
320
+ Future .failed(RejectRequest (Forbidden , Some (ErrorResponse (errorInfo, transid))))
321
+ } else {
322
+ Future .successful(())
323
+ }
324
+ }
325
+ .recoverWith {
326
+ case t : RejectRequest =>
327
+ Future .failed(t)
328
+ case _ =>
329
+ Future .successful(())
315
330
}
316
- }
317
331
} else if (operation == " invoke" ) {
318
- get(entityStore, entityName.toDocId, DocRevision .empty, true ).flatMap { whiskAction =>
319
- val currentPermissions = whiskAction.annotations
320
- .get(WhiskAction .permissionsFieldName)
321
- .map(value => value.convertTo[String ])
322
- .getOrElse(WhiskAction .defaultPermissions)
323
-
324
- // the user who is owner by default
325
- var currentExecutePermission = currentPermissions.charAt(2 )
326
- var errorInfo = s " have no permission to ${operation} this action "
327
- if (user.namespace.name.asString != entityName.path.root.asString) { // the user who invoke the shared action
328
- currentExecutePermission = currentPermissions.charAt(5 )
329
- errorInfo = s " have no permission to ${operation} this shared action "
332
+ get(entityStore, entityName.toDocId, DocRevision .empty, true )
333
+ .flatMap { whiskAction =>
334
+ val currentPermissions = whiskAction.annotations
335
+ .get(WhiskAction .permissionsFieldName)
336
+ .map(value => value.convertTo[String ])
337
+ .getOrElse(WhiskAction .defaultPermissions)
338
+
339
+ // the user who is owner by default
340
+ var currentExecutePermission = currentPermissions.charAt(2 )
341
+ var errorInfo = s " have no permission to ${operation} this action "
342
+ if (user.namespace.name.asString != entityName.path.root.asString) { // the user who invoke the shared action
343
+ currentExecutePermission = currentPermissions.charAt(5 )
344
+ errorInfo = s " have no permission to ${operation} this shared action "
345
+ }
346
+ if (currentExecutePermission == '-' ) { // have no permission
347
+ Future .failed(RejectRequest (Forbidden , Some (ErrorResponse (errorInfo, transid))))
348
+ } else {
349
+ Future .successful(())
350
+ }
330
351
}
331
- if (currentExecutePermission == '-' ) { // have no permission
332
- Future .failed(RejectRequest (Forbidden , Some (ErrorResponse (errorInfo, transid))))
333
- } else {
334
- Future .successful(())
352
+ .recoverWith {
353
+ case t : RejectRequest =>
354
+ Future .failed(t)
355
+ case _ =>
356
+ Future .successful(())
335
357
}
336
- }
337
358
} else { // download the code
338
- get(entityStore, entityName.toDocId, DocRevision .empty, true ).flatMap { whiskAction =>
339
- val currentPermissions = whiskAction.annotations
340
- .get(WhiskAction .permissionsFieldName)
341
- .map(value => value.convertTo[String ])
342
- .getOrElse(WhiskAction .defaultPermissions)
343
-
344
- val errorInfo = s " have no permission to download this shared action "
345
- val currentDownloadPermission = currentPermissions.charAt(3 )
346
- if (user.namespace.name.asString != entityName.path.root.asString) { // the shared user who download the action
347
- if (currentDownloadPermission == '-' ) {
348
- Future .failed(RejectRequest (Forbidden , Some (ErrorResponse (errorInfo, transid))))
359
+ get(entityStore, entityName.toDocId, DocRevision .empty, true )
360
+ .flatMap { whiskAction =>
361
+ val currentPermissions = whiskAction.annotations
362
+ .get(WhiskAction .permissionsFieldName)
363
+ .map(value => value.convertTo[String ])
364
+ .getOrElse(WhiskAction .defaultPermissions)
365
+
366
+ val errorInfo = s " have no permission to download this shared action "
367
+ val currentDownloadPermission = currentPermissions.charAt(3 )
368
+ if (user.namespace.name.asString != entityName.path.root.asString) { // the shared user who download the action
369
+ if (currentDownloadPermission == '-' ) {
370
+ Future .failed(RejectRequest (Forbidden , Some (ErrorResponse (errorInfo, transid))))
371
+ } else {
372
+ Future .successful(())
373
+ }
349
374
} else {
375
+ // the owner has download permission on any situation
350
376
Future .successful(())
351
377
}
352
- } else {
353
- // the owner has download permission on any situation
354
- Future .successful(())
355
378
}
356
- }
379
+ .recoverWith {
380
+ case t : RejectRequest =>
381
+ Future .failed(t)
382
+ case _ =>
383
+ Future .successful(())
384
+ }
357
385
}
358
386
}
359
387
0 commit comments