diff --git a/.changeset/lovely-adults-thank.md b/.changeset/lovely-adults-thank.md new file mode 100644 index 0000000..9fe85c3 --- /dev/null +++ b/.changeset/lovely-adults-thank.md @@ -0,0 +1,8 @@ +--- +'gov4git-desktop-app': patch +--- + +Support mismatched username cases + +- Use the casing as listed in the g4g CLI + protocol as the CLI is case sensitive diff --git a/src/electron/services/ConfigService.ts b/src/electron/services/ConfigService.ts index c6d09b4..cf47879 100644 --- a/src/electron/services/ConfigService.ts +++ b/src/electron/services/ConfigService.ts @@ -61,12 +61,28 @@ export class ConfigService extends AbstractConfigService { } } + protected _getUserName = async (username: string) => { + if (username === '') return '' + const command = ['group', 'list', '--name', 'everybody'] + const users = await this.govService.mustRun(...command) + const existingInd = users.findIndex((u) => { + return u.toLocaleLowerCase() === username.toLocaleLowerCase() + }) + if (existingInd !== -1) { + return users[existingInd]! + } + return username + } + public getConfig = async (): Promise => { const selectedConfig = await this.getSelectedConfig() if (selectedConfig == null) return null const config = await this.readConfig(selectedConfig.path) if (config != null) { this.govService.setConfigPath(selectedConfig.path) + config.user.username = await this._getUserName( + config.user?.username ?? '', + ) const configRecord = { communityUrl: selectedConfig.communityUrl, path: selectedConfig.path, @@ -315,7 +331,7 @@ export class ConfigService extends AbstractConfigService { config: Partial, ): Promise => { const errors: string[] = [] - const user = config.user ?? {} + const user = config.user! if (!(await this.gitService.doesUserExist(user as GitUserInfo))) { errors.push(`Invalid user credentials`) diff --git a/src/electron/services/UserService.ts b/src/electron/services/UserService.ts index a10b701..bdfca50 100644 --- a/src/electron/services/UserService.ts +++ b/src/electron/services/UserService.ts @@ -64,7 +64,10 @@ export class UserService extends AbstractUserService { protected isCommunityMember = async (user: User): Promise => { const command = ['group', 'list', '--name', 'everybody'] const users = await this.gov4GitService.mustRun(...command) - return users.includes(user.username) + const existingInd = users.findIndex((u) => { + return u.toLocaleLowerCase() === user.username.toLocaleLowerCase() + }) + return existingInd !== -1 } protected isCommunityMaintainer = (config: Config): boolean => {