Ejemplo n.º 1
0
        /// <summary>
        /// Formats the search result.
        /// </summary>
        /// <param name="person">The person.</param>
        /// <param name="displayOptions">The display options.</param>
        /// <param name="mergeFields">The merge fields.</param>
        /// <returns></returns>
        public override FormattedSearchResult FormatSearchResult(Person person, Dictionary <string, object> displayOptions = null, Dictionary <string, object> mergeFields = null)
        {
            var  result             = base.FormatSearchResult(person, displayOptions);
            bool isSecurityDisabled = false;

            if (displayOptions != null)
            {
                if (displayOptions.ContainsKey("EventItem-IsSecurityDisabled"))
                {
                    isSecurityDisabled = displayOptions["EventItem-IsSecurityDisabled"].ToString().AsBoolean();
                }
            }

            // If security is disabled true all items
            if (isSecurityDisabled)
            {
                result.IsViewAllowed = true;
                return(result);
            }

            // Otherwise we're checking security
            var eventItem = new EventItemService(new Data.RockContext()).Get(( int )this.Id);

            // Check if item in database has been deleted
            if (eventItem.IsNull())
            {
                result.IsViewAllowed = false;
                return(result);
            }

            if (eventItem.IsAuthorized("View", person))
            {
                result.IsViewAllowed = true;
                return(result);
            }
            else
            {
                result.IsViewAllowed = false;
                return(result);
            }
        }