private UntypedReceive GetUserEmployee()
        {
            void OnMessage(object message)
            {
                switch (message)
                {
                case ReceiveTimeout _:
                    Log.Debug($"Cannot get permissions for '${this.userIdentity}' due to timeout");
                    this.ReplyAndStop();
                    break;

                case EmployeesQuery.Response userEmployee when userEmployee.Employees.Count == 0:
                    Log.Debug($"Cannot find an employee for '{this.userIdentity}'");
                    this.ReplyAndStop();
                    break;

                case EmployeesQuery.Response userEmployee:
                    this.defaultEmployeePermission = ExistingEmployeeDefaultPermission;
                    BulkBumpPermissions(userEmployee.Employees.Select(x => x.Metadata.EmployeeId), SelfPermissions, this.permissionsForEmployees);

                    //that can be fixed (as array, not First(), when DepartmentsQuery starts to
                    //support arrays for Heads and DepartmentIds
                    this.Become(this.GetOwnDepartments(userEmployee.Employees.First().Metadata));
                    break;

                default:
                    this.Unhandled(message);
                    break;
                }
            }

            this.organizationActor.Tell(EmployeesQuery.Create().WithIdentity(this.userIdentity));
            return(OnMessage);
        }
Beispiel #2
0
 public Permissions(EmployeePermissionsEntry defaultPermission,
                    IReadOnlyDictionary <string, EmployeePermissionsEntry> departmentPermissions,
                    IReadOnlyDictionary <string, EmployeePermissionsEntry> employeePermissions)
 {
     this.defaultPermission     = defaultPermission;
     this.DepartmentPermissions = departmentPermissions;
     this.EmployeePermissions   = employeePermissions;
 }
Beispiel #3
0
 private string[] ExtractPermissionNames(EmployeePermissionsEntry employeePermissionsEntry)
 {
     return(employeePermissionsEntry
            .ToString("G")
            .Split(", ")
            .Select(x =>
     {
         var camelCased = char.ToLowerInvariant(x[0]) + x.Substring(1);
         return camelCased;
     })
            .ToArray());
 }
 private static void BulkBumpPermissions(IEnumerable <string> entriesIds,
                                         EmployeePermissionsEntry permissionSet,
                                         Dictionary <string, EmployeePermissionsEntry> targetPermissionsEntries)
 {
     foreach (var entryId in entriesIds)
     {
         if (targetPermissionsEntries.ContainsKey(entryId))
         {
             targetPermissionsEntries[entryId] |= permissionSet;
         }
         else
         {
             targetPermissionsEntries[entryId] = permissionSet;
         }
     }
 }
Beispiel #5
0
        private static bool CheckIfCancelled(CalendarEvent existingEvent, CalendarEventsModel updatedEvent, EmployeePermissionsEntry employeePermissions)
        {
            var calendarEventStatuses = new CalendarEventStatuses();
            var approvedStatus        = calendarEventStatuses.ApprovedForType(existingEvent.Type);
            var cancelledStatus       = calendarEventStatuses.CancelledForType(updatedEvent.Type);
            var statusChanged         = StatusChanged(existingEvent, updatedEvent);

            if (statusChanged && existingEvent.Status == approvedStatus && updatedEvent.Status == cancelledStatus)
            {
                return(employeePermissions.HasFlag(EmployeePermissionsEntry.CancelApprovedCalendarEvents));
            }

            return(true);
        }
Beispiel #6
0
        private static bool CheckIfRejected(CalendarEvent existingEvent, CalendarEventsModel updatedEvent, EmployeePermissionsEntry employeePermissions)
        {
            var calendarEventStatuses = new CalendarEventStatuses();
            var rejected      = calendarEventStatuses.RejectedForType(existingEvent.Type);
            var statusChanged = StatusChanged(existingEvent, updatedEvent);

            if (statusChanged && updatedEvent.Status == rejected)
            {
                return(employeePermissions.HasFlag(EmployeePermissionsEntry.RejectCalendarEvents));
            }

            return(true);
        }
 public RequiredEmployeePermissions(EmployeePermissionsEntry requiredPermissions)
 {
     this.RequiredPermissions = requiredPermissions;
 }
Beispiel #8
0
 public UserEmployeePermissionsModel(string employeeId, EmployeePermissionsEntry employeePermissionsEntry)
 {
     this.EmployeeId       = employeeId;
     this.PermissionsNames = this.ExtractPermissionNames(employeePermissionsEntry);
 }
        private static bool CheckSickLeave(CalendarEvent existingEvent, CalendarEventsModel updatedEvent, EmployeePermissionsEntry employeePermissions)
        {
            var statusChanged = StatusChanged(existingEvent, updatedEvent);

            if (!statusChanged &&
                updatedEvent.Status == SickLeaveStatuses.Approved &&
                updatedEvent.Dates != existingEvent.Dates)
            {
                return(employeePermissions.HasFlag(EmployeePermissionsEntry.ProlongSickLeave));
            }

            if (statusChanged && updatedEvent.Status == SickLeaveStatuses.Completed)
            {
                return(employeePermissions.HasFlag(EmployeePermissionsEntry.CompleteSickLeave));
            }

            return(true);
        }