99namespace OCA \Libresign \Controller ;
1010
1111use OCA \Libresign \AppInfo \Application ;
12+ use OCA \Libresign \Collaboration \Collaborators \SignerPlugin ;
1213use OCA \Libresign \Middleware \Attribute \RequireManager ;
1314use OCA \Libresign \ResponseDefinitions ;
1415use OCA \Libresign \Service \IdentifyMethod \Account ;
@@ -55,17 +56,17 @@ public function __construct(
5556 #[NoAdminRequired]
5657 #[RequireManager]
5758 #[ApiRoute(verb: 'GET ' , url: '/api/{apiVersion}/identify-account/search ' , requirements: ['apiVersion ' => '(v1) ' ])]
58- public function search (string $ search = '' , int $ page = 1 , int $ limit = 25 ): DataResponse {
59- $ shareTypes = $ this ->getShareTypes ();
60- $ lookup = false ;
61-
62- // only search for string larger than a given threshold
63- $ threshold = 1 ;
64- if (strlen ($ search ) < $ threshold ) {
59+ public function search (string $ search = '' , string $ method , int $ page = 1 , int $ limit = 25 ): DataResponse {
60+ // only search for string larger than a minimum length
61+ if (strlen ($ search ) < 1 ) {
6562 return new DataResponse ();
6663 }
6764
65+ $ shareTypes = $ this ->getShareTypes ();
66+ $ lookup = false ;
67+
6868 $ offset = $ limit * ($ page - 1 );
69+ $ this ->registerPlugin ($ method );
6970 [$ result ] = $ this ->collaboratorSearch ->search ($ search , $ shareTypes , $ lookup , $ limit , $ offset );
7071 $ result ['exact ' ] = $ this ->unifyResult ($ result ['exact ' ]);
7172 $ result = $ this ->unifyResult ($ result );
@@ -78,6 +79,19 @@ public function search(string $search = '', int $page = 1, int $limit = 25): Dat
7879 return new DataResponse ($ return );
7980 }
8081
82+ private function registerPlugin (string $ method ): void {
83+ SignerPlugin::setMethod ($ method );
84+
85+ $ refObject = new \ReflectionObject ($ this ->collaboratorSearch );
86+ $ refProperty = $ refObject ->getProperty ('pluginList ' );
87+ $ refProperty ->setAccessible (true );
88+
89+ $ plugins = $ refProperty ->getValue ($ this ->collaboratorSearch );
90+ $ plugins [SignerPlugin::TYPE_SIGNER ] = [SignerPlugin::class];
91+
92+ $ refProperty ->setValue ($ this ->collaboratorSearch , $ plugins );
93+ }
94+
8195 private function getShareTypes (): array {
8296 if (count ($ this ->shareTypes ) > 0 ) {
8397 return $ this ->shareTypes ;
@@ -90,6 +104,8 @@ private function getShareTypes(): array {
90104 if ($ settings ['enabled ' ]) {
91105 $ this ->shareTypes [] = IShare::TYPE_USER ;
92106 }
107+
108+ $ this ->shareTypes [] = SignerPlugin::TYPE_SIGNER ;
93109 return $ this ->shareTypes ;
94110 }
95111
@@ -109,21 +125,33 @@ private function unifyResult(array $list): array {
109125 }
110126
111127 private function formatForNcSelect (array $ list ): array {
128+ $ return = [];
112129 foreach ($ list as $ key => $ item ) {
113- $ list [$ key ] = [
130+ $ return [$ key ] = [
114131 'id ' => $ item ['value ' ]['shareWith ' ],
115132 'isNoUser ' => $ item ['value ' ]['shareType ' ] !== IShare::TYPE_USER ,
116133 'displayName ' => $ item ['label ' ],
117134 'subname ' => $ item ['shareWithDisplayNameUnique ' ] ?? '' ,
118- 'shareType ' => $ item ['value ' ]['shareType ' ],
119135 ];
120136 if ($ item ['value ' ]['shareType ' ] === IShare::TYPE_EMAIL ) {
121- $ list [$ key ]['icon ' ] = 'icon-mail ' ;
137+ $ return [$ key ]['method ' ] = 'email ' ;
138+ $ return [$ key ]['icon ' ] = 'icon-mail ' ;
122139 } elseif ($ item ['value ' ]['shareType ' ] === IShare::TYPE_USER ) {
123- $ list [$ key ]['icon ' ] = 'icon-user ' ;
140+ $ return [$ key ]['method ' ] = 'accoung ' ;
141+ $ return [$ key ]['icon ' ] = 'icon-user ' ;
142+ } elseif ($ item ['value ' ]['shareType ' ] === SignerPlugin::TYPE_SIGNER ) {
143+ $ return [$ key ]['method ' ] = $ item ['key ' ];
144+ if ($ item ['key ' ] === 'email ' ) {
145+ $ return [$ key ]['icon ' ] = 'icon-mail ' ;
146+ } elseif ($ item ['key ' ] === 'account ' ) {
147+ $ return [$ key ]['icon ' ] = 'icon-user ' ;
148+ } else {
149+ $ return [$ key ]['iconSvg ' ] = 'svg ' . ucfirst ($ item ['key ' ]);
150+ $ return [$ key ]['iconName ' ] = $ item ['key ' ];
151+ }
124152 }
125153 }
126- return $ list ;
154+ return $ return ;
127155 }
128156
129157 private function addHerselfAccount (array $ return , string $ search ): array {
0 commit comments