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

TNO-2831: Vacation Switch feature #2203

Merged
merged 9 commits into from
Aug 26, 2024
Merged

TNO-2831: Vacation Switch feature #2203

merged 9 commits into from
Aug 26, 2024

Conversation

areyeslo
Copy link
Collaborator

Vacation Switch Mode provides subscribers with the ability to temporarily disable notifications, such as those related to approved/requested transcriptions and evening reports, while they are on vacation.

Subscribers can easily manage their notification preferences through the Settings under My Account section. This feature gives users control to turn off completely notifications.
Settings View

When Vacation Mode is activated, a message will appear at the top of the banner, informing the user that notifications are turned off. This banner can be closed at any time by the user.
Vacation Mode Deactivation Banner

@areyeslo areyeslo added enhancement New feature or request DB Migration A DB Migration may require refreshing or simply updating your database. subscriber PR contains changes towards the subscriber application, tno-core update Indicates that there have been changes to our tno-core package, which can pose concurrency issues. labels Aug 22, 2024
@areyeslo areyeslo marked this pull request as ready for review August 22, 2024 17:57
@areyeslo areyeslo requested a review from Fosol August 22, 2024 17:58
@@ -332,12 +332,16 @@ public IActionResult GetDashboardReport(int id)
{
var report = _reportService.GetDashboardReport(id);

var subscribers = report.SubscribersManyToMany.Where(s => s.User!.AccountType != Entities.UserAccountType.Distribution).Select(s => new UserReportModel(s)).ToList();
var subscribers = report.SubscribersManyToMany.Where(s => s.User!.AccountType != Entities.UserAccountType.Distribution && s.User!.IsVacationMode != true).Select(s => new UserReportModel(s)).ToList();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are filtering on vacation mode here? This endpoint returns all users who are subscribed so that we can display the status.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

var distributions = report.SubscribersManyToMany.Where(s => s.User!.AccountType == Entities.UserAccountType.Distribution).ToArray();
foreach (var distribution in distributions)
{
// Flatten the list of subscribers by extracting users in a distribution list.
subscribers.AddRange(distribution.User!.Distribution.Select(d => new UserReportModel(distribution, d.LinkedUser!)));
subscribers.AddRange(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are filtering on vacation mode here? This endpoint returns all users who are subscribed so that we can display the status.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@@ -91,8 +91,8 @@ public IActionResult Update(UserModel model)
var user = _userService.FindByUsername(username) ?? throw new NotAuthorizedException($"User [{username}] does not exist");
var isAdmin = user.Roles.Split(',').Contains($"[{ClientRole.Administrator.GetName()}]");
if (user.Id != model.Id && !isAdmin) throw new NotAuthorizedException("You are not authorized to update this user.");
var result = _userService.UpdatePreferences((User)model) ?? throw new NoContentException("Updated did not return the user");
return new JsonResult(new UserModel(result));
var updateUser = _userService.UpdateUser((User)model) ?? throw new NoContentException("Updated did not return the user");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We cannot do this it is a security hole.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@@ -140,7 +140,7 @@ public async Task<IActionResult> RequestTranscriptionAsync(long contentId)

// Send email to requestor to confirm we have receive their request for a transcript.
var settingValue = _settingService.FindByName(_apiOptions.TranscriptRequestConfirmationKey)?.Value ?? "";
if (workOrder.RequestorId.HasValue && int.TryParse(settingValue, out int notificationId))
if (workOrder.RequestorId.HasValue && workOrder.Requestor != null && workOrder.Requestor.IsVacationMode != true && int.TryParse(settingValue, out int notificationId))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A user can still request transcripts when on vacation. The vacation mode is only about receiving emails.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@@ -10,6 +10,7 @@ export const defaultUser: IUserModel = {
firstName: '',
lastName: '',
isEnabled: true,
isVacationMode: false,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move vacation mode to user preferences.

/// get/set - Whether the user turns off notifications.
/// </summary>
[Column("is_vacation_mode")]
public bool IsVacationMode {get; set; }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not add this property to the root object. Add it to the user preferences.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added to preferences.

@@ -5108,6 +5108,10 @@ protected override void BuildModel(ModelBuilder modelBuilder)
.HasColumnType("boolean")
.HasColumnName("is_system_account");

b.Property<bool>("IsVacationMode")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need a DB migration for this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! Working on the changes

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Migration removed.

@areyeslo areyeslo marked this pull request as draft August 22, 2024 20:09
@areyeslo areyeslo force-pushed the TNO-2831-VacationSwitch branch 3 times, most recently from 37e9a72 to cad54ff Compare August 23, 2024 22:02
@areyeslo areyeslo removed the DB Migration A DB Migration may require refreshing or simply updating your database. label Aug 23, 2024
@areyeslo areyeslo force-pushed the TNO-2831-VacationSwitch branch 7 times, most recently from 4f7b240 to 41cd959 Compare August 23, 2024 23:42
@areyeslo areyeslo marked this pull request as ready for review August 23, 2024 23:51
@areyeslo areyeslo requested a review from Fosol August 23, 2024 23:52
@@ -147,7 +147,9 @@ public async Task<IActionResult> RequestTranscriptionAsync(long contentId)
NotificationId = notificationId,
ContentId = contentId,
RequestorId = workOrder.RequestorId,
To = !String.IsNullOrWhiteSpace(user.PreferredEmail) ? user.PreferredEmail : user.Email,
To = user != null && !user.IsVacationMode()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed. Vacation mode is just to turn off emails.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understood this part would send email using the email account of To property. So I checked the email account is not under VacationMode.

}
}, [isVacationMode]);

const handleVacationModeToggle = () => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use React.useCallback or this function will generate a render each time

// Handle the error, if needed
console.error('Failed to update user:', error);
}
}, [profile, impersonate, isVacationMode, storeImpersonate, storeMyProfile, updateUser]);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move profile, impersonate and isVacationMode to parameters in the function will reduce the rerendering required to keep this function in sync with the variables. You can just call the function like this toggleVacationMode(impersonate ?? profile, !isVacationMode)

const user = createUser();

try {
!!impersonate ? storeImpersonate(user) : storeMyProfile(user);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic is already performed by the useUser hook. I don't see a need to do it again.

}
else
{
return new[] { subscriber.User };
return !subscriber.User.IsVacationMode()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have already filtered out users that are on vacation mode on line 397. Why are you doing it again?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if userAccountType is type of Distribution then we will discard those emails with IsVacationMode. Otherwise, if userAccountType is not a single user, then added if does not have IsVacationMode. We want to discard email accounts with IsVacationMode in both conditions. Is this understanding not right?

@@ -1016,17 +1017,21 @@ private async Task<Dictionary<EmailSentTo, List<UserEmail>>> GetEmailAddressesAs
}
else
{
switch (sendTo)
var user = await this.Api.GetUserAsync(userId);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will add a lot of additional requests for each report. We already do a join on the user table to get all the user's email addresses. You can update the model to include the vacation mode.

@areyeslo areyeslo force-pushed the TNO-2831-VacationSwitch branch 2 times, most recently from 5399da8 to e78b39c Compare August 26, 2024 17:09
@@ -974,7 +974,7 @@ private async Task<Dictionary<EmailSentTo, List<UserEmail>>> GetEmailAddressesAs
if (user.User == null) throw new InvalidOperationException("Report subscriber is missing user information");

// Only include users who have not received an email yet.
var (a, b, c) = await GetEmailAddressesAsync(user.UserId, user.User.GetEmail(), user.User.AccountType, user.SendTo);
var (a, b, c) = await GetEmailAddressesAsync(user.UserId, user.User.GetEmail(), user.User.IsVacationMode(), user.User.AccountType, user.SendTo);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not needed. You already filtered out users on vacation before calling this method.

@areyeslo areyeslo requested a review from Fosol August 26, 2024 20:00
@jdtoombs
Copy link
Collaborator

@areyeslo - published tno-core@0.1.136 just need to update your package.json's!

@@ -61,7 +61,7 @@
"redux-logger": "3.0.6",
"styled-components": "6.1.11",
"stylis": "4.3.2",
"tno-core": "0.1.135"
"tno-core": "./tno-core-0.1.136.tgz"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to correct

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove

@areyeslo areyeslo requested a review from Fosol August 26, 2024 22:33
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove

@@ -11074,7 +11074,7 @@ __metadata:
sass-extract-loader: 1.1.0
styled-components: 6.1.11
stylis: 4.3.2
tno-core: ./tno-core-0.1.134.tgz
tno-core: ./tno-core-0.1.136.tgz
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove

@@ -10698,7 +10697,7 @@ __metadata:
sheetjs: "file:packages/xlsx-0.20.1.tgz"
styled-components: 6.1.11
stylis: 4.3.2
tno-core: ./tno-core-0.1.134.tgz
tno-core: ./tno-core-0.1.136.tgz
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update

"tno-core@file:./tno-core-0.1.134.tgz::locator=mmi-subscriber-app%40workspace%3A.":
version: 0.1.134
resolution: "tno-core@file:./tno-core-0.1.134.tgz::locator=mmi-subscriber-app%40workspace%3A."
"tno-core@file:./tno-core-0.1.136.tgz::locator=mmi-subscriber-app%40workspace%3A.":
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You didn't correctly run yarn install to fix this lock. You manually changed it.

resolution: "tno-core@file:./tno-core-0.1.134.tgz::locator=mmi-editor-app%40workspace%3A."
"tno-core@file:./tno-core-0.1.136.tgz::locator=mmi-editor-app%40workspace%3A.":
version: 0.1.136
resolution: "tno-core@file:./tno-core-0.1.136.tgz::locator=mmi-editor-app%40workspace%3A."
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You didn't correctly run yarn install to fix this lock. You manually changed it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The last push is executing yarn install.

@Fosol Fosol merged commit f205dd4 into dev Aug 26, 2024
7 checks passed
@Fosol Fosol deleted the TNO-2831-VacationSwitch branch August 26, 2024 23:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request subscriber PR contains changes towards the subscriber application, tno-core update Indicates that there have been changes to our tno-core package, which can pose concurrency issues.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants