Esempio n. 1
0
        /// <summary>
        /// Sets attribute values that have been provided by a remote client.
        /// </summary>
        /// <remarks>
        /// This should be used to handle values the client sent back after
        /// calling the <see cref="GetClientEditableAttributeValues(IHasAttributes, Person, bool)"/>
        /// method. It handles conversion from custom data formats into the
        /// proper values to be stored in the database.
        /// </remarks>
        /// <param name="entity">The entity.</param>
        /// <param name="attributeValues">The attribute values.</param>
        /// <param name="currentPerson">The current person.</param>
        /// <param name="enforceSecurity">if set to <c>true</c> then security will be enforced.</param>
        public static void SetClientAttributeValues(this IHasAttributes entity, Dictionary <string, string> attributeValues, Person currentPerson, bool enforceSecurity = true)
        {
            if (entity == null || entity.Attributes == null || entity.AttributeValues == null)
            {
                return;
            }

            foreach (var kvp in attributeValues)
            {
                if (!entity.Attributes.ContainsKey(kvp.Key) || !entity.AttributeValues.ContainsKey(kvp.Key))
                {
                    continue;
                }

                var attribute = entity.Attributes[kvp.Key];

                if (enforceSecurity && !attribute.IsAuthorized(Rock.Security.Authorization.EDIT, currentPerson))
                {
                    continue;
                }

                var value = ClientAttributeHelper.GetValueFromClient(attribute, kvp.Value);

                entity.SetAttributeValue(kvp.Key, value);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Gets the attribute values in a format that can be sent to remote
        /// clients in a compact and secure manner. This includes additional
        /// details to allow for editing the value.
        /// </summary>
        /// <param name="entity">The entity whose attributes are requested.</param>
        /// <param name="currentPerson">The current person.</param>
        /// <param name="enforceSecurity">if set to <c>true</c> then security will be enforced.</param>
        /// <returns>A collection of <see cref="ClientEditableAttributeValueViewModel" /> objects.</returns>
        public static List <ClientEditableAttributeValueViewModel> GetClientEditableAttributeValues(this IHasAttributes entity, Person currentPerson, bool enforceSecurity = true)
        {
            if (entity == null)
            {
                return(new List <ClientEditableAttributeValueViewModel>());
            }

            return(entity.AttributeValues
                   .Select(av => new
            {
                av.Value,
                Attribute = AttributeCache.Get(av.Value.AttributeId)
            })
                   .Where(av => !enforceSecurity || av.Attribute.IsAuthorized(Rock.Security.Authorization.VIEW, currentPerson))
                   .Select(kvp => ClientAttributeHelper.ToClientEditableAttributeValue(kvp.Value))
                   .ToList());
        }
Esempio n. 3
0
        /// <summary>
        /// Gets the property values that will be sent to the device in the application bundle.
        /// </summary>
        /// <returns>
        /// A collection of string/object pairs.
        /// </returns>
        public override object GetMobileConfigurationValues()
        {
            using (var rockContext = new RockContext())
            {
                var attributes = AttributeFiltersGuids.Select(a => AttributeCache.Get(a))
                                 .Where(a => a != null)
                                 .Select(a => ClientAttributeHelper.ToClientEditableAttributeValue(a, a.DefaultValue))
                                 .ToList();

                return(new
                {
                    Campuses = GetValidCampuses(rockContext),
                    SearchHeader,
                    ShowCampusFilter,
                    ShowDayOfWeekFilter,
                    ShowTimePeriodFilter,
                    ShowLocationFilter,
                    ResultsTransition,
                    Attributes = attributes
                });
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Sets a single attribute values that have been provided by a remote client.
        /// </summary>
        /// <remarks>
        /// This should be used to handle values the client sent back after
        /// calling the <see cref="GetClientEditableAttributeValues(IHasAttributes, Person, bool)"/>
        /// method. It handles conversion from custom data formats into the
        /// proper values to be stored in the database.
        /// </remarks>
        /// <param name="entity">The entity.</param>
        /// <param name="key">The attribute key to set.</param>
        /// <param name="value">The value provided by the remote client.</param>
        /// <param name="currentPerson">The current person.</param>
        /// <param name="enforceSecurity">if set to <c>true</c> then security will be enforced.</param>
        public static void SetClientAttributeValue(this IHasAttributes entity, string key, string value, Person currentPerson, bool enforceSecurity = true)
        {
            if (entity == null || entity.Attributes == null || entity.AttributeValues == null)
            {
                return;
            }

            if (!entity.Attributes.ContainsKey(key) || !entity.AttributeValues.ContainsKey(key))
            {
                return;
            }

            var attribute = entity.Attributes[key];

            if (enforceSecurity && !attribute.IsAuthorized(Rock.Security.Authorization.EDIT, currentPerson))
            {
                return;
            }

            var databaseValue = ClientAttributeHelper.GetValueFromClient(attribute, value);

            entity.SetAttributeValue(key, databaseValue);
        }