@@ -13,6 +13,7 @@ const EMAIL_RGX = /^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]
1313
1414// Valid actions for handling a contributor
1515type ContributorActions = 'create' | 'remove' ;
16+ type ContributorType = 'user' | 'group' ;
1617
1718interface CreateProfileRequest {
1819 namespace ?: string ;
@@ -21,6 +22,7 @@ interface CreateProfileRequest {
2122
2223interface AddOrRemoveContributorRequest {
2324 contributor ?: string ;
25+ cType ?: ContributorType ;
2426}
2527
2628interface HasWorkgroupResponse {
@@ -53,6 +55,7 @@ export interface SimpleBinding {
5355 namespace : string ;
5456 role : SimpleRole ;
5557 subject : string ;
58+ kind ?: string ;
5659}
5760
5861export interface WorkgroupInfo {
@@ -68,6 +71,7 @@ export function mapWorkgroupBindingToSimpleBinding (bindings: WorkgroupBinding[]
6871 subject : n . subject . name ,
6972 namespace : n . referredNamespace ,
7073 role : roleMap . get ( n . roleRef . name as Role ) as SimpleRole ,
74+ kind : n . subject . kind ,
7175 } ) ) ;
7276}
7377
@@ -87,10 +91,10 @@ export function mapNamespacesToSimpleBinding (subject: string, namespaces: V1Nam
8791 * Converts SimpleBinding to Workgroup Binding from Profile Controller
8892 */
8993export function mapSimpleBindingToWorkgroupBinding ( binding : SimpleBinding ) : WorkgroupBinding {
90- const { subject, namespace, role} = binding ;
94+ const { subject, namespace, role, kind : subjectKind } = binding ;
9195 return {
9296 subject : {
93- kind : 'User' ,
97+ kind : subjectKind . charAt ( 0 ) . toUpperCase ( ) + subjectKind . slice ( 1 ) ,
9498 name : subject ,
9599 } ,
96100 referredNamespace : namespace ,
@@ -191,7 +195,7 @@ export class WorkgroupApi {
191195 }
192196 async handleContributor ( action : ContributorActions , req : Request , res : Response ) {
193197 const { namespace} = req . params ;
194- const { contributor} = req . body as AddOrRemoveContributorRequest ;
198+ const { contributor, cType } = req . body as AddOrRemoveContributorRequest ;
195199 const { profilesService} = this ;
196200 if ( ! contributor || ! namespace ) {
197201 const missing = [ ] ;
@@ -204,7 +208,7 @@ export class WorkgroupApi {
204208 error : `Missing ${ missing . join ( ' and ' ) } field${ missing . length - 1 ?'s' :'' } .` ,
205209 } ) ;
206210 }
207- if ( ! EMAIL_RGX . test ( contributor ) ) {
211+ if ( cType === "user" && ! EMAIL_RGX . test ( contributor ) ) {
208212 return apiError ( {
209213 res,
210214 error : `Contributor doesn't look like a valid email address` ,
@@ -214,6 +218,7 @@ export class WorkgroupApi {
214218 try {
215219 const binding = mapSimpleBindingToWorkgroupBinding ( {
216220 subject : contributor ,
221+ kind : cType ,
217222 namespace,
218223 role : 'contributor' ,
219224 } ) ;
@@ -226,8 +231,8 @@ export class WorkgroupApi {
226231 const actionAPI = action === 'create' ? 'createBinding' : 'deleteBinding' ;
227232 await profilesService [ actionAPI ] ( binding , { headers} ) ;
228233 errIndex ++ ;
229- const users = await this . getContributors ( namespace ) ;
230- res . json ( users ) ;
234+ const contributors = await this . getContributors ( namespace ) ;
235+ res . json ( contributors ) ;
231236 } catch ( err ) {
232237 const errMessage = [
233238 `Unable to add new contributor for ${ namespace } . HTTP ${ err . response . statusCode || '???' } - ${ err . response . statusMessage || 'Unknown' } ` ,
@@ -244,13 +249,19 @@ export class WorkgroupApi {
244249 * Given an owned namespace, list all contributors under it
245250 * @param namespace Namespace to find contributors for
246251 */
247- async getContributors ( namespace : string ) {
252+ async getContributors ( namespace : string ) : Promise < Array < { name : string , kind ?: string } > > {
248253 const { body} = await this . profilesService
249254 . readBindings ( undefined , namespace ) ;
250- const users = mapWorkgroupBindingToSimpleBinding ( body . bindings )
255+ const simpleBindings = mapWorkgroupBindingToSimpleBinding ( body . bindings ) ;
256+ console . log ( simpleBindings ) ;
257+ const contributors = simpleBindings
251258 . filter ( ( b ) => b . role === 'contributor' )
252- . map ( ( b ) => b . subject ) ;
253- return users ;
259+ . map ( ( b ) => ( {
260+ name : b . subject ,
261+ kind : b . kind ,
262+ } ) ) ;
263+ console . log ( contributors ) ;
264+ return contributors ;
254265 }
255266 routes ( ) { return Router ( )
256267 . get ( '/exists' , async ( req : Request , res : Response ) => {
@@ -374,8 +385,8 @@ export class WorkgroupApi {
374385 . get ( '/get-contributors/:namespace' , async ( req : Request , res : Response ) => {
375386 const { namespace} = req . params ;
376387 try {
377- const users = await this . getContributors ( namespace ) ;
378- res . json ( users ) ;
388+ const contributors = await this . getContributors ( namespace ) ;
389+ res . json ( contributors ) ;
379390 } catch ( err ) {
380391 surfaceProfileControllerErrors ( {
381392 res,
0 commit comments