Skip to content

Commit

Permalink
Support mismatched username cases
Browse files Browse the repository at this point in the history
- Use the casing as listed in the g4g CLI
protocol as the CLI is case sensitive
  • Loading branch information
dworthen committed Oct 31, 2023
1 parent dc2490a commit 1a5372a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
8 changes: 8 additions & 0 deletions .changeset/lovely-adults-thank.md
Original file line number Diff line number Diff line change
@@ -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
18 changes: 17 additions & 1 deletion src/electron/services/ConfigService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string[]>(...command)
const existingInd = users.findIndex((u) => {
return u.toLocaleLowerCase() === username.toLocaleLowerCase()
})
if (existingInd !== -1) {
return users[existingInd]!
}
return username
}

public getConfig = async (): Promise<Config | null> => {
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,
Expand Down Expand Up @@ -315,7 +331,7 @@ export class ConfigService extends AbstractConfigService {
config: Partial<Config>,
): Promise<string[]> => {
const errors: string[] = []
const user = config.user ?? {}
const user = config.user!

if (!(await this.gitService.doesUserExist(user as GitUserInfo))) {
errors.push(`Invalid user credentials`)
Expand Down
5 changes: 4 additions & 1 deletion src/electron/services/UserService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ export class UserService extends AbstractUserService {
protected isCommunityMember = async (user: User): Promise<boolean> => {
const command = ['group', 'list', '--name', 'everybody']
const users = await this.gov4GitService.mustRun<string[]>(...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 => {
Expand Down

0 comments on commit 1a5372a

Please sign in to comment.