-
Notifications
You must be signed in to change notification settings - Fork 17
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
Conversation
94b5c6b
to
90a96d7
Compare
@@ -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(); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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"); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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.
libs/net/entities/User.cs
Outdated
/// get/set - Whether the user turns off notifications. | ||
/// </summary> | ||
[Column("is_vacation_mode")] | ||
public bool IsVacationMode {get; set; } |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Migration removed.
37e9a72
to
cad54ff
Compare
4f7b240
to
41cd959
Compare
@@ -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() |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 = () => { |
There was a problem hiding this comment.
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]); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
5399da8
to
e78b39c
Compare
e78b39c
to
71182ab
Compare
@@ -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); |
There was a problem hiding this comment.
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.
01299e7
to
3dda3ca
Compare
@areyeslo - published |
f5c8c3e
to
15de8f7
Compare
15de8f7
to
7b2c454
Compare
app/editor/package.json
Outdated
@@ -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" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to correct
app/editor/tno-core-0.1.135.tgz
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove
app/editor/tno-core-0.1.136.tgz
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove
app/subscriber/tno-core-0.1.134.tgz
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove
app/subscriber/tno-core-0.1.135.tgz
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove
app/subscriber/tno-core-0.1.136.tgz
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove
app/editor/tno-core-0.1.136.tgz
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove
app/editor/yarn.lock
Outdated
@@ -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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update
app/subscriber/tno-core-0.1.136.tgz
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove
app/subscriber/yarn.lock
Outdated
@@ -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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update
app/subscriber/yarn.lock
Outdated
"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.": |
There was a problem hiding this comment.
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.
app/editor/yarn.lock
Outdated
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." |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
.
8f488bb
to
d14408d
Compare
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.
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.