1111use OCA \Tables \Db \Column ;
1212use OCA \Tables \Errors \BadRequestError ;
1313use OCA \Tables \Helper \CircleHelper ;
14+ use OCP \IGroupManager ;
1415use OCP \IUserManager ;
1516use Psr \Log \LoggerInterface ;
1617
@@ -20,6 +21,7 @@ public function __construct(
2021 protected LoggerInterface $ logger ,
2122 protected CircleHelper $ circleHelper ,
2223 protected IUserManager $ userManager ,
24+ protected IGroupManager $ groupManager ,
2325 ) {
2426 parent ::__construct ($ logger );
2527 }
@@ -53,15 +55,19 @@ public function validateValue(mixed $value, Column $column, string $userId, int
5355 if (!isset ($ userGroupEntry ['type ' ]) || !is_int ($ userGroupEntry ['type ' ])) {
5456 throw new BadRequestError ('Invalid usergroup type ' );
5557 }
56- if ($ userGroupEntry ['type ' ] === UsergroupType::CIRCLE ) {
57- if ($ this ->userManager ->get ($ userId ) === null ) {
58+ if ($ userGroupEntry ['type ' ] === UsergroupType::USER ) {
59+ if (! $ this ->userManager ->get ($ userGroupEntry [ ' id ' ]) ) {
5860 throw new BadRequestError ('User not found ' );
5961 }
60- if (!$ this ->circleHelper ->circleExists ($ userGroupEntry ['id ' ], null )) {
61- throw new BadRequestError ('Circle does not exist ' );
62+ }
63+ if ($ userGroupEntry ['type ' ] === UsergroupType::GROUP ) {
64+ if (!$ this ->groupManager ->get ($ userGroupEntry ['id ' ])) {
65+ throw new BadRequestError ('Group not found. ' );
6266 }
67+ }
68+ if ($ userGroupEntry ['type ' ] === UsergroupType::CIRCLE ) {
6369 if (!$ this ->circleHelper ->circleExists ($ userGroupEntry ['id ' ], $ userId )) {
64- throw new BadRequestError ('Circle not found ' );
70+ throw new BadRequestError ('Circle not found. ' );
6571 }
6672 }
6773 }
0 commit comments