File tree 3 files changed +53
-4
lines changed
angular/app/components/user-roles-edit 3 files changed +53
-4
lines changed Original file line number Diff line number Diff line change @@ -39,6 +39,16 @@ <h4>{{alert.title}}</h4>
39
39
< textarea class ="form-control " rows ="3 " ng-model ="vm.role.data.description " name ="description " placeholder ="Description "> </ textarea >
40
40
</ div >
41
41
</ div >
42
+ < div class ="form-group ">
43
+ < label for ="inputEmail3 " class ="col-sm-2 control-label "> Permission</ label >
44
+ < div class ="col-sm-10 ">
45
+ < div class ="checkbox " ng-repeat ="permission in vm.systemPermissions ">
46
+ < label >
47
+ < input type ="checkbox " checklist-model ="vm.role.data.permissions " checklist-value ="permission.id "> {{permission.name}}
48
+ </ label >
49
+ </ div >
50
+ </ div >
51
+ </ div >
42
52
</ div >
43
53
< div class ="box-footer ">
44
54
< a ui-sref ="app.userroles " class ="btn btn-default "> < i class ="fa fa-angle-double-left "> </ i > Back</ a >
Original file line number Diff line number Diff line change @@ -10,12 +10,33 @@ class UserRolesEditController{
10
10
this . alerts . push ( $stateParams . alerts ) ;
11
11
}
12
12
13
+ let Permissions = API . service ( 'permissions' , API . all ( 'users' ) ) ;
14
+
15
+ Permissions . getList ( )
16
+ . then ( ( response ) => {
17
+ let permissionList = [ ]
18
+ let permissionResponse = response . plain ( )
19
+
20
+ angular . forEach ( permissionResponse , function ( value , key ) {
21
+ permissionList . push ( { id : value . id , name : value . name } )
22
+ } )
23
+
24
+ this . systemPermissions = permissionList
25
+ } , ( response ) => {
26
+ console . log ( response ) ;
27
+ } ) ;
28
+
13
29
let roleId = $stateParams . roleId ;
14
30
let Role = API . service ( 'roles-show' , API . all ( 'users' ) ) ;
15
31
Role . one ( roleId ) . get ( )
16
32
. then ( ( response ) => {
17
- let res = response . plain ( )
18
- let data = res . data . role
33
+ let rolePermissions = [ ]
34
+
35
+ angular . forEach ( response . data . permissions , function ( value , key ) {
36
+ rolePermissions . push ( value . id )
37
+ } )
38
+
39
+ response . data . permissions = rolePermissions ;
19
40
20
41
this . role = API . copy ( response )
21
42
} , ( response ) => {
Original file line number Diff line number Diff line change @@ -90,16 +90,34 @@ public function getRolesShow($id)
90
90
{
91
91
$ role = Role::find ($ id );
92
92
93
+ $ role ['permissions ' ] = $ role
94
+ ->permissions ()
95
+ ->select (array ('permissions.name ' ,'permissions.id ' ))
96
+ ->get ();
97
+
93
98
return response ()->success ($ role );
94
99
}
95
100
96
101
public function putRolesShow ()
97
102
{
98
103
$ roleForm = Input::get ('data ' );
104
+ $ roleData = array (
105
+ 'name ' => $ roleForm ['name ' ],
106
+ 'slug ' => $ roleForm ['slug ' ],
107
+ 'description ' => $ roleForm ['description ' ]
108
+ );
109
+
99
110
$ roleForm ['slug ' ] = str_slug ($ roleForm ['slug ' ], ". " );
100
- $ affectedRows = Role::where ('id ' , '= ' , intval ($ roleForm ['id ' ]))->update ($ roleForm );
111
+ $ affectedRows = Role::where ('id ' , '= ' , intval ($ roleForm ['id ' ]))->update ($ roleData );
101
112
102
- return response ()->success ($ roleForm );
113
+ $ role = Role::find ($ roleForm ['id ' ]);
114
+ $ role ->detachAllPermissions ();
115
+
116
+ foreach (Input::get ('data.permissions ' ) as $ setPermission ) {
117
+ $ role ->attachPermission ($ setPermission );
118
+ }
119
+
120
+ return response ()->success ('success ' );
103
121
}
104
122
105
123
public function postRoles () {
You can’t perform that action at this time.
0 commit comments