Esempio n. 1
0
        /// <summary>
        /// Возвращает список настроек фильтров по умолчанию для списка статей
        /// </summary>
        /// <param name="actionCode"></param>
        /// <param name="contentId"></param>
        /// <returns></returns>
        public IEnumerable <RelationSearchBlockState> GetDefaultFilterStates(string actionCode, int contentId)
        {
            var action     = BackendActionRepository.GetByCode(actionCode);
            var entityCode = action.EntityType.Code;

            if (
                (
                    action.ActionType.Code.Equals(ActionTypeCode.List, StringComparison.CurrentCultureIgnoreCase) ||
                    action.ActionType.Code.Equals(ActionTypeCode.Select, StringComparison.CurrentCultureIgnoreCase) ||
                    action.ActionType.Code.Equals(ActionTypeCode.MultipleSelect, StringComparison.CurrentCultureIgnoreCase)
                )
                &&
                (
                    entityCode.Equals(EntityTypeCode.Article, StringComparison.CurrentCultureIgnoreCase) ||
                    entityCode.Equals(EntityTypeCode.VirtualArticle, StringComparison.CurrentCultureIgnoreCase)
                )
                )
            {
                var defFilter = UserRepository.GetById(QPContext.CurrentUserId).ContentDefaultFilters
                                .Where(f => f.ContentId.HasValue && f.ArticleIDs.Any())
                                .ToDictionary(f => f.ContentId.Value);
                if (defFilter.Any())
                {
                    var articles =
                        ArticleRepository.GetList(defFilter.SelectMany(f => f.Value.ArticleIDs).ToList())
                        .GroupBy(a => a.ContentId)
                        .ToDictionary(g => g.Key, g => g.Select(a => new EntityListItem {
                        Id = a.Id, Name = a.Name
                    }));

                    return(ContentRepository.GetById(contentId).Fields
                           .Where(f =>
                                  (f.ExactType == FieldExactTypes.M2MRelation || f.ExactType == FieldExactTypes.O2MRelation) &&
                                  f.UseForDefaultFiltration &&
                                  f.RelateToContentId.HasValue && defFilter.ContainsKey(f.RelateToContentId.Value)
                                  )
                           .Select(f => new RelationSearchBlockState
                    {
                        SearchType = GetFieldSearchType(f),
                        FieldId = f.Id,
                        ContentId = f.ContentId,
                        FieldColumnName = f.Name,
                        FieldName = f.DisplayName,
                        FieldGroup = f.Content.Name,
                        SelectedEntities = articles[f.RelateToContentId.Value]
                    })
                           .ToArray());
                }

                return(Enumerable.Empty <RelationSearchBlockState>());
            }

            return(Enumerable.Empty <RelationSearchBlockState>());
        }
Esempio n. 2
0
        /// <summary>
        /// Возвращает список кнопок панели инструментов по коду действия
        /// </summary>
        /// <param name="actionCode">код действия</param>
        /// <returns>список кнопок панели инструментов</returns>
        public static IEnumerable <ToolbarButton> GetButtonListByActionCode(string actionCode, int entityId, int parentEntityId, bool?boundToExternal)
        {
            var id     = entityId == 0 ? parentEntityId : entityId;
            var action = BackendActionRepository.GetByCode(actionCode);

            var allButtons = ToolbarRepository.GetButtonListByActionCode(action.Code, entityId);


            // если неопределен id сущности, то нужно работать с родительским entity type
            var etypeCode = entityId != 0 ? action.EntityType.Code : action.EntityType.ParentCode;
            IEnumerable <string> legalActionCodes = CustomActionResolver.CanExecuteFilter(etypeCode, id, parentEntityId, allButtons.Select(b => b.ActionCode)).ToArray();

            // Только те кнопки, для которых разрешены Action
            IEnumerable <ToolbarButton> result = allButtons.Where(b => legalActionCodes.Contains(b.ActionCode)).ToArray();

            if (actionCode.Equals(ActionCode.Articles) || actionCode.Equals(ActionCode.EditArticle))
            {
                var content = ContentRepository.GetById(parentEntityId);

                if (actionCode.Equals(ActionCode.Articles) && (!content.WorkflowBinding.IsAssigned || !content.WorkflowBinding.CurrentUserCanRemoveArticles))
                {
                    result = result.Where(b => b.ActionCode != ActionCode.MultiplePublishArticles);
                }

                if (!content.IsArticleChangingActionsAllowed(boundToExternal))
                {
                    result = result.Where(b => ActionCode.ArticleNonChangingActionCodes.Contains(b.ActionCode, StringComparer.InvariantCultureIgnoreCase)).ToArray();
                }
            }
            else if (actionCode.Equals(ActionCode.ArticleVersions) || actionCode.Equals(ActionCode.PreviewArticleVersion))
            {
                var article = ArticleRepository.GetById(parentEntityId);
                if (!article.IsArticleChangingActionsAllowed(boundToExternal))
                {
                    result = result.Where(b => ActionCode.ArticleVersionsNonChangingActionCodes.Contains(b.ActionCode, StringComparer.InvariantCultureIgnoreCase)).ToArray();
                }
            }

            return(result);
        }
Esempio n. 3
0
 public static BackendAction GetByCode(string actionCode) => string.IsNullOrWhiteSpace(actionCode) ? null : BackendActionRepository.GetByCode(actionCode);