3737use OCP \Group \Backend \IBatchMethodsBackend ;
3838use OCP \Group \Backend \ICountDisabledInGroup ;
3939use OCP \Group \Backend \ICountUsersBackend ;
40- use OCP \Group \Backend \ICreateGroupBackend ;
40+ use OCP \Group \Backend \ICreateNamedGroupBackend ;
4141use OCP \Group \Backend \IDeleteGroupBackend ;
4242use OCP \Group \Backend \IGetDisplayNameBackend ;
4343use OCP \Group \Backend \IGroupDetailsBackend ;
@@ -55,7 +55,7 @@ class Database extends ABackend implements
5555 IAddToGroupBackend,
5656 ICountDisabledInGroup,
5757 ICountUsersBackend,
58- ICreateGroupBackend ,
58+ ICreateNamedGroupBackend ,
5959 IDeleteGroupBackend,
6060 IGetDisplayNameBackend,
6161 IGroupDetailsBackend,
@@ -86,35 +86,28 @@ private function fixDI() {
8686 }
8787 }
8888
89- /**
90- * Try to create a new group
91- * @param string $gid The name of the group to create
92- * @return bool
93- *
94- * Tries to create a new group. If the group name already exists, false will
95- * be returned.
96- */
97- public function createGroup (string $ gid ): bool {
89+ public function createGroup (string $ name ): ?string {
9890 $ this ->fixDI ();
9991
92+ $ gid = $ this ->computeGid ($ name );
10093 try {
10194 // Add group
10295 $ builder = $ this ->dbConn ->getQueryBuilder ();
10396 $ result = $ builder ->insert ('groups ' )
10497 ->setValue ('gid ' , $ builder ->createNamedParameter ($ gid ))
105- ->setValue ('displayname ' , $ builder ->createNamedParameter ($ gid ))
98+ ->setValue ('displayname ' , $ builder ->createNamedParameter ($ name ))
10699 ->execute ();
107100 } catch (UniqueConstraintViolationException $ e ) {
108- $ result = 0 ;
101+ return null ;
109102 }
110103
111104 // Add to cache
112105 $ this ->groupCache [$ gid ] = [
113106 'gid ' => $ gid ,
114- 'displayname ' => $ gid
107+ 'displayname ' => $ name
115108 ];
116109
117- return $ result === 1 ;
110+ return $ gid ;
118111 }
119112
120113 /**
@@ -595,4 +588,13 @@ public function setDisplayName(string $gid, string $displayName): bool {
595588 public function getBackendName (): string {
596589 return 'Database ' ;
597590 }
591+
592+ /**
593+ * Compute group ID from display name (GIDs are limited to 64 characters in database)
594+ */
595+ private function computeGid (string $ displayName ): string {
596+ return mb_strlen ($ displayName ) > 64
597+ ? hash ('sha256 ' , $ displayName )
598+ : $ displayName ;
599+ }
598600}
0 commit comments