Skip to content

Commit ebae582

Browse files
committed
Fixed send kudos logic to update Total/Spent/Remaining Kudos
1 parent 6cfcaf2 commit ebae582

File tree

12 files changed

+37
-52
lines changed

12 files changed

+37
-52
lines changed

src/api/Shrooms.DataLayer/DAL/ShroomsDbContext.cs

Lines changed: 7 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -222,13 +222,16 @@ protected override void OnModelCreating(DbModelBuilder modelBuilder)
222222
new OtherEntitiesConfig(modelBuilder).Add();
223223
}
224224

225-
private static void UpdateEntityMetadata(IEnumerable<DbEntityEntry> entries, string userId)
225+
private static void UpdateEntityMetadata(IEnumerable<DbEntityEntry> entries, string userId = "")
226226
{
227+
if (string.IsNullOrEmpty(userId) && HttpContext.Current != null && HttpContext.Current.User != null)
228+
{
229+
userId = HttpContext.Current.User.Identity.GetUserId();
230+
}
231+
227232
var now = DateTime.UtcNow;
228233
var items = entries
229-
.Where(p =>
230-
p.Entity is ITrackable &&
231-
p.Entity is ISoftDelete)
234+
.Where(p => p.Entity is ITrackable && p.Entity is ISoftDelete)
232235
.Select(x => new
233236
{
234237
x.State,
@@ -250,35 +253,5 @@ p.Entity is ITrackable &&
250253
}
251254
}
252255
}
253-
254-
private static void UpdateEntityMetadata(IEnumerable<DbEntityEntry> entries)
255-
{
256-
var now = DateTime.UtcNow;
257-
var trackableItems = entries.Where(p => p.Entity is ITrackable);
258-
259-
foreach (var entry in trackableItems)
260-
{
261-
if (entry.Entity is ITrackable trackableEntry)
262-
{
263-
var userId = string.Empty;
264-
if (HttpContext.Current != null && HttpContext.Current.User != null)
265-
{
266-
userId = HttpContext.Current.User.Identity.GetUserId();
267-
}
268-
269-
if (entry.State == EntityState.Added)
270-
{
271-
trackableEntry.Created = now;
272-
trackableEntry.Modified = now;
273-
trackableEntry.CreatedBy = userId;
274-
}
275-
else if (entry.State == EntityState.Deleted || entry.State == EntityState.Modified)
276-
{
277-
trackableEntry.Modified = now;
278-
trackableEntry.ModifiedBy = userId;
279-
}
280-
}
281-
}
282-
}
283256
}
284257
}

src/api/Shrooms.Domain/Services/Kudos/KudosService.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -479,8 +479,9 @@ public decimal[] GetMonthlyKudosStatistics(string id)
479479

480480
if (sentThisMonth < BusinessLayerConstants.KudosAvailableToSendThisMonth)
481481
{
482-
available = BusinessLayerConstants.KudosAvailableToSendThisMonth - sentThisMonth < remaining ?
483-
BusinessLayerConstants.KudosAvailableToSendThisMonth - sentThisMonth : remaining;
482+
available = BusinessLayerConstants.KudosAvailableToSendThisMonth - sentThisMonth < remaining
483+
? BusinessLayerConstants.KudosAvailableToSendThisMonth - sentThisMonth
484+
: remaining;
484485
}
485486

486487
return new[] { sentThisMonth, available < 0 ? 0 : available };
@@ -532,6 +533,9 @@ private void AddKudosRequest(AddKudosLogDTO kudosLog, decimal? points = null)
532533
.Where(x => kudosLog.ReceivingUserIds.Contains(x.Id) && x.OrganizationId == kudosLog.OrganizationId)
533534
.ToList();
534535

536+
var sendingUser = _usersDbSet
537+
.FirstOrDefault(x => x.Id == kudosDto.SendingUser.Id && x.OrganizationId == kudosLog.OrganizationId);
538+
535539
_kudosServiceValidator.CheckForEmptyUserList(receivingUsers);
536540

537541
foreach (var receivingUser in receivingUsers)
@@ -550,12 +554,10 @@ private void AddKudosRequest(AddKudosLogDTO kudosLog, decimal? points = null)
550554

551555
foreach (var receivingUser in receivingUsers)
552556
{
553-
kudosDto.ReceivingUser = _mapper.Map<ApplicationUserDTO>(receivingUser);
554557
_asyncRunner.Run<IKudosNotificationService>(n => n.NotifyAboutKudosSent(kudosDto), _uow.ConnectionName);
555558
UpdateProfileKudos(receivingUser, kudosLog);
556559
}
557560

558-
var sendingUser = _mapper.Map<ApplicationUser>(kudosDto.SendingUser);
559561
UpdateProfileKudos(sendingUser, kudosLog);
560562
}
561563

@@ -595,7 +597,7 @@ public IEnumerable<KudosBasicDataDTO> GetKudosStats(int months, int amount, int
595597
public void UpdateProfileKudos(ApplicationUser user, UserAndOrganizationDTO userOrg)
596598
{
597599
SetKudosToUserProfile(user, userOrg);
598-
_uow.SaveChanges();
600+
_uow.SaveChanges(userOrg.UserId);
599601
}
600602

601603
public void UpdateProfilesFromUserIds(IEnumerable<string> usersId, UserAndOrganizationDTO userOrg)
@@ -640,7 +642,7 @@ private void SetKudosToUserProfile(ApplicationUser user, UserAndOrganizationDTO
640642
public bool HasPendingKudos(string employeeId)
641643
{
642644
IList<KudosLog> kudosLogs = _kudosLogsDbSet.Where(e => e.EmployeeId == employeeId &&
643-
e.Status == KudosStatus.Pending).ToList();
645+
e.Status == KudosStatus.Pending).ToList();
644646

645647
return kudosLogs.Any();
646648
}

src/webapp/src/client/app/committee/committee-new-edit-modal.html

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,10 @@ <h4 ng-show="edit" class="modal-title"><span>{{"committee.editCommittee" | trans
5858
add-on-space="true"
5959
add-on-comma="true"
6060
placeholder="{{'committee.leadsPlaceHolder' | translate}}"
61+
replace-spaces-with-dashes="false"
6162
add-on-blur="true"
6263
wrapped>
63-
<auto-complete source="allUsers($query)" min-length="0" max-results-to-show="5" debounce-delay="500"></auto-complete>
64+
<auto-complete source="allUsers($query)" min-length="1" max-results-to-show="5" debounce-delay="500"></auto-complete>
6465
</tags-input>
6566
<p data-test-id="newCommitteeLeadsError"
6667
ng-show="!committee.leads.length && !newCommittee.leads.$pristine"
@@ -82,7 +83,7 @@ <h4 ng-show="edit" class="modal-title"><span>{{"committee.editCommittee" | trans
8283
replace-spaces-with-dashes="false"
8384
add-on-blur="true"
8485
wrapped>
85-
<auto-complete source="allUsers($query)" min-length="0" max-results-to-show="5" debounce-delay="500"></auto-complete>
86+
<auto-complete source="allUsers($query)" min-length="1" max-results-to-show="5" debounce-delay="500"></auto-complete>
8687
</tags-input>
8788
<p data-test-id="newCommitteeMembersError"
8889
ng-show="!committee.members.length && !newCommittee.members.$pristine"
@@ -101,9 +102,10 @@ <h4 ng-show="edit" class="modal-title"><span>{{"committee.editCommittee" | trans
101102
add-on-space="true"
102103
add-on-comma="true"
103104
placeholder="{{'committee.delegatesPlaceHolder' | translate}}"
105+
replace-spaces-with-dashes="false"
104106
add-on-blur="true"
105107
wrapped>
106-
<auto-complete source="allUsers($query)" min-length="0" max-results-to-show="5" debounce-delay="500"></auto-complete>
108+
<auto-complete source="allUsers($query)" min-length="1" max-results-to-show="5" debounce-delay="500"></auto-complete>
107109
</tags-input>
108110
<p data-test-id="newCommitteeDelegatesError"
109111
ng-show="!committee.delegates.length && !newCommittee.delegates.$pristine"

src/webapp/src/client/app/common/directives/item-filter-panel/item-filter-panel.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
add-on-comma="true"
2222
on-tag-added="vm.executeFilter()"
2323
on-tag-removed="vm.executeFilter()"
24+
replace-spaces-with-dashes="false"
2425
add-on-blur="true" wrapped translate-cloak>
2526
<auto-complete source="item.load($query)" min-length="1" max-results-to-show="20" debounce-delay="500">
2627
</auto-complete>

src/webapp/src/client/app/customization/service-request-types/create-edit/create-edit.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,10 @@
5353
add-on-space="true"
5454
add-on-comma="true"
5555
placeholder="{{'customization.assigneesPlaceHolder' | translate}}"
56+
replace-spaces-with-dashes="false"
5657
add-on-blur="true"
5758
wrapped>
58-
<auto-complete source="vm.allUsers($query)" min-length="0" max-results-to-show="5" debounce-delay="500"></auto-complete>
59+
<auto-complete source="vm.allUsers($query)" min-length="1" max-results-to-show="5" debounce-delay="500"></auto-complete>
5960
</tags-input>
6061
</div>
6162
</div>

src/webapp/src/client/app/events/join/join-options/join-options.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ <h3 ng-if="!vm.options.length && !vm.isAddColleague" class="modal-title" transla
3232
<tags-input ng-if="vm.isAddColleague" id="participants" name="participants" ng-model="vm.participants"
3333
add-from-autocomplete-only="true" display-property="fullName"
3434
ng-attr-placeholder="{{'events.addFriends' | translate}}" add-on-enter="true" add-on-space="true"
35-
add-on-comma="true" add-on-blur="true" wrapped translate-cloak>
36-
<auto-complete source="vm.getUserForAutoComplete($query)" min-length="0" max-results-to-show="5"
35+
add-on-comma="true" add-on-blur="true" replace-spaces-with-dashes="false" wrapped translate-cloak>
36+
<auto-complete source="vm.getUserForAutoComplete($query)" min-length="1" max-results-to-show="5"
3737
debounce-delay="500"></auto-complete>
3838
</tags-input>
3939

src/webapp/src/client/app/kudos/kudosify-modal/kudosify-modal.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ <h3 class="modal-title" ng-if="vm.isSendModal()" translate="kudos.sayThankYouAnd
3030
add-on-enter="true"
3131
add-on-space="true"
3232
add-on-comma="true"
33+
replace-spaces-with-dashes="false"
3334
add-on-blur="true"
3435
placeholder="{{'kudos.addPeople' | translate}}"
3536
data-test-id="kudosify-multiple-users-input" wrapped translate-cloak>

src/webapp/src/client/app/office/floor/room/room-manage-popup.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ <h4 class="modal-title"><span>{{"room.roomData" | translate}}</span></h4>
2121
</div>
2222
<div class="form-group">
2323
<label for="applicationUsers"><span>{{"room.employees" | translate}}</span></label><br />
24-
<tags-input id="applicationUsers" data-ng-model="model.applicationUsers" data-add-from-autocomplete-only="true" data-display-property="fullName" placeholder="{{'map.addApplicationUserPlaceholder' | translate}}">
25-
<auto-complete data-source="loadApplicationUsers($query)" data-min-length="0" data-max-results-to-show="5" debounce-delay="500"></auto-complete>
24+
<tags-input id="applicationUsers" data-ng-model="model.applicationUsers" replace-spaces-with-dashes="false" data-add-from-autocomplete-only="true" data-display-property="fullName" placeholder="{{'map.addApplicationUserPlaceholder' | translate}}">
25+
<auto-complete data-source="loadApplicationUsers($query)" data-min-length="1" data-max-results-to-show="5" debounce-delay="500"></auto-complete>
2626
</tags-input>
2727
</div>
2828
<div class="form-group">

src/webapp/src/client/app/profile/profile-edit/job-info/job-info.html

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,10 @@
3838
add-on-enter="true"
3939
add-on-space="true"
4040
add-on-comma="true"
41+
replace-spaces-with-dashes="false"
4142
add-on-blur="true"
4243
wrapped>
43-
<auto-complete source="allProjects($query)" min-length="0" max-results-to-show="5" debounce-delay="500"></auto-complete>
44+
<auto-complete source="allProjects($query)" min-length="1" max-results-to-show="5" debounce-delay="500"></auto-complete>
4445
</tags-input>
4546
</input-wrapper>
4647
</div>
@@ -73,6 +74,7 @@
7374
replace-spaces-with-dashes="false"
7475
add-on-enter="true"
7576
add-on-comma="false"
77+
replace-spaces-with-dashes="false"
7678
add-on-blur="true"
7779
min-length="1"
7880
wrapped>
@@ -302,9 +304,10 @@
302304
add-on-enter="true"
303305
add-on-space="true"
304306
add-on-comma="true"
307+
replace-spaces-with-dashes="false"
305308
add-on-blur="true"
306309
wrapped>
307-
<auto-complete source="allRoles($query)" min-length="0" max-results-to-show="5" debounce-delay="500"></auto-complete>
310+
<auto-complete source="allRoles($query)" min-length="1" max-results-to-show="5" debounce-delay="500"></auto-complete>
308311
</tags-input>
309312
</input-wrapper>
310313

src/webapp/src/client/app/project/create/create-edit.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,10 @@
7777
add-on-enter="true"
7878
add-on-space="true"
7979
add-on-comma="true"
80+
replace-spaces-with-dashes="false"
8081
add-on-blur="true"
8182
wrapped>
82-
<auto-complete debounce-delay="500" source="vm.autocompleteUser($query)" min-length="0" max-results-to-show="5"></auto-complete>
83+
<auto-complete debounce-delay="500" source="vm.autocompleteUser($query)" min-length="1" max-results-to-show="5"></auto-complete>
8384
</tags-input>
8485
</div>
8586
</div>

0 commit comments

Comments
 (0)