1919use OCA \Files_External \Service \StoragesService ;
2020use OCA \Files_External \Service \UserStoragesService ;
2121use OCP \AppFramework \Http ;
22+ use OCP \IGroupManager ;
2223use OCP \IUserManager ;
2324use OCP \IUserSession ;
2425use OCP \User \Exceptions \UserNotFoundException ;
@@ -35,6 +36,7 @@ public function __construct(
3536 private IUserManager $ userManager ,
3637 private IUserSession $ userSession ,
3738 private BackendService $ backendService ,
39+ private IGroupManager $ groupManager ,
3840 ) {
3941 parent ::__construct ();
4042 }
@@ -76,6 +78,18 @@ protected function configure(): void {
7678 '' ,
7779 InputOption::VALUE_NONE ,
7880 'Don \'t save the created mount, only list the new mount '
81+ )
82+ ->addOption (
83+ 'applicable-user ' ,
84+ '' ,
85+ InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED ,
86+ 'Add a user as applicable to the newly created mount '
87+ )
88+ ->addOption (
89+ 'applicable-group ' ,
90+ '' ,
91+ InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED ,
92+ 'Add a group as applicable to the newly created mount '
7993 );
8094 parent ::configure ();
8195 }
@@ -87,6 +101,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
87101 $ storageIdentifier = $ input ->getArgument ('storage_backend ' );
88102 $ authIdentifier = $ input ->getArgument ('authentication_backend ' );
89103 $ configInput = $ input ->getOption ('config ' );
104+ $ applicableUsers = $ input ->getOption ('applicable-user ' );
105+ $ applicableGroups = $ input ->getOption ('applicable-group ' );
90106
91107 $ storageBackend = $ this ->backendService ->getBackend ($ storageIdentifier );
92108 $ authBackend = $ this ->backendService ->getAuthMechanism ($ authIdentifier );
@@ -129,6 +145,19 @@ protected function execute(InputInterface $input, OutputInterface $output): int
129145 $ mount ->setAuthMechanism ($ authBackend );
130146 $ mount ->setBackendOptions ($ config );
131147
148+ foreach ($ applicableUsers as $ applicableUser ) {
149+ if (!$ this ->userManager ->userExists ($ applicableUser )) {
150+ $ output ->writeln ('<error>Unknown user " ' . $ applicableUser . '"</error> ' );
151+ }
152+ }
153+ foreach ($ applicableGroups as $ applicableGroup ) {
154+ if (!$ this ->groupManager ->groupExists ($ applicableGroup )) {
155+ $ output ->writeln ('<error>Unknown group " ' . $ applicableGroup . '"</error> ' );
156+ }
157+ }
158+ $ mount ->setApplicableUsers ($ applicableUsers );
159+ $ mount ->setApplicableGroups ($ applicableGroups );
160+
132161 if ($ user ) {
133162 if (!$ this ->userManager ->userExists ($ user )) {
134163 $ output ->writeln ('<error>User " ' . $ user . '" not found</error> ' );
0 commit comments