Пример #1
0
        public async Task <DeleteUserResults> DeleteUserAsync(int departmentId, string authorizingUserId, string userIdToDelete)
        {
            if (!await _authorizationService.CanUserDeleteUserAsync(departmentId, authorizingUserId, userIdToDelete))
            {
                return(DeleteUserResults.UnAuthroized);
            }

            var department = await _departmentsService.GetDepartmentByUserIdAsync(userIdToDelete);

            if (department.ManagingUserId == userIdToDelete)
            {
                return(DeleteUserResults.UserIsManagingDepartmentAdmin);
            }

            var member = await _departmentsService.GetDepartmentMemberAsync(userIdToDelete, departmentId);

            member.IsDeleted = true;
            await _departmentsService.SaveDepartmentMemberAsync(member);

            //_certificationService.DeleteAllCertificationsForUser(userIdToDelete);
            //_distributionListsService.RemoveUserFromAllLists(userIdToDelete);
            //_personnelRolesService.RemoveUserFromAllRoles(userIdToDelete);
            //_userStateService.DeleteStatesForUser(userIdToDelete);
            //_workLogsService.ClearInvestigationByLogsForUser(userIdToDelete);
            //_workLogsService.DeleteLogsForUser(userIdToDelete, department.ManagingUserId);
            //_messageService.DeleteMessagesForUser(userIdToDelete);
            ////_userProfileService.DeletProfileForUser(userIdToDelete);
            //_pushUriService.DeletePushUrisForUser(userIdToDelete);
            //_actionLogsService.DeleteActionLogsForUser(userIdToDelete);
            //_callsService.DeleteDispatchesForUserAndRemapCalls(department.ManagingUserId, userIdToDelete);
            //_departmentGroupsService.DeleteUserFromGroups(userIdToDelete);
            //_usersService.DeleteUser(userIdToDelete);

            return(DeleteUserResults.NoFailure);
        }
Пример #2
0
        public async Task <bool> EnqueueMessageBroadcastAsync(MessageQueueItem mqi, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (Config.SystemBehaviorConfig.IsAzure)
            {
                if (!String.IsNullOrWhiteSpace(mqi.Message.ReceivingUserId))
                {
                    var dm = await _departmentsService.GetDepartmentMemberAsync(mqi.Message.ReceivingUserId, mqi.DepartmentId);

                    string departmentNumber = await _departmentSettingsService.GetTextToCallNumberForDepartmentAsync(dm.DepartmentId);

                    mqi.DepartmentTextNumber = departmentNumber;

                    if (mqi.Message.ReceivingUser == null)
                    {
                        var user = mqi.Profiles.FirstOrDefault(x => x.UserId == mqi.Message.ReceivingUserId);

                        if (user != null && user.User != null)
                        {
                            mqi.Message.ReceivingUser = user.User;
                        }
                    }
                }
                else if (!String.IsNullOrWhiteSpace(mqi.Message.SendingUserId))
                {
                    var dm = await _departmentsService.GetDepartmentMemberAsync(mqi.Message.SendingUserId, mqi.DepartmentId);

                    string departmentNumber = await _departmentSettingsService.GetTextToCallNumberForDepartmentAsync(dm.DepartmentId);

                    mqi.DepartmentTextNumber = departmentNumber;
                }

                return(await _outboundQueueProvider.EnqueueMessage(mqi));
            }
            else
            {
                QueueItem item = new QueueItem();
                item.QueueType = (int)QueueTypes.MessageBroadcast;
                item.SourceId  = mqi.Message.MessageId.ToString();
                item.QueuedOn  = DateTime.UtcNow;

                await _queueItemsRepository.SaveOrUpdateAsync(item, cancellationToken);
            }

            return(true);
        }
Пример #3
0
        public async Task <ActionResult> SetStaffingForUser(StaffingInput staffingInput, CancellationToken cancellationToken)
        {
            if (this.ModelState.IsValid)
            {
                try
                {
                    UserState savedState         = null;
                    var       userToSetStatusFor = await _departmentsService.GetDepartmentMemberAsync(staffingInput.Uid, DepartmentId);

                    if (userToSetStatusFor == null)
                    {
                        return(NotFound());
                    }

                    if (!await _authorizationService.IsUserValidWithinLimitsAsync(staffingInput.Uid, DepartmentId))
                    {
                        return(Unauthorized());
                    }

                    if (!await _authorizationService.IsUserValidWithinLimitsAsync(userToSetStatusFor.UserId, DepartmentId))
                    {
                        return(Unauthorized());
                    }

                    // TODO: We need to check here if the user is a department admin, or the admin that the user is a part of

                    if (String.IsNullOrWhiteSpace(staffingInput.Not))
                    {
                        savedState = await _userStateService.CreateUserState(userToSetStatusFor.UserId, DepartmentId, staffingInput.Typ, cancellationToken);
                    }
                    else
                    {
                        savedState = await _userStateService.CreateUserState(userToSetStatusFor.UserId, DepartmentId, staffingInput.Typ, staffingInput.Not, cancellationToken);
                    }

                    return(CreatedAtAction(nameof(SetStaffingForUser), new { id = savedState.UserStateId }, savedState));
                }
                catch (Exception ex)
                {
                    Logging.LogException(ex);
                    return(BadRequest());
                }
            }

            return(BadRequest());
        }
Пример #4
0
        public async Task <ActionResult> SetStatusForUser(StatusInput statusInput, CancellationToken cancellationToken)
        {
            if (this.ModelState.IsValid)
            {
                try
                {
                    var userToSetStatusFor = await _departmentsService.GetDepartmentMemberAsync(statusInput.Uid, DepartmentId);

                    if (userToSetStatusFor == null)
                    {
                        return(NotFound());
                    }

                    if (!await _authorizationService.IsUserValidWithinLimitsAsync(statusInput.Uid, DepartmentId))
                    {
                        return(Unauthorized());
                    }

                    if (!await _authorizationService.IsUserValidWithinLimitsAsync(userToSetStatusFor.UserId, DepartmentId))
                    {
                        return(Unauthorized());
                    }

                    if (DepartmentId != userToSetStatusFor.DepartmentId)
                    {
                        return(Unauthorized());
                    }

                    // TODO: We need to check here if the user is a department admin, or the admin that the user is a part of

                    ActionLog log = null;
                    if (statusInput.Rto == 0)
                    {
                        log = await _actionLogsService.SetUserActionAsync(statusInput.Uid, DepartmentId, statusInput.Typ, statusInput.Geo, cancellationToken);
                    }
                    else if (statusInput.Dtp == 0)
                    {
                        log = await _actionLogsService.SetUserActionAsync(statusInput.Uid, DepartmentId, statusInput.Typ, statusInput.Geo, statusInput.Rto, statusInput.Not, cancellationToken);
                    }
                    else
                    {
                        log = await _actionLogsService.SetUserActionAsync(statusInput.Uid, DepartmentId, statusInput.Typ, statusInput.Geo, statusInput.Rto, cancellationToken);
                    }


                    //OutboundEventProvider.PersonnelStatusChangedTopicHandler handler = new OutboundEventProvider.PersonnelStatusChangedTopicHandler();
                    //await handler.Handle(new UserStatusEvent() { DepartmentId = DepartmentId, Status = log });
                    _eventAggregator.SendMessage <UserStatusEvent>(new UserStatusEvent()
                    {
                        DepartmentId = DepartmentId, Status = log
                    });

                    return(CreatedAtAction(nameof(SetStatusForUser), new { id = log.ActionLogId }, log));
                }
                catch (Exception ex)
                {
                    Logging.LogException(ex);
                    return(BadRequest());
                }
            }

            return(BadRequest());
        }
Пример #5
0
        public async Task <ActionResult <ProfileResult> > GetProfile()
        {
            var profile = await _userProfileService.GetProfileByUserIdAsync(UserId.ToUpper(), true);

            if (profile == null)
            {
                return(NotFound());
            }

            var department = await _departmentsService.GetDepartmentByIdAsync(DepartmentId);

            var dm = await _departmentsService.GetDepartmentMemberAsync(UserId.ToUpper(), DepartmentId);

            var membership = _usersService.GetMembershipByUserId(UserId.ToUpper());

            var result = new ProfileResult
            {
                Uid = UserId.ToUpper().ToString(),
                Adm = department.IsUserAnAdmin(UserId.ToUpper()),
                Hid = dm.IsHidden.GetValueOrDefault(),
                Dis = dm.IsDisabled.GetValueOrDefault(),
                Fnm = profile.FirstName,
                Lnm = profile.LastName,
                Eml = membership.Email,
                Tz  = profile.TimeZone,
                Mob = profile.MobileNumber,
                Moc = profile.MobileCarrier,
                Hmn = profile.HomeNumber,
                Sce = profile.SendEmail,
                Scp = profile.SendPush,
                Scs = profile.SendSms,
                Sme = profile.SendMessageEmail,
                Smp = profile.SendMessagePush,
                Sms = profile.SendMessageSms,
                Sne = profile.SendNotificationEmail,
                Snp = profile.SendNotificationPush,
                Sns = profile.SendNotificationSms,
                Id  = profile.IdentificationNumber,
                Val = await _limitsService.CanDepartmentUseVoiceAsync(DepartmentId),
                Voc = profile.VoiceForCall,
                Vcm = profile.VoiceCallMobile,
                Vch = profile.VoiceCallHome,
                Lup = profile.LastUpdated
            };

            if (membership.LockoutEnd.HasValue)
            {
                result.Lkd = true;
            }
            else
            {
                result.Lkd = false;
            }

            if (profile.HomeAddressId.HasValue)
            {
                var address = await _addressService.GetAddressByIdAsync(profile.HomeAddressId.Value);

                if (address != null)
                {
                    result.Hme = new AddressResult()
                    {
                        Aid = address.AddressId,
                        Str = address.Address1,
                        Cty = address.City,
                        Ste = address.State,
                        Zip = address.PostalCode,
                        Cnt = address.Country
                    };
                }
            }

            if (profile.MailingAddressId.HasValue)
            {
                var address = await _addressService.GetAddressByIdAsync(profile.MailingAddressId.Value);

                if (address != null)
                {
                    result.Mal = new AddressResult()
                    {
                        Aid = address.AddressId,
                        Str = address.Address1,
                        Cty = address.City,
                        Ste = address.State,
                        Zip = address.PostalCode,
                        Cnt = address.Country
                    };
                }
            }

            return(Ok(result));
        }
Пример #6
0
        public async Task <IActionResult> EditUserProfile(string userId)
        {
            var model = new EditProfileModel();

            model.ApiUrl     = Config.SystemBehaviorConfig.ResgridApiBaseUrl;
            model.Department = await _departmentsService.GetDepartmentByIdAsync(DepartmentId);

            var departmentMember = await _departmentsService.GetDepartmentMemberAsync(userId, DepartmentId);

            if (!await _authorizationService.CanUserEditProfileAsync(UserId, DepartmentId, userId))
            {
                Unauthorized();
            }

            var groups       = new List <DepartmentGroup>();
            var defaultGroup = new DepartmentGroup();

            defaultGroup.Name = "No Group";
            groups.Add(defaultGroup);
            groups.AddRange(await _departmentGroupsService.GetAllGroupsForDepartmentAsync(model.Department.DepartmentId));

            ViewBag.Carriers  = model.Carrier.ToSelectList();
            ViewBag.Countries = new SelectList(Countries.CountryNames);
            ViewBag.TimeZones = new SelectList(TimeZones.Zones, "Key", "Value");

            model.Groups = new SelectList(groups, "DepartmentGroupId", "Name");
            var group = await _departmentGroupsService.GetGroupForUserAsync(userId, DepartmentId);

            if (group != null)
            {
                model.UserGroup        = group.DepartmentGroupId;
                model.IsUserGroupAdmin = group.IsUserGroupAdmin(userId);
            }

            //model.UsersRoles = await _personnelRolesService.GetRolesForUser(userId);
            model.IsDisabled        = departmentMember.IsDisabled.HasValue != false && departmentMember.IsDisabled.Value;
            model.IsHidden          = departmentMember.IsHidden.HasValue != false && departmentMember.IsHidden.Value;
            model.IsDepartmentAdmin = departmentMember.IsAdmin.HasValue != false && departmentMember.IsAdmin.Value;
            model.CanEnableVoice    = await _limitsService.CanDepartmentUseVoiceAsync(DepartmentId);

            if (userId == UserId)
            {
                model.IsOwnProfile = true;
            }

            model.User   = _usersService.GetUserById(userId, true);
            model.UserId = userId;
            model.Email  = model.User.Email;

            model.Profile = await _userProfileService.GetProfileByUserIdAsync(userId, true);

            if (model.Profile == null)
            {
                model.Profile = new UserProfile();
            }

            if (model.Profile.Image == null)
            {
                model.HasCustomIamge = false;
            }
            else
            {
                model.HasCustomIamge = true;
            }

            if (model.Profile != null && model.Profile.HomeAddressId.HasValue)
            {
                var homeAddress = await _addressService.GetAddressByIdAsync(model.Profile.HomeAddressId.Value);

                model.PhysicalAddress1   = homeAddress.Address1;
                model.PhysicalCity       = homeAddress.City;
                model.PhysicalCountry    = homeAddress.Country;
                model.PhysicalPostalCode = homeAddress.PostalCode;
                model.PhysicalState      = homeAddress.State;
            }

            if (model.Profile != null && model.Profile.MailingAddressId.HasValue && model.Profile.HomeAddressId.HasValue &&
                (model.Profile.MailingAddressId.Value == model.Profile.HomeAddressId.Value))
            {
                model.MailingAddressSameAsPhysical = true;
            }
            else if (model.Profile != null && model.Profile.MailingAddressId.HasValue)
            {
                var mailingAddress = await _addressService.GetAddressByIdAsync(model.Profile.MailingAddressId.Value);

                model.MailingAddress1   = mailingAddress.Address1;
                model.MailingCity       = mailingAddress.City;
                model.MailingCountry    = mailingAddress.Country;
                model.MailingPostalCode = mailingAddress.PostalCode;
                model.MailingState      = mailingAddress.State;
            }

            if (model.Profile != null)
            {
                model.Carrier = (MobileCarriers)model.Profile.MobileCarrier;
            }

            if (!String.IsNullOrEmpty(model.Profile.FirstName) && !String.IsNullOrEmpty(model.Profile.LastName))
            {
                model.FirstName = model.Profile.FirstName;
                model.LastName  = model.Profile.LastName;
            }
            else
            {
                //MembershipUser currentUser = Membership.GetUser(model.User.UserName, userIsOnline: true);
                //var pfile = ProfileBase.Create(model.User.UserName, true);

                var userProfile = await _userProfileService.GetProfileByUserIdAsync(userId);

                if (userProfile != null)
                {
                    model.FirstName = userProfile.FirstName;
                    model.LastName  = userProfile.LastName;
                }
                else
                {
                    model.FirstName = "";
                    model.LastName  = "";
                }
            }

            model.EnableSms = model.Profile.SendSms;

            return(View(model));
        }
Пример #7
0
        public async Task <ActionResult <DepartmentRightsResult> > GetCurrentUsersRights()
        {
            var result     = new DepartmentRightsResult();
            var department = await _departmentsService.GetDepartmentByIdAsync(DepartmentId, false);

            var departmentMembership = await _departmentsService.GetDepartmentMemberAsync(UserId, DepartmentId, false);

            var roles = await _personnelRolesService.GetRolesForUserAsync(UserId, DepartmentId);

            if (departmentMembership == null)
            {
                return(Unauthorized());
            }

            if (departmentMembership.IsAdmin.HasValue)
            {
                result.Adm = departmentMembership.IsAdmin.Value;
            }

            if (department.ManagingUserId == UserId)
            {
                result.Adm = true;
            }

            bool isGroupAdmin = false;

            result.Grps = new List <GroupRight>();

            var group = await _departmentGroupsService.GetGroupForUserAsync(UserId, DepartmentId);

            if (group != null)
            {
                var groupRight = new GroupRight();
                groupRight.Gid = group.DepartmentGroupId;
                groupRight.Adm = group.IsUserGroupAdmin(UserId);

                if (groupRight.Adm)
                {
                    isGroupAdmin = true;
                }

                result.Grps.Add(groupRight);
            }

            var createCallPermission = await _permissionsService.GetPermissionByDepartmentTypeAsync(DepartmentId, PermissionTypes.CreateCall);

            var viewPIIPermission = await _permissionsService.GetPermissionByDepartmentTypeAsync(DepartmentId, PermissionTypes.ViewPersonalInfo);

            var createNotePermission = await _permissionsService.GetPermissionByDepartmentTypeAsync(DepartmentId, PermissionTypes.CreateNote);

            var createMessagePermission = await _permissionsService.GetPermissionByDepartmentTypeAsync(DepartmentId, PermissionTypes.CreateMessage);

            result.VPii = _permissionsService.IsUserAllowed(viewPIIPermission, result.Adm, isGroupAdmin, roles);
            result.CCls = _permissionsService.IsUserAllowed(createCallPermission, result.Adm, isGroupAdmin, roles);
            result.ANot = _permissionsService.IsUserAllowed(createNotePermission, result.Adm, isGroupAdmin, roles);
            result.CMsg = _permissionsService.IsUserAllowed(createMessagePermission, result.Adm, isGroupAdmin, roles);

            if (!String.IsNullOrWhiteSpace(Config.FirebaseConfig.ResponderJsonFile) && !String.IsNullOrWhiteSpace(Config.FirebaseConfig.ResponderProjectEmail))
            {
                result.FirebaseApiToken = await _firebaseService.CreateTokenAsync(UserId, null);
            }

            return(result);
        }