예제 #1
0
        public async Task <ActionResult <GetResult> > Get([FromQuery] ChannelRequest request)
        {
            if (!await _authManager.HasSitePermissionsAsync(request.SiteId,
                                                            MenuUtils.SitePermissions.Contents) ||
                !await _authManager.HasContentPermissionsAsync(request.SiteId, request.ChannelId, MenuUtils.ContentPermissions.Add))
            {
                return(Unauthorized());
            }

            var site = await _siteRepository.GetAsync(request.SiteId);

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

            var channelInfo = await _channelRepository.GetAsync(request.ChannelId);

            if (channelInfo == null)
            {
                return(this.Error("无法确定内容对应的栏目"));
            }

            var(isChecked, checkedLevel) = await CheckManager.GetUserCheckLevelAsync(_authManager, site, request.SiteId);

            var checkedLevels = CheckManager.GetCheckedLevels(site, isChecked, checkedLevel, false);

            return(new GetResult
            {
                CheckedLevels = checkedLevels,
                CheckedLevel = checkedLevel
            });
        }
예제 #2
0
        public async Task <ActionResult <GetResult> > Get([FromQuery] ChannelRequest request)
        {
            if (!await _authManager.HasContentPermissionsAsync(request.SiteId, request.ChannelId, Types.ContentPermissions.View))
            {
                return(Unauthorized());
            }

            var site = await _siteRepository.GetAsync(request.SiteId);

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

            var channel = await _channelRepository.GetAsync(request.ChannelId);

            if (channel == null)
            {
                return(this.Error("无法确定内容对应的栏目"));
            }

            var columnsManager = new ColumnsManager(_databaseManager, _pathManager);
            var columns        = await columnsManager.GetContentListColumnsAsync(site, channel, ColumnsManager.PageType.Contents);

            var(isChecked, checkedLevel) = await CheckManager.GetUserCheckLevelAsync(_authManager, site, request.SiteId);

            var checkedLevels = CheckManager.GetCheckedLevels(site, isChecked, checkedLevel, true);

            return(new GetResult
            {
                Value = columns,
                CheckedLevels = checkedLevels,
                CheckedLevel = checkedLevel
            });
        }
예제 #3
0
        public async Task <ActionResult <GetResult> > Get([FromQuery] ChannelRequest request)
        {
            if (!await _authManager.HasContentPermissionsAsync(request.SiteId, request.ChannelId, Types.ContentPermissions.Add))
            {
                return(Unauthorized());
            }

            var site = await _siteRepository.GetAsync(request.SiteId);

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

            var channel = await _channelRepository.GetAsync(request.ChannelId);

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

            var(isChecked, checkedLevel) = await CheckManager.GetUserCheckLevelAsync(_authManager, site, request.SiteId);

            var checkedLevels = CheckManager.GetCheckedLevels(site, isChecked, checkedLevel, true);

            return(new GetResult
            {
                CheckedLevel = checkedLevel,
                CheckedLevels = checkedLevels
            });
        }
예제 #4
0
        public async Task <ActionResult <GetResult> > Get([FromBody] GetRequest request)
        {
            if (!await _authManager.HasContentPermissionsAsync(request.SiteId, request.ChannelId, Types.ContentPermissions.CheckLevel1))
            {
                return(Unauthorized());
            }

            var site = await _siteRepository.GetAsync(request.SiteId);

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

            var channelInfo = await _channelRepository.GetAsync(request.ChannelId);

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

            var retVal = new List <IDictionary <string, object> >();

            foreach (var contentId in request.ContentIds)
            {
                var contentInfo = await _contentRepository.GetAsync(site, channelInfo, contentId);

                if (contentInfo == null)
                {
                    continue;
                }

                var dict = contentInfo.ToDictionary();
                dict["checkState"] =
                    CheckManager.GetCheckState(site, contentInfo);
                retVal.Add(dict);
            }

            var(isChecked, checkedLevel) = await CheckManager.GetUserCheckLevelAsync(_authManager, site, request.ChannelId);

            var checkedLevels = CheckManager.GetCheckedLevels(site, isChecked, checkedLevel, true);

            var allChannels =
                await _channelRepository.GetChannelsAsync(request.SiteId, _authManager, Types.ContentPermissions.Add);

            return(new GetResult
            {
                Value = retVal,
                CheckedLevels = checkedLevels,
                CheckedLevel = checkedLevel,
                AllChannels = allChannels
            });
        }
        public async Task <ActionResult <GetResult> > Get([FromQuery] GetRequest request)
        {
            if (!await _authManager.HasSitePermissionsAsync(request.SiteId,
                                                            Types.SitePermissions.Contents) ||
                !await _authManager.HasContentPermissionsAsync(request.SiteId, request.ChannelId, Types.ContentPermissions.CheckLevel1))
            {
                return(Unauthorized());
            }

            var site = await _siteRepository.GetAsync(request.SiteId);

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

            var summaries = ContentUtility.ParseSummaries(request.ChannelContentIds);

            var contents = new List <Content>();

            foreach (var summary in summaries)
            {
                var channel = await _channelRepository.GetAsync(summary.ChannelId);

                var content = await _contentRepository.GetAsync(site, channel, summary.Id);

                if (content == null)
                {
                    continue;
                }

                var pageContent = content.Clone <Content>();
                pageContent.Set(ColumnsManager.CheckState, CheckManager.GetCheckState(site, content));
                contents.Add(pageContent);
            }

            var siteIdList = await _authManager.GetSiteIdsAsync();

            var transSites = await _siteRepository.GetSelectsAsync(siteIdList);

            var(isChecked, checkedLevel) = await CheckManager.GetUserCheckLevelAsync(_authManager, site, request.ChannelId);

            var checkedLevels = ElementUtils.GetSelects(CheckManager.GetCheckedLevels(site, isChecked, checkedLevel, true));

            return(new GetResult
            {
                Contents = contents,
                CheckedLevels = checkedLevels,
                CheckedLevel = checkedLevel,
                TransSites = transSites
            });
        }
예제 #6
0
        public async Task <ActionResult <TreeResult> > Tree([FromBody] SiteRequest request)
        {
            if (!await _authManager.HasSitePermissionsAsync(request.SiteId,
                                                            MenuUtils.SitePermissions.ContentsCheck))
            {
                return(Unauthorized());
            }

            var site = await _siteRepository.GetAsync(request.SiteId);

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

            var channel = await _channelRepository.GetAsync(request.SiteId);

            var root = await _channelRepository.GetCascadeAsync(site, channel);

            var siteUrl = await _pathManager.GetSiteUrlAsync(site, true);

            var groupNames = await _contentGroupRepository.GetGroupNamesAsync(request.SiteId);

            var tagNames = await _contentTagRepository.GetTagNamesAsync(request.SiteId);

            var allLevels = CheckManager.GetCheckedLevels(site, true, site.CheckContentLevel, true);
            var levels    = new List <KeyValuePair <int, string> >();

            foreach (var level in allLevels)
            {
                if (level.Key == CheckManager.LevelInt.CaoGao || level.Key > 0)
                {
                    continue;
                }
                levels.Add(level);
            }
            var checkedLevels = ElementUtils.GetCheckBoxes(levels);

            var columnsManager = new ColumnsManager(_databaseManager, _pathManager);
            var columns        = await columnsManager.GetContentListColumnsAsync(site, channel, ColumnsManager.PageType.CheckContents);

            return(new TreeResult
            {
                Root = root,
                SiteUrl = siteUrl,
                GroupNames = groupNames,
                TagNames = tagNames,
                CheckedLevels = checkedLevels,
                Columns = columns
            });
        }
        public IHttpActionResult GetConfig()
        {
            try
            {
                var request = new RequestImpl();

                var siteId    = request.GetQueryInt("siteId");
                var channelId = request.GetQueryInt("channelId");

                if (!request.IsAdminLoggin ||
                    !request.AdminPermissions.HasChannelPermissions(siteId, channelId,
                                                                    ConfigManager.ChannelPermissions.ContentView))
                {
                    return(Unauthorized());
                }

                var siteInfo = SiteManager.GetSiteInfo(siteId);
                if (siteInfo == null)
                {
                    return(BadRequest("无法确定内容对应的站点"));
                }

                var channelInfo = ChannelManager.GetChannelInfo(siteId, channelId);
                if (channelInfo == null)
                {
                    return(BadRequest("无法确定内容对应的栏目"));
                }

                var columns = ContentManager.GetContentColumns(siteInfo, channelInfo, true);

                var isChecked     = CheckManager.GetUserCheckLevel(request.AdminPermissionsImpl, siteInfo, siteId, out var checkedLevel);
                var checkedLevels = CheckManager.GetCheckedLevels(siteInfo, isChecked, checkedLevel, true);

                return(Ok(new
                {
                    Value = columns,
                    CheckedLevels = checkedLevels,
                    CheckedLevel = checkedLevel
                }));
            }
            catch (Exception ex)
            {
                LogUtils.AddErrorLog(ex);
                return(InternalServerError(ex));
            }
        }
        public async Task <ActionResult <TreeResult> > Tree([FromBody] SiteRequest request)
        {
            if (!await _authManager.HasSitePermissionsAsync(request.SiteId,
                                                            MenuUtils.SitePermissions.ContentsRecycle))
            {
                return(Unauthorized());
            }

            var site = await _siteRepository.GetAsync(request.SiteId);

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

            var channel = await _channelRepository.GetAsync(request.SiteId);

            var root = await _channelRepository.GetCascadeAsync(site, channel);

            var siteUrl = await _pathManager.GetSiteUrlAsync(site, true);

            var groupNames = await _contentGroupRepository.GetGroupNamesAsync(request.SiteId);

            var tagNames = await _contentTagRepository.GetTagNamesAsync(request.SiteId);

            var checkedLevels = ElementUtils.GetCheckBoxes(CheckManager.GetCheckedLevels(site, true, site.CheckContentLevel, true));

            var columnsManager = new ColumnsManager(_databaseManager, _pathManager);
            var columns        = await columnsManager.GetContentListColumnsAsync(site, channel, ColumnsManager.PageType.RecycleContents);

            return(new TreeResult
            {
                Root = root,
                SiteUrl = siteUrl,
                GroupNames = groupNames,
                TagNames = tagNames,
                CheckedLevels = checkedLevels,
                Columns = columns
            });
        }
예제 #9
0
        public async Task <ActionResult <ListResult> > List([FromBody] ListRequest request)
        {
            if (!await _authManager.HasSitePermissionsAsync(request.SiteId,
                                                            MenuUtils.SitePermissions.Contents) ||
                !await _authManager.HasContentPermissionsAsync(request.SiteId, request.ChannelId,
                                                               MenuUtils.ContentPermissions.View,
                                                               MenuUtils.ContentPermissions.Add,
                                                               MenuUtils.ContentPermissions.Edit,
                                                               MenuUtils.ContentPermissions.Delete,
                                                               MenuUtils.ContentPermissions.Translate,
                                                               MenuUtils.ContentPermissions.Arrange,
                                                               MenuUtils.ContentPermissions.CheckLevel1,
                                                               MenuUtils.ContentPermissions.CheckLevel2,
                                                               MenuUtils.ContentPermissions.CheckLevel3,
                                                               MenuUtils.ContentPermissions.CheckLevel4,
                                                               MenuUtils.ContentPermissions.CheckLevel5))
            {
                return(Unauthorized());
            }

            var site = await _siteRepository.GetAsync(request.SiteId);

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

            var channel = await _channelRepository.GetAsync(request.ChannelId);

            if (channel == null)
            {
                return(this.Error("无法确定内容对应的栏目"));
            }

            var columnsManager = new ColumnsManager(_databaseManager, _pathManager);
            var columns        = await columnsManager.GetContentListColumnsAsync(site, channel, ColumnsManager.PageType.Contents);

            var pageContents = new List <Content>();
            List <ContentSummary> summaries;

            if (!string.IsNullOrEmpty(request.SearchType) &&
                !string.IsNullOrEmpty(request.SearchText) ||
                request.IsAdvanced)
            {
                summaries = await _contentRepository.Search(site, channel, channel.IsAllContents, request.SearchType, request.SearchText, request.IsAdvanced, request.CheckedLevels, request.IsTop, request.IsRecommend, request.IsHot, request.IsColor, request.GroupNames, request.TagNames);
            }
            else
            {
                summaries = await _contentRepository.GetSummariesAsync(site, channel, channel.IsAllContents);
            }
            var total = summaries.Count;

            var channelPlugins = _pluginManager.GetPlugins(request.SiteId, request.ChannelId);
            var contentMenus   = new List <Menu>();

            foreach (var plugin in channelPlugins)
            {
                var pluginMenus = plugin.GetMenus()
                                  .Where(x => ListUtils.ContainsIgnoreCase(x.Type, Types.Resources.Content)).ToList();
                if (pluginMenus.Count == 0)
                {
                    continue;
                }

                contentMenus.AddRange(pluginMenus);
            }

            if (total > 0)
            {
                var offset        = site.PageSize * (request.Page - 1);
                var pageSummaries = summaries.Skip(offset).Take(site.PageSize).ToList();

                var sequence = offset + 1;
                foreach (var summary in pageSummaries)
                {
                    var content = await _contentRepository.GetAsync(site, summary.ChannelId, summary.Id);

                    if (content == null)
                    {
                        continue;
                    }

                    var pageContent =
                        await columnsManager.CalculateContentListAsync(sequence ++, site, request.ChannelId, content, columns);

                    pageContents.Add(pageContent);
                }
            }

            var(isChecked, checkedLevel) = await CheckManager.GetUserCheckLevelAsync(_authManager, site, request.ChannelId);

            var checkedLevels = ElementUtils.GetCheckBoxes(CheckManager.GetCheckedLevels(site, isChecked, checkedLevel, true));

            var permissions = new Permissions
            {
                IsAdd         = await _authManager.HasContentPermissionsAsync(site.Id, channel.Id, MenuUtils.ContentPermissions.Add),
                IsDelete      = await _authManager.HasContentPermissionsAsync(site.Id, channel.Id, MenuUtils.ContentPermissions.Delete),
                IsEdit        = await _authManager.HasContentPermissionsAsync(site.Id, channel.Id, MenuUtils.ContentPermissions.Edit),
                IsArrange     = await _authManager.HasContentPermissionsAsync(site.Id, channel.Id, MenuUtils.ContentPermissions.Arrange),
                IsTranslate   = await _authManager.HasContentPermissionsAsync(site.Id, channel.Id, MenuUtils.ContentPermissions.Translate),
                IsCheck       = await _authManager.HasContentPermissionsAsync(site.Id, channel.Id, MenuUtils.ContentPermissions.CheckLevel1),
                IsCreate      = await _authManager.HasSitePermissionsAsync(site.Id, MenuUtils.SitePermissions.CreateContents) || await _authManager.HasContentPermissionsAsync(site.Id, channel.Id, MenuUtils.ContentPermissions.Create),
                IsChannelEdit = await _authManager.HasChannelPermissionsAsync(site.Id, channel.Id, MenuUtils.ChannelPermissions.Edit)
            };

            return(new ListResult
            {
                PageContents = pageContents,
                Total = total,
                PageSize = site.PageSize,
                Columns = columns,
                IsAllContents = channel.IsAllContents,
                CheckedLevels = checkedLevels,
                Permissions = permissions,
                Menus = contentMenus
            });
        }
예제 #10
0
        public async Task <ActionResult <GetResult> > Get()
        {
            var siteIds = await _authManager.GetSiteIdsAsync();

            if (siteIds.Count == 0)
            {
                return(new GetResult
                {
                    Unauthorized = true
                });
            }

            var sites = new List <Select <int> >();

            foreach (var siteId in siteIds)
            {
                var permissionSite = await _siteRepository.GetAsync(siteId);

                sites.Add(new Select <int>
                {
                    Value = permissionSite.Id,
                    Label = permissionSite.SiteName
                });
            }

            var site = await _siteRepository.GetAsync(siteIds[0]);

            var channel = await _channelRepository.GetAsync(site.Id);

            var root = await _channelRepository.GetCascadeAsync(site, channel, async summary =>
            {
                var count = await _contentRepository.GetCountAsync(site, summary);
                return(new
                {
                    Count = count
                });
            });

            var siteUrl = await _pathManager.GetSiteUrlAsync(site, true);

            var groupNames = await _contentGroupRepository.GetGroupNamesAsync(site.Id);

            var tagNames = await _contentTagRepository.GetTagNamesAsync(site.Id);

            var checkedLevels = ElementUtils.GetCheckBoxes(CheckManager.GetCheckedLevels(site, true, site.CheckContentLevel, true));

            var columnsManager = new ColumnsManager(_databaseManager, _pathManager);
            var columns        = await columnsManager.GetContentListColumnsAsync(site, channel, ColumnsManager.PageType.SearchContents);

            var permissions = new GetPermissions
            {
                IsAdd         = await _authManager.HasContentPermissionsAsync(site.Id, channel.Id, MenuUtils.ContentPermissions.Add),
                IsDelete      = await _authManager.HasContentPermissionsAsync(site.Id, channel.Id, MenuUtils.ContentPermissions.Delete),
                IsEdit        = await _authManager.HasContentPermissionsAsync(site.Id, channel.Id, MenuUtils.ContentPermissions.Edit),
                IsArrange     = await _authManager.HasContentPermissionsAsync(site.Id, channel.Id, MenuUtils.ContentPermissions.Arrange),
                IsTranslate   = await _authManager.HasContentPermissionsAsync(site.Id, channel.Id, MenuUtils.ContentPermissions.Translate),
                IsCheck       = await _authManager.HasContentPermissionsAsync(site.Id, channel.Id, MenuUtils.ContentPermissions.CheckLevel1),
                IsCreate      = await _authManager.HasSitePermissionsAsync(site.Id, MenuUtils.SitePermissions.CreateContents) || await _authManager.HasContentPermissionsAsync(site.Id, channel.Id, MenuUtils.ContentPermissions.Create),
                IsChannelEdit = await _authManager.HasChannelPermissionsAsync(site.Id, channel.Id, MenuUtils.ChannelPermissions.Edit)
            };

            return(new GetResult
            {
                Unauthorized = false,
                Sites = sites,
                SiteId = site.Id,
                SiteName = site.SiteName,
                SiteUrl = siteUrl,
                Root = root,
                GroupNames = groupNames,
                TagNames = tagNames,
                CheckedLevels = checkedLevels,
                Columns = columns,
                Permissions = permissions
            });
        }
        public IHttpActionResult GetConfig()
        {
            try
            {
                var request = new AuthenticatedRequest();

                var siteId        = request.GetQueryInt("siteId");
                var channelId     = request.GetQueryInt("channelId");
                var contentIdList = TranslateUtils.StringCollectionToIntList(request.GetQueryString("contentIds"));

                if (!request.IsAdminLoggin ||
                    !request.AdminPermissionsImpl.HasChannelPermissions(siteId, channelId,
                                                                        ConfigManager.ChannelPermissions.ContentCheck))
                {
                    return(Unauthorized());
                }

                var siteInfo = SiteManager.GetSiteInfo(siteId);
                if (siteInfo == null)
                {
                    return(BadRequest("无法确定内容对应的站点"));
                }

                var channelInfo = ChannelManager.GetChannelInfo(siteId, channelId);
                if (channelInfo == null)
                {
                    return(BadRequest("无法确定内容对应的栏目"));
                }

                var retval = new List <Dictionary <string, object> >();
                foreach (var contentId in contentIdList)
                {
                    var contentInfo = ContentManager.GetContentInfo(siteInfo, channelInfo, contentId);
                    if (contentInfo == null)
                    {
                        continue;
                    }

                    var dict = contentInfo.ToDictionary();
                    dict["title"]      = WebUtils.GetContentTitle(siteInfo, contentInfo, string.Empty);
                    dict["checkState"] =
                        CheckManager.GetCheckState(siteInfo, contentInfo);
                    retval.Add(dict);
                }

                var isChecked     = CheckManager.GetUserCheckLevel(request.AdminPermissionsImpl, siteInfo, siteId, out var checkedLevel);
                var checkedLevels = CheckManager.GetCheckedLevels(siteInfo, isChecked, checkedLevel, true);

                var allChannels =
                    ChannelManager.GetChannels(siteId, request.AdminPermissionsImpl, ConfigManager.ChannelPermissions.ContentAdd);

                return(Ok(new
                {
                    Value = retval,
                    CheckedLevels = checkedLevels,
                    CheckedLevel = checkedLevel,
                    AllChannels = allChannels
                }));
            }
            catch (Exception ex)
            {
                LogUtils.AddErrorLog(ex);
                return(InternalServerError(ex));
            }
        }
예제 #12
0
        public async Task <ActionResult <TreeResult> > Tree([FromBody] TreeRequest request)
        {
            if (!await _authManager.HasSitePermissionsAsync(request.SiteId,
                                                            MenuUtils.SitePermissions.Contents))
            {
                return(Unauthorized());
            }

            var site = await _siteRepository.GetAsync(request.SiteId);

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

            var channel = await _channelRepository.GetAsync(request.SiteId);

            var enabledChannelIds = await _authManager.GetContentPermissionsChannelIdsAsync(site.Id);

            var visibleChannelIds = await _authManager.GetVisibleChannelIdsAsync(enabledChannelIds);

            var root = await _channelRepository.GetCascadeAsync(site, channel, async summary =>
            {
                var visible  = visibleChannelIds.Contains(summary.Id);
                var disabled = !enabledChannelIds.Contains(summary.Id);
                var current  = await _contentRepository.GetSummariesAsync(site, summary);

                if (!visible)
                {
                    return(null);
                }

                return(new
                {
                    current.Count,
                    Disabled = disabled
                });
            });

            if (!request.Reload)
            {
                var siteUrl = await _pathManager.GetSiteUrlAsync(site, true);

                var groupNames = await _contentGroupRepository.GetGroupNamesAsync(request.SiteId);

                var tagNames = await _contentTagRepository.GetTagNamesAsync(request.SiteId);

                var checkedLevels = ElementUtils.GetCheckBoxes(CheckManager.GetCheckedLevels(site, true, site.CheckContentLevel, true));

                return(new TreeResult
                {
                    Root = root,
                    SiteUrl = siteUrl,
                    GroupNames = groupNames,
                    TagNames = tagNames,
                    CheckedLevels = checkedLevels
                });
            }

            return(new TreeResult
            {
                Root = root
            });
        }
예제 #13
0
        public object GetContentAdd(RequestImpl request)
        {
            var requestSiteId    = request.SiteId;
            var requestChannelId = request.ChannelId;
            var requestContentId = request.ContentId;

            var                   sites       = new List <object>();
            var                   channels    = new List <object>();
            object                site        = null;
            object                channel     = null;
            List <string>         groupNames  = null;
            List <string>         tagNames    = null;
            ContentInfo           contentInfo = null;
            List <TableStyleInfo> styles      = null;
            List <KeyValuePair <int, string> > checkedLevels = null;
            var checkedLevel = 0;

            if (request.IsUserLoggin)
            {
                SiteInfo    siteInfo    = null;
                ChannelInfo channelInfo = null;
                var         siteIdList  = request.UserPermissionsImpl.GetSiteIdList();
                foreach (var siteId in siteIdList)
                {
                    var permissionSiteInfo = SiteManager.GetSiteInfo(siteId);
                    if (requestSiteId == siteId)
                    {
                        siteInfo = permissionSiteInfo;
                    }
                    sites.Add(new
                    {
                        permissionSiteInfo.Id,
                        permissionSiteInfo.SiteName
                    });
                }

                if (siteInfo == null && siteIdList.Count > 0)
                {
                    siteInfo = SiteManager.GetSiteInfo(siteIdList[0]);
                }

                if (siteInfo != null)
                {
                    var channelIdList = request.UserPermissionsImpl.GetChannelIdList(siteInfo.Id,
                                                                                     ConfigManager.ChannelPermissions.ContentAdd);
                    foreach (var permissionChannelId in channelIdList)
                    {
                        var permissionChannelInfo = ChannelManager.GetChannelInfo(siteInfo.Id, permissionChannelId);
                        if (channelInfo == null || permissionChannelInfo.Id == requestChannelId)
                        {
                            channelInfo = permissionChannelInfo;
                        }
                        channels.Add(new
                        {
                            permissionChannelInfo.Id,
                            ChannelName = ChannelManager.GetChannelNameNavigation(siteInfo.Id, permissionChannelId)
                        });
                    }

                    site = new
                    {
                        siteInfo.Id,
                        siteInfo.SiteName,
                        SiteUrl = PageUtility.GetSiteUrl(siteInfo, false)
                    };

                    groupNames = ContentGroupManager.GetGroupNameList(siteInfo.Id);
                    tagNames   = ContentTagManager.GetTagNameList(siteInfo.Id);
                }

                if (channelInfo != null)
                {
                    channel = new
                    {
                        channelInfo.Id,
                        ChannelName = ChannelManager.GetChannelNameNavigation(siteInfo.Id, channelInfo.Id)
                    };

                    styles = TableStyleManager.GetContentStyleInfoList(siteInfo, channelInfo);

                    var checkKeyValuePair = CheckManager.GetUserCheckLevel(request.AdminPermissionsImpl, siteInfo, siteInfo.Id);
                    checkedLevels = CheckManager.GetCheckedLevels(siteInfo, checkKeyValuePair.Key, checkedLevel, true);

                    if (requestContentId != 0)
                    {
                        checkedLevels.Insert(0, new KeyValuePair <int, string>(CheckManager.LevelInt.NotChange, CheckManager.Level.NotChange));
                        checkedLevel = CheckManager.LevelInt.NotChange;

                        contentInfo = ContentManager.GetContentInfo(siteInfo, channelInfo, requestContentId);
                        if (contentInfo != null &&
                            (contentInfo.SiteId != siteInfo.Id || contentInfo.ChannelId != channelInfo.Id))
                        {
                            contentInfo = null;
                        }
                    }
                    else
                    {
                        contentInfo = new ContentInfo(new
                        {
                            Id        = 0,
                            SiteId    = siteInfo.Id,
                            ChannelId = channelInfo.Id,
                            AddDate   = DateTime.Now
                        });
                    }
                }
            }

            return(new
            {
                Value = request.UserInfo,
                Config = ConfigManager.Instance.SystemConfigInfo,
                Sites = sites,
                Channels = channels,
                Site = site,
                Channel = channel,
                AllGroupNames = groupNames,
                AllTagNames = tagNames,
                Styles = styles,
                CheckedLevels = checkedLevels,
                CheckedLevel = checkedLevel,
                Content = contentInfo,
            });
        }
예제 #14
0
        public async Task <ActionResult <TreeResult> > Tree([FromBody] TreeRequest request)
        {
            if (!await _authManager.HasSitePermissionsAsync(request.SiteId,
                                                            MenuUtils.SitePermissions.ContentsSearch))
            {
                return(Unauthorized());
            }

            var site = await _siteRepository.GetAsync(request.SiteId);

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

            var channel = await _channelRepository.GetAsync(request.SiteId);

            var root = await _channelRepository.GetCascadeAsync(site, channel, async summary =>
            {
                var count = await _contentRepository.GetCountAsync(site, summary);
                return(new
                {
                    Count = count
                });
            });

            if (!request.Reload)
            {
                var siteUrl = await _pathManager.GetSiteUrlAsync(site, true);

                var groupNames = await _contentGroupRepository.GetGroupNamesAsync(request.SiteId);

                var tagNames = await _contentTagRepository.GetTagNamesAsync(request.SiteId);

                var checkedLevels = ElementUtils.GetCheckBoxes(CheckManager.GetCheckedLevels(site, true, site.CheckContentLevel, true));

                var columnsManager = new ColumnsManager(_databaseManager, _pathManager);
                var columns        = await columnsManager.GetContentListColumnsAsync(site, channel, ColumnsManager.PageType.SearchContents);

                var permissions = new Permissions
                {
                    IsAdd         = await _authManager.HasContentPermissionsAsync(site.Id, channel.Id, MenuUtils.ContentPermissions.Add),
                    IsDelete      = await _authManager.HasContentPermissionsAsync(site.Id, channel.Id, MenuUtils.ContentPermissions.Delete),
                    IsEdit        = await _authManager.HasContentPermissionsAsync(site.Id, channel.Id, MenuUtils.ContentPermissions.Edit),
                    IsArrange     = await _authManager.HasContentPermissionsAsync(site.Id, channel.Id, MenuUtils.ContentPermissions.Arrange),
                    IsTranslate   = await _authManager.HasContentPermissionsAsync(site.Id, channel.Id, MenuUtils.ContentPermissions.Translate),
                    IsCheck       = await _authManager.HasContentPermissionsAsync(site.Id, channel.Id, MenuUtils.ContentPermissions.CheckLevel1),
                    IsCreate      = await _authManager.HasSitePermissionsAsync(site.Id, MenuUtils.SitePermissions.CreateContents) || await _authManager.HasContentPermissionsAsync(site.Id, channel.Id, MenuUtils.ContentPermissions.Create),
                    IsChannelEdit = await _authManager.HasChannelPermissionsAsync(site.Id, channel.Id, MenuUtils.ChannelPermissions.Edit)
                };

                var titleColumn =
                    columns.FirstOrDefault(x => StringUtils.EqualsIgnoreCase(x.AttributeName, nameof(Models.Content.Title)));
                columns.Remove(titleColumn);

                return(new TreeResult
                {
                    Root = root,
                    SiteUrl = siteUrl,
                    GroupNames = groupNames,
                    TagNames = tagNames,
                    CheckedLevels = checkedLevels,
                    TitleColumn = titleColumn,
                    Columns = columns,
                    Permissions = permissions
                });
            }

            return(new TreeResult
            {
                Root = root
            });
        }
예제 #15
0
        public async Task <ActionResult <GetResult> > Get()
        {
            var siteIds = await _authManager.GetSiteIdsAsync();

            if (siteIds.Count == 0)
            {
                return(new GetResult
                {
                    Unauthorized = true
                });
            }

            var sites = new List <Select <int> >();

            foreach (var siteId in siteIds)
            {
                var permissionSite = await _siteRepository.GetAsync(siteId);

                sites.Add(new Select <int>
                {
                    Value = permissionSite.Id,
                    Label = permissionSite.SiteName
                });
            }

            var site = await _siteRepository.GetAsync(siteIds[0]);

            var channel = await _channelRepository.GetAsync(site.Id);

            var enabledChannelIds = await _authManager.GetChannelIdsAsync(site.Id);

            var visibleChannelIds = await _authManager.GetVisibleChannelIdsAsync(enabledChannelIds);

            var root = await _channelRepository.GetCascadeAsync(site, channel, async summary =>
            {
                var visible  = visibleChannelIds.Contains(summary.Id);
                var disabled = !enabledChannelIds.Contains(summary.Id);
                var current  = await _contentRepository.GetSummariesAsync(site, summary);

                if (!visible)
                {
                    return(null);
                }

                return(new
                {
                    current.Count,
                    Disabled = disabled
                });
            });

            var siteUrl = await _pathManager.GetSiteUrlAsync(site, true);

            var groupNames = await _contentGroupRepository.GetGroupNamesAsync(site.Id);

            var tagNames = await _contentTagRepository.GetTagNamesAsync(site.Id);

            var checkedLevels = ElementUtils.GetCheckBoxes(CheckManager.GetCheckedLevels(site, true, site.CheckContentLevel, true));

            var columnsManager = new ColumnsManager(_databaseManager, _pathManager);
            var columns        = await columnsManager.GetContentListColumnsAsync(site, channel, ColumnsManager.PageType.SearchContents);

            var titleColumn =
                columns.FirstOrDefault(x => StringUtils.EqualsIgnoreCase(x.AttributeName, nameof(Models.Content.Title)));

            columns.Remove(titleColumn);

            return(new GetResult
            {
                Unauthorized = false,
                Sites = sites,
                SiteId = site.Id,
                SiteName = site.SiteName,
                SiteUrl = siteUrl,
                Root = root,
                GroupNames = groupNames,
                TagNames = tagNames,
                CheckedLevels = checkedLevels,
                TitleColumn = titleColumn,
                Columns = columns
            });
        }