File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -447,15 +447,47 @@ public function getAbilities($module = null)
447447 {
448448 $ abilities_arr = $ this ->config ->get ('permit.abilities ' );
449449
450+ $ abilities = null ;
450451 if (is_null ($ module )) {
451- return $ abilities_arr ;
452+ $ abilities = $ abilities_arr ;
452453 }
453454
454455 if (isset ($ abilities_arr [$ module ])) {
455- return $ abilities_arr [$ module ];
456+ $ abilities = $ abilities_arr [$ module ];
456457 }
457458
458- return null ;
459+ return $ this ->parseAbilities ($ abilities );
460+ }
461+
462+ /**
463+ * parseAbilities is parse for policy
464+ *
465+ * @param $modules
466+ * @return array
467+ */
468+ protected function parseAbilities ($ modules )
469+ {
470+ $ policies = $ this ->config ->get ('permit.policies ' );
471+ $ new_abilities = [];
472+
473+ foreach ($ modules as $ module =>$ abilities ) {
474+ foreach ($ abilities as $ key => $ ability ) {
475+ if (!isset ($ new_abilities [$ module ])) {
476+ $ new_abilities [$ module ] = [];
477+ }
478+ if (is_int ($ key )) {
479+ $ new_abilities [$ module ][] = $ ability ;
480+ } elseif (is_string ($ key )) {
481+ $ policies_name = explode ('. ' , $ ability );
482+ if (count ($ policies_name )==2 ) {
483+ $ new_abilities [$ module ][$ ability ] = $ policies [$ policies_name [0 ]][$ policies_name [1 ]];
484+ }
485+ }
486+ }
487+
488+ }
489+
490+ return $ new_abilities ;
459491 }
460492
461493 /**
You can’t perform that action at this time.
0 commit comments