Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix to handle User ID sent as GUID.GUID insetad of just GUID #18

Merged
merged 2 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
{
UserSettings us = new(setting.UserId, setting.DarkMode, setting.Planners, setting.Personas, setting.SimplifiedChatExperience,
Expand All @@ -77,39 +77,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 All @@ -134,6 +134,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 @@ -54,7 +54,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
Loading