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 Symfony \Component \Console \Input \ArrayInput ;
@@ -34,6 +35,7 @@ public function __construct(
3435 private IUserManager $ userManager ,
3536 private IUserSession $ userSession ,
3637 private BackendService $ backendService ,
38+ private IGroupManager $ groupManager ,
3739 ) {
3840 parent ::__construct ();
3941 }
@@ -75,6 +77,18 @@ protected function configure(): void {
7577 '' ,
7678 InputOption::VALUE_NONE ,
7779 'Don \'t save the created mount, only list the new mount '
80+ )
81+ ->addOption (
82+ 'applicable-user ' ,
83+ '' ,
84+ InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED ,
85+ 'Add a user as applicable to the newly created mount '
86+ )
87+ ->addOption (
88+ 'applicable-group ' ,
89+ '' ,
90+ InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED ,
91+ 'Add a group as applicable to the newly created mount '
7892 );
7993 parent ::configure ();
8094 }
@@ -86,6 +100,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
86100 $ storageIdentifier = $ input ->getArgument ('storage_backend ' );
87101 $ authIdentifier = $ input ->getArgument ('authentication_backend ' );
88102 $ configInput = $ input ->getOption ('config ' );
103+ $ applicableUsers = $ input ->getOption ('applicable-user ' );
104+ $ applicableGroups = $ input ->getOption ('applicable-group ' );
89105
90106 $ storageBackend = $ this ->backendService ->getBackend ($ storageIdentifier );
91107 $ authBackend = $ this ->backendService ->getAuthMechanism ($ authIdentifier );
@@ -128,6 +144,19 @@ protected function execute(InputInterface $input, OutputInterface $output): int
128144 $ mount ->setAuthMechanism ($ authBackend );
129145 $ mount ->setBackendOptions ($ config );
130146
147+ foreach ($ applicableUsers as $ applicableUser ) {
148+ if (!$ this ->userManager ->userExists ($ applicableUser )) {
149+ $ output ->writeln ('<error>Unknown user " ' . $ applicableUser . '"</error> ' );
150+ }
151+ }
152+ foreach ($ applicableGroups as $ applicableGroup ) {
153+ if (!$ this ->groupManager ->groupExists ($ applicableGroup )) {
154+ $ output ->writeln ('<error>Unknown group " ' . $ applicableGroup . '"</error> ' );
155+ }
156+ }
157+ $ mount ->setApplicableUsers ($ applicableUsers );
158+ $ mount ->setApplicableGroups ($ applicableGroups );
159+
131160 if ($ user ) {
132161 if (!$ this ->userManager ->userExists ($ user )) {
133162 $ output ->writeln ('<error>User " ' . $ user . '" not found</error> ' );
0 commit comments