/// <summary>
        /// 获取用户当前选中的皮肤
        /// </summary>
        /// <param name="ownerId">拥有者Id(如:用户Id、群组Id)</param>
        /// <returns></returns>
        public string GetThemeAppearance(long ownerId)
        {
            var groupService = new GroupService();
            GroupEntity group = groupService.Get(ownerId);
            if (group == null)
                return string.Empty;
            PresentArea pa = new PresentAreaService().Get(PresentAreaKeysOfBuiltIn.GroupSpace);
            if (pa != null && !pa.EnableThemes)
            {
                return pa.DefaultThemeKey + "," + pa.DefaultAppearanceKey;
            }

            if (group.IsUseCustomStyle)
            {
                return "Default,Default";
            }
            else if (!string.IsNullOrEmpty(group.ThemeAppearance))
            {
                var appearance = new ThemeService().GetThemeAppearance(PresentAreaKeysOfBuiltIn.GroupSpace, group.ThemeAppearance);
                if (appearance != null)
                    return group.ThemeAppearance;
            }

            if (pa != null)
            {
                return pa.DefaultThemeKey + "," + pa.DefaultAppearanceKey;
            }
            return string.Empty;
        }
Exemple #2
0
        /// <summary>
        /// 获取用户当前选中的皮肤
        /// </summary>
        /// <param name="ownerId">拥有者Id(如:用户Id、群组Id)</param>
        /// <returns></returns>
        public string GetThemeAppearance(long ownerId)
        {
            var         groupService = new GroupService();
            GroupEntity group        = groupService.Get(ownerId);

            if (group == null)
            {
                return(string.Empty);
            }
            PresentArea pa = new PresentAreaService().Get(PresentAreaKeysOfBuiltIn.GroupSpace);

            if (pa != null && !pa.EnableThemes)
            {
                return(pa.DefaultThemeKey + "," + pa.DefaultAppearanceKey);
            }

            if (group.IsUseCustomStyle)
            {
                return("Default,Default");
            }
            else if (!string.IsNullOrEmpty(group.ThemeAppearance))
            {
                var appearance = new ThemeService().GetThemeAppearance(PresentAreaKeysOfBuiltIn.GroupSpace, group.ThemeAppearance);
                if (appearance != null)
                {
                    return(group.ThemeAppearance);
                }
            }

            if (pa != null)
            {
                return(pa.DefaultThemeKey + "," + pa.DefaultAppearanceKey);
            }
            return(string.Empty);
        }
        /// <summary>
        /// 更新皮肤
        /// </summary>
        /// <param name="ownerId">拥有者Id(如:用户Id、群组Id)</param>
        /// <param name="isUseCustomStyle">是否使用自定义皮肤</param>
        /// <param name="themeAppearance">themeKey与appearanceKey用逗号关联</param>
        public void ChangeThemeAppearance(long ownerId, bool isUseCustomStyle, string themeAppearance)
        {
            var groupService = new GroupService();
            GroupEntity group = groupService.Get(ownerId);
            if (group == null)
                throw new ExceptionFacade("找不到群组");

            new ThemeService().ChangeThemeAppearanceUserCount(PresentAreaKeysOfBuiltIn.GroupSpace, group.IsUseCustomStyle ? string.Empty : group.ThemeAppearance, isUseCustomStyle ? string.Empty : themeAppearance);
            new GroupService().ChangeThemeAppearance(ownerId, isUseCustomStyle, themeAppearance);
        }
 /// <summary>
 /// 获取接收人UserId集合
 /// </summary>
 /// <param name="activityService">动态业务逻辑类</param>
 /// <param name="activity">动态</param>
 /// <returns></returns>
 IEnumerable<long> IActivityReceiverGetter.GetReceiverUserIds(ActivityService activityService, Activity activity)
 {
     GroupService groupService = new GroupService();
     IEnumerable<long> userIds = groupService.GetUserIdsOfGroup(activity.OwnerId);
     bool isPublic = false;
     var group = groupService.Get(activity.OwnerId);
     if (group != null)
         isPublic = group.IsPublic;
     if (userIds == null)
         return new List<long>();
     return userIds.Where(n => IsReceiveActivity(activityService, isPublic, n, activity));
 }
Exemple #5
0
        /// <summary>
        /// 更新皮肤
        /// </summary>
        /// <param name="ownerId">拥有者Id(如:用户Id、群组Id)</param>
        /// <param name="isUseCustomStyle">是否使用自定义皮肤</param>
        /// <param name="themeAppearance">themeKey与appearanceKey用逗号关联</param>
        public void ChangeThemeAppearance(long ownerId, bool isUseCustomStyle, string themeAppearance)
        {
            var         groupService = new GroupService();
            GroupEntity group        = groupService.Get(ownerId);

            if (group == null)
            {
                throw new ExceptionFacade("找不到群组");
            }

            new ThemeService().ChangeThemeAppearanceUserCount(PresentAreaKeysOfBuiltIn.GroupSpace, group.IsUseCustomStyle ? string.Empty : group.ThemeAppearance, isUseCustomStyle ? string.Empty : themeAppearance);
            new GroupService().ChangeThemeAppearance(ownerId, isUseCustomStyle, themeAppearance);
        }
Exemple #6
0
        /// <summary>
        /// 获取接收人UserId集合
        /// </summary>
        /// <param name="activityService">动态业务逻辑类</param>
        /// <param name="activity">动态</param>
        /// <returns></returns>
        IEnumerable <long> IActivityReceiverGetter.GetReceiverUserIds(ActivityService activityService, Activity activity)
        {
            GroupService       groupService = new GroupService();
            IEnumerable <long> userIds      = groupService.GetUserIdsOfGroup(activity.OwnerId);
            bool isPublic = false;
            var  group    = groupService.Get(activity.OwnerId);

            if (group != null)
            {
                isPublic = group.IsPublic;
            }
            if (userIds == null)
            {
                return(new List <long>());
            }
            return(userIds.Where(n => IsReceiveActivity(activityService, isPublic, n, activity)));
        }
Exemple #7
0
        /// <summary>
        /// 转换成groupEntity类型
        /// </summary>
        /// <returns></returns>
        public GroupEntity AsGroupEntity()
        {
            CategoryService categoryService = new CategoryService();
            GroupEntity     groupEntity     = null;

            //创建群组
            if (this.GroupId == 0)
            {
                groupEntity             = GroupEntity.New();
                groupEntity.UserId      = UserContext.CurrentUser.UserId;
                groupEntity.DateCreated = DateTime.UtcNow;
                groupEntity.GroupKey    = this.GroupKey;
            }
            //编辑群组
            else
            {
                GroupService groupService = new GroupService();
                groupEntity = groupService.Get(this.GroupId);
            }
            groupEntity.IsPublic  = this.IsPublic;
            groupEntity.GroupName = this.GroupName;
            if (Logo != null)
            {
                groupEntity.Logo = this.Logo;
            }
            groupEntity.Description         = Formatter.FormatMultiLinePlainTextForStorage(this.Description == null ? string.Empty : this.Description, true);
            groupEntity.AreaCode            = this.AreaCode ?? string.Empty;
            groupEntity.JoinWay             = this.JoinWay;
            groupEntity.EnableMemberInvite  = this.EnableMemberInvite;
            groupEntity.IsDynamicPermission = this.IsDynamicPermission;
            if (JoinWay == JoinWay.ByQuestion)
            {
                groupEntity.Question = this.Question;
                groupEntity.Answer   = this.Answer;
            }
            return(groupEntity);
        }
        /// <summary>
        /// 转换成groupEntity类型
        /// </summary>
        /// <returns></returns>
        public GroupEntity AsGroupEntity()
        {
            CategoryService categoryService = new CategoryService();
            GroupEntity groupEntity = null;

            //创建群组
            if (this.GroupId == 0)
            {
                groupEntity = GroupEntity.New();
                groupEntity.UserId = UserContext.CurrentUser.UserId;
                groupEntity.DateCreated = DateTime.UtcNow;
                groupEntity.GroupKey = this.GroupKey;

            }
            //编辑群组
            else
            {
                GroupService groupService = new GroupService();
                groupEntity = groupService.Get(this.GroupId);
            }
            groupEntity.IsPublic = this.IsPublic;
            groupEntity.GroupName = this.GroupName;
            if (Logo != null)
            {
                groupEntity.Logo = this.Logo;
            }
            groupEntity.Description = Formatter.FormatMultiLinePlainTextForStorage(this.Description == null ? string.Empty : this.Description, true);
            groupEntity.AreaCode = this.AreaCode??string.Empty;
            groupEntity.JoinWay = this.JoinWay;
            groupEntity.EnableMemberInvite = this.EnableMemberInvite;
            groupEntity.IsDynamicPermission = this.IsDynamicPermission;
            if (JoinWay == JoinWay.ByQuestion)
            {
                groupEntity.Question = this.Question;
                groupEntity.Answer = this.Answer;
            }
            return groupEntity;
        }
Exemple #9
0
        private void AuthorizeCore(AuthorizationContext filterContext)
        {
            string spaceKey = UserContext.CurrentSpaceKey(filterContext);

            if (string.IsNullOrEmpty(spaceKey))
            {
                throw new ExceptionFacade("spaceKey为null");
            }
            GroupService groupService = new GroupService();
            GroupEntity  group        = groupService.Get(spaceKey);

            if (group == null)
            {
                throw new ExceptionFacade("找不到当前群组");
            }

            IUser currentUser = UserContext.CurrentUser;



            //判断访问群组权限
            if (!new Authorizer().Group_View(group))
            {
                if (currentUser == null)
                {
                    filterContext.Result = new RedirectResult(SiteUrls.Instance().Login(true));
                }
                else
                {
                    if (group.AuditStatus != AuditStatus.Success)
                    {
                        filterContext.Result = new RedirectResult(SiteUrls.Instance().SystemMessage(filterContext.Controller.TempData, new SystemMessageViewModel
                        {
                            Title             = "无权访问群组!",
                            Body              = "该群组还没有通过审核,所以不能访问!",
                            StatusMessageType = StatusMessageType.Error
                        }, filterContext.HttpContext.Request.RawUrl) /* 跳向无权访问页 */);
                    }
                    else
                    {
                        filterContext.Result = new RedirectResult(SiteUrls.Instance().SystemMessage(filterContext.Controller.TempData, new SystemMessageViewModel
                        {
                            Title             = "无权访问群组!",
                            Body              = "你没有访问该群组的权限",
                            StatusMessageType = StatusMessageType.Error
                        }, filterContext.HttpContext.Request.RawUrl) /* 跳向无权访问页 */);
                    }
                }
                return;
            }

            //判断该用户是否有访问该群组管理页面的权限
            if (!RequireManager)
            {
                return;
            }
            //匿名用户要求先登录跳转
            if (currentUser == null)
            {
                filterContext.Result = new RedirectResult(SiteUrls.Instance().Login(true));
                return;
            }

            if (new Authorizer().Group_Manage(group))
            {
                return;
            }
            filterContext.Result = new RedirectResult(SiteUrls.Instance().SystemMessage(filterContext.Controller.TempData, new SystemMessageViewModel
            {
                Title             = "无权访问",
                Body              = "您无权访问此页面,只有群主或管理员才能访问",
                StatusMessageType = Tunynet.Mvc.StatusMessageType.Error
            }) /* 跳向无权访问页 */);
        }
        /// <summary>
        /// 通知处理程序
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="eventArgs"></param>
        private void GroupMemberApplyNoticeModule_After(GroupMemberApply sender, CommonEventArgs eventArgs)
        {
            GroupService groupService = new GroupService();
            GroupEntity entity = groupService.Get(sender.GroupId);
            if (entity == null)
                return;

            User senderUser = DIContainer.Resolve<IUserService>().GetFullUser(sender.UserId);
            if (senderUser == null)
                return;
            InvitationService invitationService = new InvitationService();
            Invitation invitation;
            NoticeService noticeService = DIContainer.Resolve<NoticeService>();
            Notice notice;
            if (eventArgs.EventOperationType == EventOperationType.Instance().Create())
            {
                if (sender.ApplyStatus == GroupMemberApplyStatus.Pending)
                {
                    List<long> toUserIds = new List<long>();
                    toUserIds.Add(entity.UserId);
                    toUserIds.AddRange(entity.GroupManagers.Select(n => n.UserId));
                    foreach (var toUserId in toUserIds)
                    {
                        //申请加入群组的请求
                        if (!groupService.IsMember(sender.GroupId, sender.UserId))
                        {
                            invitation = Invitation.New();
                            invitation.ApplicationId = GroupConfig.Instance().ApplicationId;
                            invitation.InvitationTypeKey = InvitationTypeKeys.Instance().ApplyJoinGroup();
                            invitation.UserId = toUserId;
                            invitation.SenderUserId = sender.UserId;
                            invitation.Sender = senderUser.DisplayName;
                            invitation.SenderUrl = SiteUrls.Instance().SpaceHome(sender.UserId);
                            invitation.RelativeObjectId = sender.GroupId;
                            invitation.RelativeObjectName = entity.GroupName;
                            invitation.RelativeObjectUrl = SiteUrls.FullUrl(SiteUrls.Instance().GroupHome(entity.GroupKey));
                            invitation.Remark = sender.ApplyReason;
                            invitationService.Create(invitation);
                        }
                    }
                }
            }

            string noticeTemplateName = string.Empty;
            if (eventArgs.EventOperationType == EventOperationType.Instance().Approved())
            {
                if (sender.ApplyStatus == GroupMemberApplyStatus.Approved)
                {
                    noticeTemplateName = NoticeTemplateNames.Instance().MemberApplyApproved();
                }
            }
            else if (eventArgs.EventOperationType == EventOperationType.Instance().Disapproved())
            {
                if (sender.ApplyStatus == GroupMemberApplyStatus.Disapproved)
                {
                    noticeTemplateName = NoticeTemplateNames.Instance().MemberApplyDisapproved();
                }
            }

            if (string.IsNullOrEmpty(noticeTemplateName))
                return;

            notice = Notice.New();

            notice.UserId = sender.UserId;
            notice.ApplicationId = GroupConfig.Instance().ApplicationId;
            notice.TypeId = NoticeTypeIds.Instance().Hint();
            //notice.LeadingActorUserId = UserContext.CurrentUser.UserId;
            //notice.LeadingActor = UserContext.CurrentUser.DisplayName;
            //notice.LeadingActorUrl = SiteUrls.FullUrl(SiteUrls.Instance().SpaceHome(UserContext.CurrentUser.UserId));
            notice.RelativeObjectId = sender.GroupId;
            notice.RelativeObjectName = StringUtility.Trim(entity.GroupName, 64);
            notice.RelativeObjectUrl = SiteUrls.FullUrl(SiteUrls.Instance().GroupHome(entity.GroupKey));
            notice.TemplateName = noticeTemplateName;
            noticeService.Create(notice);
        }
Exemple #11
0
        /// <summary>
        /// 设置/取消管理员通知处理程序
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="eventArgs"></param>
        private void SetManagerNoticeEventModule_After(GroupMember sender, CommonEventArgs eventArgs)
        {
            if (eventArgs.EventOperationType != EventOperationType.Instance().SetGroupManager() && eventArgs.EventOperationType != EventOperationType.Instance().CancelGroupManager())
                return;

            GroupService groupService = new GroupService();
            GroupEntity entity = groupService.Get(sender.GroupId);
            if (entity == null)
                return;

            User senderUser = DIContainer.Resolve<IUserService>().GetFullUser(sender.UserId);
            if (senderUser == null)
                return;

            NoticeService noticeService = DIContainer.Resolve<NoticeService>();

            Notice notice = Notice.New();
            notice.UserId = sender.UserId;
            notice.ApplicationId = GroupConfig.Instance().ApplicationId;
            notice.TypeId = NoticeTypeIds.Instance().Hint();
            notice.LeadingActorUserId = 0;
            notice.LeadingActor = string.Empty;
            notice.LeadingActorUrl = string.Empty;
            notice.RelativeObjectId = sender.GroupId;
            notice.RelativeObjectName = StringUtility.Trim(entity.GroupName, 64);
            notice.RelativeObjectUrl = SiteUrls.FullUrl(SiteUrls.Instance().GroupHome(entity.GroupKey));

            if (eventArgs.EventOperationType == EventOperationType.Instance().SetGroupManager())
            {
                notice.TemplateName = NoticeTemplateNames.Instance().SetGroupManager();
            }
            else
            {
                notice.TemplateName = NoticeTemplateNames.Instance().CannelGroupManager();
            }
            noticeService.Create(notice);
        }
Exemple #12
0
        /// <summary>
        /// 通知处理程序
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="eventArgs"></param>
        private void GroupMemberNoticeModule_After(GroupMember sender, CommonEventArgs eventArgs)
        {
            if (eventArgs.EventOperationType != EventOperationType.Instance().Delete() && eventArgs.EventOperationType != EventOperationType.Instance().Create() && sender != null)
                return;
            GroupService groupService = new GroupService();
            GroupEntity entity = groupService.Get(sender.GroupId);
            if (entity == null)
                return;

            User senderUser = DIContainer.Resolve<IUserService>().GetFullUser(sender.UserId);
            if (senderUser == null)
                return;

            NoticeService noticeService = DIContainer.Resolve<NoticeService>();
            Notice notice;

            List<long> toUserIds = new List<long>();
            toUserIds.Add(entity.UserId);
            toUserIds.AddRange(entity.GroupManagers.Select(n => n.UserId));
            //删除群组成员通知群管理员
            if (eventArgs.EventOperationType == EventOperationType.Instance().Delete())
            {
                foreach (var toUserId in toUserIds)
                {
                    if (toUserId == sender.UserId)
                        continue;
                    notice = Notice.New();
                    notice.UserId = toUserId;
                    notice.ApplicationId = GroupConfig.Instance().ApplicationId;
                    notice.TypeId = NoticeTypeIds.Instance().Hint();
                    notice.LeadingActorUserId = sender.UserId;
                    notice.LeadingActor = senderUser.DisplayName;
                    notice.LeadingActorUrl = SiteUrls.FullUrl(SiteUrls.Instance().SpaceHome(sender.UserId));
                    notice.RelativeObjectId = sender.GroupId;
                    notice.RelativeObjectName = StringUtility.Trim(entity.GroupName, 64);
                    notice.RelativeObjectUrl = SiteUrls.FullUrl(SiteUrls.Instance().GroupHome(entity.GroupKey));
                    notice.TemplateName = NoticeTemplateNames.Instance().MemberQuit();
                    noticeService.Create(notice);
                }
            }
            else if (eventArgs.EventOperationType == EventOperationType.Instance().Create()) //添加群成员时向群管理员发送通知
            {
                foreach (var toUserId in toUserIds)
                {
                    if (toUserId == sender.UserId)
                        continue;
                    notice = Notice.New();
                    notice.UserId = toUserId;
                    notice.ApplicationId = GroupConfig.Instance().ApplicationId;
                    notice.TypeId = NoticeTypeIds.Instance().Hint();
                    notice.LeadingActorUserId = sender.UserId;
                    notice.LeadingActor = senderUser.DisplayName;
                    notice.LeadingActorUrl = SiteUrls.FullUrl(SiteUrls.Instance().SpaceHome(sender.UserId));
                    notice.RelativeObjectId = sender.GroupId;
                    notice.RelativeObjectName = StringUtility.Trim(entity.GroupName, 64);
                    notice.RelativeObjectUrl = SiteUrls.FullUrl(SiteUrls.Instance().GroupHome(entity.GroupKey));
                    notice.TemplateName = NoticeTemplateNames.Instance().MemberJoin();
                    noticeService.Create(notice);
                }
                //向加入者发送通知

                //notice = Notice.New();
                //notice.UserId = sender.UserId;
                //notice.ApplicationId = GroupConfig.Instance().ApplicationId;
                //notice.TypeId = NoticeTypeIds.Instance().Hint();
                //notice.LeadingActorUserId = sender.UserId;
                //notice.LeadingActor = senderUser.DisplayName;
                //notice.LeadingActorUrl = SiteUrls.FullUrl(SiteUrls.Instance().SpaceHome(sender.UserId));
                //notice.RelativeObjectId = sender.GroupId;
                //notice.RelativeObjectName = StringUtility.Trim(entity.GroupName, 64);
                //notice.RelativeObjectUrl = SiteUrls.FullUrl(SiteUrls.Instance().GroupHome(entity.GroupKey));
                //notice.TemplateName = NoticeTemplateNames.Instance().MemberApplyApproved();
                //noticeService.Create(notice);
            }
        }
        private void AuthorizeCore(AuthorizationContext filterContext)
        {
            string spaceKey = UserContext.CurrentSpaceKey(filterContext);

            if (string.IsNullOrEmpty(spaceKey))
                throw new ExceptionFacade("spaceKey为null");
            GroupService groupService = new GroupService();
            GroupEntity group = groupService.Get(spaceKey);
            if (group == null)
                throw new ExceptionFacade("找不到当前群组");

            IUser currentUser = UserContext.CurrentUser;

            //判断访问群组权限
            if (!DIContainer.Resolve<Authorizer>().Group_View(group))
            {
                if (currentUser == null)
                    filterContext.Result = new RedirectResult(SiteUrls.Instance().Login(true));
                else
                {
                    if (group.AuditStatus != AuditStatus.Success)
                    {
                        filterContext.Result = new RedirectResult(SiteUrls.Instance().SystemMessage(filterContext.Controller.TempData, new SystemMessageViewModel
                        {
                            Title = "无权访问群组!",
                            Body = "该群组还没有通过审核,所以不能访问!",
                            StatusMessageType = StatusMessageType.Hint
                        }, filterContext.HttpContext.Request.RawUrl)/* 跳向无权访问页 */);
                    }
                    else
                    {
                        filterContext.Result = new RedirectResult(SiteUrls.Instance().SystemMessage(filterContext.Controller.TempData, new SystemMessageViewModel
                        {
                            Title = "无权访问群组!",
                            Body = "你没有访问该群组的权限",
                            StatusMessageType = StatusMessageType.Hint
                        }, filterContext.HttpContext.Request.RawUrl)/* 跳向无权访问页 */);
                    }
                }
                return;
            }

            //判断该用户是否有访问该群组管理页面的权限
            if (!RequireManager)
                return;
            //匿名用户要求先登录跳转
            if (currentUser == null)
            {
                filterContext.Result = new RedirectResult(SiteUrls.Instance().Login(true));
                return;
            }

            if (DIContainer.Resolve<Authorizer>().Group_Manage(group))
                return;
            filterContext.Result = new RedirectResult(SiteUrls.Instance().SystemMessage(filterContext.Controller.TempData, new SystemMessageViewModel
            {
                Title = "无权访问",
                Body = "您无权访问此页面,只有群主或管理员才能访问",
                StatusMessageType = StatusMessageType.Hint
            })/* 跳向无权访问页 */);
        }