Skip to content

Commit

Permalink
Merge pull request #18 from aaronba/main
Browse files Browse the repository at this point in the history
Fix to handle User ID sent as GUID.GUID insetad of just GUID
  • Loading branch information
mattahearn authored May 14, 2024
2 parents 805818b + 6951a71 commit d02b389
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 20 deletions.
30 changes: 15 additions & 15 deletions webapi/Controllers/UserSettingsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,27 +43,27 @@ public UserSettingsController(
/// </summary>
/// <param name="userId">The user id to retrieve settings for.</param>
[HttpGet]
[Route("settings/{userId:guid}")]
[Route("settings/{userId}")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public async Task<IActionResult> GetUserSettingsAsync([FromRoute] Guid userId)
public async Task<IActionResult> GetUserSettingsAsync([FromRoute] string userId)
{
IEnumerable<UserSettings> settings;
try
{
settings = await this._userSettingsRepository.FindSettingsByUserIdAsync(userId.ToString());
settings = await this._userSettingsRepository.FindSettingsByUserIdAsync(userId);

if (!settings.OfType<UserSettings>().Any())
{
this._logger.LogDebug("No user settings record found for {0}. Creating a default record", userId.ToString());
this._logger.LogDebug("No user settings record found for {0}. Creating a default record", userId);

// No record found, create a new settings record for this user
UserSettings newUserSettings = new(userId.ToString(), false, false, false, true, true, false, false, false, true, true, false);
UserSettings newUserSettings = new(userId, false, false, false, true, true, false, false, false, true, true, false);
await this._userSettingsRepository.CreateAsync(newUserSettings);
return this.Ok(newUserSettings); // Only 1 record per user id
}

this._logger.LogDebug("User settings record found for: {0}", userId.ToString());
this._logger.LogDebug("User settings record found for: {0}", userId);
foreach (var setting in settings)
{
if (setting.DeploymentGPT35 != true && setting.DeploymentGPT4 != true)
Expand All @@ -82,39 +82,39 @@ public async Task<IActionResult> GetUserSettingsAsync([FromRoute] Guid userId)
this._logger.LogError("GetUserSettingsAsync() exception: {0}", ex.ToString());
}

return this.NotFound(" Did not find any user specific settings for: " + userId.ToString());
return this.NotFound(" Did not find any user specific settings for: " + userId);
}

/// <summary>
/// Update user settings.
/// </summary>
/// <param name="msgParameters">Params to update settings.</param>
[HttpPatch]
[Route("settings/{userId:guid}")]
[HttpPost]
[Route("settings/{userId}")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public async Task<IActionResult> UpdateUserSettingsAsync(
[FromBody] EditUserSettingsParameters msgParameters,
[FromRoute] Guid userId)
[FromRoute] string userId)
{
IEnumerable<UserSettings> settings;
try
{
settings = await this._userSettingsRepository.FindSettingsByUserIdAsync(userId.ToString());
settings = await this._userSettingsRepository.FindSettingsByUserIdAsync(userId);

if (!settings.OfType<UserSettings>().Any())
{
this._logger.LogDebug("No user settings record found for {0}. Creating a default record", userId.ToString());
this._logger.LogDebug("No user settings record found for {0}. Creating a default record", userId);

// Create a new settings record for this user
UserSettings newUserSettings = new(userId.ToString(), msgParameters.darkMode, msgParameters.planners, msgParameters.personas,
UserSettings newUserSettings = new(userId, msgParameters.darkMode, msgParameters.planners, msgParameters.personas,
msgParameters.simplifiedChatExperience, msgParameters.azureContentSafety, msgParameters.azureAISearch, msgParameters.exportChatSessions,
msgParameters.liveChatSessionSharing, msgParameters.feedbackFromUser, msgParameters.deploymentGPT35, msgParameters.deploymentGPT4);
await this._userSettingsRepository.CreateAsync(newUserSettings);
return this.Ok(newUserSettings);
}

this._logger.LogDebug("User settings record found for: {0}", userId.ToString());
this._logger.LogDebug("User settings record found for: {0}", userId);
foreach (var setting in settings)
{
// Update existing settings record for this user
Expand Down Expand Up @@ -143,6 +143,6 @@ public async Task<IActionResult> UpdateUserSettingsAsync(
this._logger.LogError("UpdateUserSettingsAsync() exception: {0}", ex.ToString());
}

return this.NotFound(" Unable to update user settings for: " + userId.ToString());
return this.NotFound(" Unable to update user settings for: " + userId);
}
}
2 changes: 1 addition & 1 deletion webapp/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ const App = () => {
}

setAppState(AppState.UserSettings);
void userSettingsHandler.getUserSettings(account.localAccountId).then((us) => {
void userSettingsHandler.getUserSettings(account.homeAccountId).then((us) => {
if (us !== undefined) {
dispatch(setUserSettings(us));
if (us.darkMode) dispatch(toggleFeatureFlag(FeatureKeys.DarkMode)); // Turn on
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ export const SettingSection: React.FC<ISettingsSectionProps> = ({ setting, conte
{setting.features.map((key) => {
const feature = features[key];
const disableControl = !!feature.inactive;
console.debug('Disable Settings Controls? ' + disableControl);

return (
<div key={key} className={classes.feature}>
Expand Down
10 changes: 8 additions & 2 deletions webapp/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,15 +144,21 @@ export function renderApp() {

fetch(new URL('authConfig', BackendServiceUrl))
.then((response) => (response.ok ? (response.json() as Promise<AuthConfig>) : Promise.reject()))
.then((authConfig) => {
.then(async (authConfig) => {
store.dispatch(setAuthConfig(authConfig));

if (AuthHelper.isAuthAAD()) {
if (!msalInstance) {
msalInstance = new PublicClientApplication(AuthHelper.getMsalConfig(authConfig));
void msalInstance.handleRedirectPromise().then((response) => {
await msalInstance.initialize();
await msalInstance.handleRedirectPromise().then((response) => {
if (response) {
msalInstance?.setActiveAccount(response.account);
} else {
const activeAccount = msalInstance?.getAllAccounts()[0];
if (activeAccount) {
msalInstance?.setActiveAccount(activeAccount);
}
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion webapp/src/libs/services/UserSettingsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class UserSettingsService extends BaseService {
const result = await this.getResponseAsync<IUserSettings>(
{
commandPath: `settings/${userId}`,
method: 'PATCH',
method: 'POST',
body,
},
accessToken,
Expand Down

0 comments on commit d02b389

Please sign in to comment.