@@ -10,6 +10,7 @@ import {
1010 AppNavigationItem ,
1111 defineWebApplication ,
1212 useAbility ,
13+ useAuthService ,
1314 useUserStore
1415} from '@ownclouders/web-pkg'
1516import { RouteRecordRaw } from 'vue-router'
@@ -22,7 +23,7 @@ function $gettext(msg: string) {
2223
2324const appId = 'admin-settings'
2425
25- function getAvailableRoute ( ability : Ability ) {
26+ function getNextAvailableRoute ( ability : Ability ) {
2627 if ( ability . can ( 'read-all' , 'Setting' ) ) {
2728 return { name : 'admin-settings-general' }
2829 }
@@ -42,6 +43,12 @@ function getAvailableRoute(ability: Ability) {
4243 throw Error ( 'Insufficient permissions' )
4344}
4445
46+ async function requireAcr ( acrValue : string , redirectUrl : string ) {
47+ // TODO: check capabilities
48+ const authService = useAuthService ( )
49+ await authService . requireAcr ( acrValue , redirectUrl )
50+ }
51+
4552export const routes = ( { $ability } : { $ability : Ability } ) : RouteRecordRaw [ ] => [
4653 {
4754 path : '/' ,
@@ -53,10 +60,13 @@ export const routes = ({ $ability }: { $ability: Ability }): RouteRecordRaw[] =>
5360 path : '/general' ,
5461 name : 'admin-settings-general' ,
5562 component : General ,
56- beforeEnter : ( to , from , next ) => {
63+ beforeEnter : async ( to , from , next ) => {
5764 if ( ! $ability . can ( 'read-all' , 'Setting' ) ) {
58- return next ( getAvailableRoute ( $ability ) )
65+ return next ( getNextAvailableRoute ( $ability ) )
5966 }
67+
68+ await requireAcr ( 'advanced' , to . fullPath )
69+
6070 next ( )
6171 } ,
6272 meta : {
@@ -68,10 +78,13 @@ export const routes = ({ $ability }: { $ability: Ability }): RouteRecordRaw[] =>
6878 path : '/users' ,
6979 name : 'admin-settings-users' ,
7080 component : Users ,
71- beforeEnter : ( to , from , next ) => {
81+ beforeEnter : async ( to , from , next ) => {
7282 if ( ! $ability . can ( 'read-all' , 'Account' ) ) {
73- return next ( getAvailableRoute ( $ability ) )
83+ return next ( getNextAvailableRoute ( $ability ) )
7484 }
85+
86+ await requireAcr ( 'advanced' , to . fullPath )
87+
7588 next ( )
7689 } ,
7790 meta : {
@@ -83,10 +96,13 @@ export const routes = ({ $ability }: { $ability: Ability }): RouteRecordRaw[] =>
8396 path : '/groups' ,
8497 name : 'admin-settings-groups' ,
8598 component : Groups ,
86- beforeEnter : ( to , from , next ) => {
99+ beforeEnter : async ( to , from , next ) => {
87100 if ( ! $ability . can ( 'read-all' , 'Group' ) ) {
88- return next ( getAvailableRoute ( $ability ) )
101+ return next ( getNextAvailableRoute ( $ability ) )
89102 }
103+
104+ await requireAcr ( 'advanced' , to . fullPath )
105+
90106 next ( )
91107 } ,
92108 meta : {
@@ -98,10 +114,13 @@ export const routes = ({ $ability }: { $ability: Ability }): RouteRecordRaw[] =>
98114 path : '/spaces' ,
99115 name : 'admin-settings-spaces' ,
100116 component : Spaces ,
101- beforeEnter : ( to , from , next ) => {
117+ beforeEnter : async ( to , from , next ) => {
102118 if ( ! $ability . can ( 'read-all' , 'Drive' ) ) {
103- return next ( getAvailableRoute ( $ability ) )
119+ return next ( getNextAvailableRoute ( $ability ) )
104120 }
121+
122+ await requireAcr ( 'advanced' , to . fullPath )
123+
105124 next ( )
106125 } ,
107126 meta : {
0 commit comments