예제 #1
0
        public IEnumerable <AuditEventWrapper> GetAuditEventsByFilter(Guid userId,
                                                                      ProductType productType,
                                                                      ModuleType moduleType,
                                                                      ActionType actionType,
                                                                      MessageAction action,
                                                                      EntryType entryType,
                                                                      string target,
                                                                      ApiDateTime from,
                                                                      ApiDateTime to)
        {
            SecurityContext.DemandPermissions(SecutiryConstants.EditPortalSettings);

            var startIndex = (int)Context.StartIndex;
            var limit      = (int)Context.Count;

            Context.SetDataPaginated();

            action = action == 0 ? MessageAction.None : action;

            if (!TenantExtra.GetTenantQuota().Audit || !SetupInfo.IsVisibleSettings(ManagementType.LoginHistory.ToString()))
            {
                return(GetLastAuditEvents());
            }
            else
            {
                DemandAuditPermission();

                return(AuditEventsRepository.GetByFilter(userId, productType, moduleType, actionType, action, entryType, target, from, to, startIndex, limit).Select(x => new AuditEventWrapper(x)));
            }
        }
예제 #2
0
        public string CreateAuditTrailReport()
        {
            SecurityContext.DemandPermissions(SecutiryConstants.EditPortalSettings);

            var tenantId = TenantProvider.CurrentTenantID;

            if (!SetupInfo.IsVisibleSettings(ManagementType.AuditTrail.ToString()) ||
                CoreContext.Configuration.Standalone && !CoreContext.TenantManager.GetTenantQuota(tenantId).Audit)
            {
                throw new BillingException(Resource.ErrorNotAllowedOption, "Audit");
            }

            var settings = TenantAuditSettings.LoadForTenant(tenantId);

            var to   = DateTime.UtcNow;
            var from = to.Subtract(TimeSpan.FromDays(settings.AuditTrailLifeTime));

            var reportName = string.Format(AuditReportResource.AuditTrailReportName + ".csv", from.ToString("MM.dd.yyyy"), to.ToString("MM.dd.yyyy"));

            var events = AuditEventsRepository.Get(tenantId, from, to);
            var result = AuditReportCreator.CreateCsvReport(events, reportName);

            MessageService.Send(Request, MessageAction.AuditTrailReportDownloaded);
            return(result);
        }
예제 #3
0
        public EmployeeWraperFull ChangeUserPassword(Guid userid, String password, String email)
        {
            SecurityContext.DemandPermissions(new UserSecurityProvider(userid), Core.Users.Constants.Action_EditUser);

            if (!CoreContext.UserManager.UserExists(userid))
            {
                return(null);
            }

            var user = CoreContext.UserManager.GetUsers(userid);

            if (CoreContext.UserManager.IsSysytemUser(user.ID))
            {
                throw new SecurityException();
            }

            if (!string.IsNullOrEmpty(email))
            {
                var address = new MailAddress(email);
                if (!string.Equals(address.Address, user.Email, StringComparison.OrdinalIgnoreCase))
                {
                    user.Email            = address.Address.ToLowerInvariant();
                    user.ActivationStatus = EmployeeActivationStatus.Activated;
                    CoreContext.UserManager.SaveUserInfo(user);
                }
            }

            if (!string.IsNullOrEmpty(password))
            {
                SecurityContext.SetUserPassword(userid, password);
            }

            return(new EmployeeWraperFull(GetUserInfo(userid.ToString())));
        }
예제 #4
0
        public IEnumerable <EmployeeWraperFull> RemoveUsers(IEnumerable <Guid> userIds)
        {
            SecurityContext.DemandPermissions(Core.Users.Constants.Action_AddRemoveUser);

            var users = userIds.Select(userId => CoreContext.UserManager.GetUsers(userId))
                        .Where(u => !CoreContext.UserManager.IsSystemUser(u.ID) && !u.IsLDAP())
                        .ToList();

            var userNames = users.Select(x => x.DisplayUserName(false)).ToList();

            foreach (var user in users)
            {
                if (user.Status != EmployeeStatus.Terminated)
                {
                    continue;
                }

                UserPhotoManager.RemovePhoto(Guid.Empty, user.ID);
                CoreContext.UserManager.DeleteUser(user.ID);
            }

            MessageService.Send(Request, MessageAction.UsersDeleted, userNames);

            return(users.Select(user => new EmployeeWraperFull(user)).ToSmartList());
        }
        public List <UsageSpaceStatItemWrapper> GetSpaceUsageStatistics(Guid id)
        {
            SecurityContext.DemandPermissions(Tenant, SecutiryConstants.EditPortalSettings);

            var webtem = WebItemManager.Instance.GetItems(Tenant, WebZoneType.All, ItemAvailableState.All)
                         .FirstOrDefault(item =>
                                         item != null &&
                                         item.ID == id &&
                                         item.Context != null &&
                                         item.Context.SpaceUsageStatManager != null);

            if (webtem == null)
            {
                return(new List <UsageSpaceStatItemWrapper>());
            }

            return(webtem.Context.SpaceUsageStatManager.GetStatData()
                   .ConvertAll(it => new UsageSpaceStatItemWrapper
            {
                Name = it.Name.HtmlEncode(),
                Icon = it.ImgUrl,
                Disabled = it.Disabled,
                Size = FileSizeComment.FilesSizeToString(it.SpaceUsage),
                Url = it.Url
            }));
        }
예제 #6
0
        private void UpdatePhotoUrl(string files, UserInfo user)
        {
            if (string.IsNullOrEmpty(files))
            {
                return;
            }

            SecurityContext.DemandPermissions(new UserSecurityProvider(user.ID), Core.Users.Constants.Action_EditUser);

            if (!files.StartsWith("http://") && !files.StartsWith("https://"))
            {
                files = _context.RequestContext.HttpContext.Request.Url.GetLeftPart(UriPartial.Scheme | UriPartial.Authority) + "/" + files.TrimStart('/');
            }
            var request = HttpWebRequest.Create(files);

            using (var response = (HttpWebResponse)request.GetResponse())
            {
                using (var inputStream = response.GetResponseStream())
                    using (var br = new BinaryReader(inputStream))
                    {
                        var imageByteArray = br.ReadBytes((int)response.ContentLength);
                        UserPhotoManager.SaveOrUpdatePhoto(user.ID, imageByteArray);
                    }
            }
        }
        public GroupWrapperFull UpdateGroup(Guid groupid, GroupModel groupModel)
        {
            SecurityContext.DemandPermissions(Tenant, Constants.Action_EditGroups, Constants.Action_AddRemoveUser);
            var group = CoreContext.UserManager.GetGroups(Tenant.TenantId).SingleOrDefault(x => x.ID == groupid).NotFoundIfNull("group not found");

            if (groupid == Constants.LostGroupInfo.ID)
            {
                throw new ItemNotFoundException("group not found");
            }

            group.Name = groupModel.GroupName ?? group.Name;
            CoreContext.UserManager.SaveGroupInfo(Tenant, group);

            RemoveMembersFrom(new GroupModel {
                Groupid = groupid, Members = CoreContext.UserManager.GetUsersByGroup(Tenant, groupid, EmployeeStatus.All).Select(u => u.ID).Where(id => !groupModel.Members.Contains(id))
            });

            TransferUserToDepartment(groupModel.GroupManager, @group, true);
            if (groupModel.Members != null)
            {
                foreach (var member in groupModel.Members)
                {
                    TransferUserToDepartment(member, group, false);
                }
            }

            MessageService.Send(MessageAction.GroupUpdated, MessageTarget.Create(groupid), group.Name);

            return(GetById(groupModel.Groupid));
        }
예제 #8
0
        public EmployeeWraperFull DeleteMember(string userid)
        {
            SecurityContext.DemandPermissions(Core.Users.Constants.Action_AddRemoveUser);

            var user = GetUserInfo(userid);

            if (CoreContext.UserManager.IsSystemUser(user.ID) || user.IsLDAP())
            {
                throw new SecurityException();
            }

            if (user.Status != EmployeeStatus.Terminated)
            {
                throw new Exception("The user is not suspended");
            }

            var userName = user.DisplayUserName(false);

            UserPhotoManager.RemovePhoto(Guid.Empty, user.ID);
            CoreContext.UserManager.DeleteUser(user.ID);

            MessageService.Send(Request, MessageAction.UserDeleted, userName);

            return(new EmployeeWraperFull(user));
        }
예제 #9
0
        public IEnumerable <AuditEventWrapper> GetLastAuditEvents()
        {
            SecurityContext.DemandPermissions(SecutiryConstants.EditPortalSettings);

            DemandBaseAuditPermission();

            return(AuditEventsRepository.GetByFilter(startIndex: 0, limit: 20).Select(x => new AuditEventWrapper(x)));
        }
예제 #10
0
        public TenantAuditSettings GetAuditSettings()
        {
            SecurityContext.DemandPermissions(SecutiryConstants.EditPortalSettings);

            DemandBaseAuditPermission();

            return(TenantAuditSettings.LoadForTenant(TenantProvider.CurrentTenantID));
        }
예제 #11
0
        public EmployeeWraperFull AddMemberAsActivated(
            bool isVisitor,
            String email,
            String firstname,
            String lastname,
            Guid[] department,
            String title,
            String location,
            String sex,
            ApiDateTime birthday,
            ApiDateTime worksfrom,
            String comment,
            IEnumerable <Contact> contacts,
            String files,
            String password)
        {
            SecurityContext.DemandPermissions(Core.Users.Constants.Action_AddRemoveUser);

            var user = new UserInfo();

            if (String.IsNullOrEmpty(password))
            {
                password = UserManagerWrapper.GeneratePassword();
            }

            //Validate email
            var address = new MailAddress(email);

            user.Email = address.Address;
            //Set common fields
            user.FirstName = firstname;
            user.LastName  = lastname;
            user.Title     = title;
            user.Location  = location;
            user.Notes     = comment;
            user.Sex       = "male".Equals(sex, StringComparison.OrdinalIgnoreCase)
                           ? true
                           : ("female".Equals(sex, StringComparison.OrdinalIgnoreCase) ? (bool?)false : null);

            user.BirthDate = birthday != null?TenantUtil.DateTimeFromUtc(Convert.ToDateTime(birthday)) : (DateTime?)null;

            user.WorkFromDate = worksfrom != null?TenantUtil.DateTimeFromUtc(Convert.ToDateTime(worksfrom)) : DateTime.UtcNow.Date;

            UpdateContacts(contacts, user);

            user = UserManagerWrapper.AddUser(user, password, false, false, isVisitor);

            user.ActivationStatus = EmployeeActivationStatus.Activated;

            UpdateDepartments(department, user);

            if (files != UserPhotoManager.GetDefaultPhotoAbsoluteWebPath())
            {
                UpdatePhotoUrl(files, user);
            }

            return(new EmployeeWraperFull(user));
        }
        public TenantVersionWrapper SetVersion(SettingsModel model)
        {
            SecurityContext.DemandPermissions(Tenant, SecutiryConstants.EditPortalSettings);

            CoreContext.TenantManager.GetTenantVersions().FirstOrDefault(r => r.Id == model.VersionId).NotFoundIfNull();
            CoreContext.TenantManager.SetTenantVersion(Tenant, model.VersionId);

            return(GetVersions());
        }
        public List <StorageWrapper> GetAllStorages()
        {
            SecurityContext.DemandPermissions(Tenant, SecutiryConstants.EditPortalSettings);

            var current   = StorageSettings.Load();
            var consumers = ConsumerFactory.GetAll <DataStoreConsumer>().ToList();

            return(consumers.Select(consumer => new StorageWrapper(consumer, current)).ToList());
        }
예제 #14
0
        public GroupWrapperFull DeleteGroup(Guid groupid)
        {
            SecurityContext.DemandPermissions(Core.Users.Constants.Action_EditGroups, Core.Users.Constants.Action_AddRemoveUser);
            var @group           = GetGroupInfo(groupid);
            var groupWrapperFull = new GroupWrapperFull(group, false);

            CoreContext.GroupManager.DeleteGroup(groupid);

            return(groupWrapperFull);
        }
예제 #15
0
        public TenantVersionWrapper SetVersion(int versionId)
        {
            SecurityContext.DemandPermissions(SecutiryConstants.EditPortalSettings);
            CoreContext.TenantManager.GetTenantVersions().FirstOrDefault(r => r.Id == versionId).NotFoundIfNull();

            var tenant = CoreContext.TenantManager.GetCurrentTenant(false);

            CoreContext.TenantManager.SetTenantVersion(tenant, versionId);
            return(GetVersions());
        }
        public void ResetCdnToDefault()
        {
            SecurityContext.DemandPermissions(Tenant, SecutiryConstants.EditPortalSettings);
            if (!CoreContext.Configuration.Standalone)
            {
                return;
            }

            CdnStorageSettings.Load().Clear();
        }
        public GroupWrapperFull RemoveMembersFrom(GroupModel groupModel)
        {
            SecurityContext.DemandPermissions(Tenant, Constants.Action_EditGroups, Constants.Action_AddRemoveUser);
            var group = GetGroupInfo(groupModel.Groupid);

            foreach (var userId in groupModel.Members)
            {
                RemoveUserFromDepartment(userId, group);
            }
            return(GetById(group.ID));
        }
예제 #18
0
        public GroupWrapperFull RemoveMembersFrom(Guid groupid, IEnumerable <Guid> members)
        {
            SecurityContext.DemandPermissions(Core.Users.Constants.Action_EditGroups, Core.Users.Constants.Action_AddRemoveUser);
            var group = GetGroupInfo(groupid);

            foreach (var userId in members)
            {
                RemoveUserFromDepartment(userId, group);
            }
            return(GetById(group.ID));
        }
        public void RemoveUserFromGroup(Tenant tenant, Guid userId, Guid groupId)
        {
            if (Constants.LostUser.ID == userId || Constants.LostGroupInfo.ID == groupId)
            {
                return;
            }
            SecurityContext.DemandPermissions(tenant, Constants.Action_EditGroups);

            userService.RemoveUserGroupRef(tenant.TenantId, userId, groupId, UserGroupRefType.Contains);

            ResetGroupCache(userId);
        }
        public double GetStorageProgress()
        {
            SecurityContext.DemandPermissions(Tenant, SecutiryConstants.EditPortalSettings);

            if (!CoreContext.Configuration.Standalone)
            {
                return(-1);
            }

            using var migrateClient = new ServiceClient();
            return(migrateClient.GetProgress(Tenant.TenantId));
        }
        public IPRestrictionsSettings UpdateIpRestrictionsSettings(IpRestrictionsModel model)
        {
            SecurityContext.DemandPermissions(Tenant, SecutiryConstants.EditPortalSettings);

            var settings = new IPRestrictionsSettings {
                Enable = model.Enable
            };

            settings.Save();

            return(settings);
        }
        public string SaveDefaultPageSettings(SettingsModel model)
        {
            SecurityContext.DemandPermissions(Tenant, SecutiryConstants.EditPortalSettings);

            new StudioDefaultPageSettings {
                DefaultProductID = model.DefaultProductID
            }.Save();

            MessageService.Send(MessageAction.DefaultStartPageSettingsUpdated);

            return(Resource.SuccessfullySaveSettingsMessage);
        }
예제 #23
0
        public string SaveDefaultPageSettings(string defaultProductID)
        {
            SecurityContext.DemandPermissions(SecutiryConstants.EditPortalSettings);

            new StudioDefaultPageSettings {
                DefaultProductID = new Guid(defaultProductID)
            }.Save();

            MessageService.Send(HttpContext.Current.Request, MessageAction.DefaultStartPageSettingsUpdated);

            return(Resource.SuccessfullySaveSettingsMessage);
        }
예제 #24
0
        public IPRestrictionsSettings UpdateIpRestrictionsSettings(bool enable)
        {
            SecurityContext.DemandPermissions(SecutiryConstants.EditPortalSettings);

            var settings = new IPRestrictionsSettings {
                Enable = enable
            };

            settings.Save();

            return(settings);
        }
예제 #25
0
        public UserInfo SaveUserInfo(UserInfo u, bool isVisitor = false)
        {
            if (IsSystemUser(u.ID))
            {
                return(systemUsers[u.ID]);
            }
            if (u.ID == Guid.Empty)
            {
                SecurityContext.DemandPermissions(Constants.Action_AddRemoveUser);
            }
            else
            {
                SecurityContext.DemandPermissions(new UserSecurityProvider(u.ID), Constants.Action_EditUser);
            }

            if (!CoreContext.Configuration.Personal)
            {
                if (Constants.MaxEveryoneCount <= GetUsersByGroup(Constants.GroupEveryone.ID).Length)
                {
                    throw new TenantQuotaException("Maximum number of users exceeded");
                }

                if (u.Status == EmployeeStatus.Active)
                {
                    if (isVisitor)
                    {
                        var maxUsers = CoreContext.TenantManager.GetTenantQuota(CoreContext.TenantManager.GetCurrentTenant().TenantId).ActiveUsers;

                        if (!CoreContext.Configuration.Standalone && CoreContext.UserManager.GetUsersByGroup(Constants.GroupVisitor.ID).Length > Constants.CoefficientOfVisitors * maxUsers)
                        {
                            throw new TenantQuotaException("Maximum number of visitors exceeded");
                        }
                    }
                    else
                    {
                        var q = CoreContext.TenantManager.GetTenantQuota(CoreContext.TenantManager.GetCurrentTenant().TenantId);
                        if (q.ActiveUsers < GetUsersByGroup(Constants.GroupUser.ID).Length)
                        {
                            throw new TenantQuotaException(string.Format("Exceeds the maximum active users ({0})", q.ActiveUsers));
                        }
                    }
                }
            }

            if (u.Status == EmployeeStatus.Terminated && u.ID == CoreContext.TenantManager.GetCurrentTenant().OwnerId)
            {
                throw new InvalidOperationException("Can not disable tenant owner.");
            }

            var newUser = userService.SaveUser(CoreContext.TenantManager.GetCurrentTenant().TenantId, u);

            return(newUser);
        }
예제 #26
0
        public IEnumerable <AuditEventWrapper> GetLastAuditEvents()
        {
            SecurityContext.DemandPermissions(SecutiryConstants.EditPortalSettings);

            if (!SetupInfo.IsVisibleSettings(ManagementType.AuditTrail.ToString()) ||
                CoreContext.Configuration.Standalone && !CoreContext.TenantManager.GetTenantQuota(TenantProvider.CurrentTenantID).Audit)
            {
                throw new BillingException(Resource.ErrorNotAllowedOption, "Audit");
            }

            return(AuditEventsRepository.GetLast(TenantProvider.CurrentTenantID, 20).Select(x => new AuditEventWrapper(x)));
        }
예제 #27
0
        public void RemoveUserFromGroup(Guid userId, Guid groupId)
        {
            if (Constants.LostUser.ID == userId || Constants.LostGroupInfo.ID == groupId)
            {
                return;
            }
            SecurityContext.DemandPermissions(Constants.Action_EditGroups);

            userService.RemoveUserGroupRef(CoreContext.TenantManager.GetCurrentTenant().TenantId, userId, groupId, UserGroupRefType.Contains);

            GetUsers(userId).ResetGroupCache();
        }
예제 #28
0
        public void AddUserIntoGroup(Guid userId, Guid groupId)
        {
            if (Constants.LostUser.ID == userId || Constants.LostGroupInfo.ID == groupId)
            {
                return;
            }
            SecurityContext.DemandPermissions(Constants.Action_EditGroups);

            userService.SaveUserGroupRef(
                CoreContext.TenantManager.GetCurrentTenant().TenantId,
                new UserGroupRef(userId, groupId, UserGroupRefType.Contains));
        }
예제 #29
0
        public IPRestrictionsSettings UpdateIpRestrictionsSettings(bool enable)
        {
            SecurityContext.DemandPermissions(SecutiryConstants.EditPortalSettings);

            var settings = new IPRestrictionsSettings {
                Enable = enable
            };

            SettingsManager.Instance.SaveSettings(settings, CurrentTenant);

            return(settings);
        }
        public GroupWrapperFull DeleteGroup(Guid groupid)
        {
            SecurityContext.DemandPermissions(Tenant, Constants.Action_EditGroups, Constants.Action_AddRemoveUser);
            var @group           = GetGroupInfo(groupid);
            var groupWrapperFull = new GroupWrapperFull(group, false, ApiContext);

            CoreContext.UserManager.DeleteGroup(Tenant, groupid);

            MessageService.Send(MessageAction.GroupDeleted, MessageTarget.Create(group.ID), group.Name);

            return(groupWrapperFull);
        }