2121
2222namespace OCA \GroupFolders ;
2323
24- use Exception ;
24+ use OC \AppFramework \Middleware \Security \Exceptions \NotAdminException ;
25+ use OCA \GroupFolders \Folder \FolderManager ;
2526use OCA \GroupFolders \Service \DelegationService ;
2627use OCP \AppFramework \Http \JSONResponse ;
2728use OCP \AppFramework \Http \Response ;
2829use OCP \AppFramework \Http \TemplateResponse ;
2930use OCP \AppFramework \Middleware ;
3031use OCP \AppFramework \Utility \IControllerMethodReflector ;
3132use OCP \IRequest ;
33+ use OCP \IUserSession ;
3234
3335class AuthorizedAdminSettingMiddleware extends Middleware {
34- private DelegationService $ delegatedService ;
35- private IControllerMethodReflector $ reflector ;
36- private IRequest $ request ;
37-
3836 public function __construct (
39- DelegationService $ delegatedService ,
40- IControllerMethodReflector $ reflector ,
41- IRequest $ request
37+ private DelegationService $ delegatedService ,
38+ private IControllerMethodReflector $ reflector ,
39+ private IRequest $ request ,
40+ private IUserSession $ userSession ,
41+ private FolderManager $ folderManager ,
4242 ) {
43- $ this ->delegatedService = $ delegatedService ;
44- $ this ->reflector = $ reflector ;
45- $ this ->request = $ request ;
4643 }
4744
4845 /**
@@ -54,11 +51,24 @@ public function __construct(
5451 *
5552 */
5653 public function beforeController ($ controller , $ methodName ) {
57- if ($ this ->reflector ->hasAnnotation ('RequireGroupFolderAdmin ' )) {
58- if (!$ this ->delegatedService ->hasApiAccess ()) {
59- throw new Exception ('Logged in user must be an admin, a sub admin or gotten special right to access this setting ' );
54+ if (!$ this ->reflector ->hasAnnotation ('RequireGroupFolderAdmin ' )) {
55+ return ;
56+ }
57+
58+ if ($ this ->delegatedService ->isAdminNextcloud () || $ this ->delegatedService ->isDelegatedAdmin ()) {
59+ return ;
60+ }
61+
62+ if ($ this ->delegatedService ->hasOnlyApiAccess ()
63+ && ($ user = $ this ->userSession ->getUser ()) !== null
64+ && ($ id = $ this ->request ->getParam ('id ' )) !== null ) {
65+ /** @var string $id */
66+ if ($ this ->folderManager ->canManageACL ((int )$ id , $ user )) {
67+ return ;
6068 }
6169 }
70+
71+ throw new NotAdminException ('Logged in user must be an admin, a sub admin or gotten special right to access this setting ' );
6272 }
6373
6474 /**
0 commit comments