/// <summary>
        /// Check whether the user has automatic or hardcoded access to the entities in <paramref name="entityType"/>.
        /// </summary>
        /// <param name="permission">
        /// The <see cref="Permission"/> being checked. This cannot be null.
        /// </param>
        /// <param name="entityType">
        /// A key value pair mapping the entity type ID (key) and the entities being checked of that type (value).
        /// </param>
        /// <param name="permissionToAccess">
        /// The map of the permission ID to true (if the user can access it) or false (if not). This cannot be null.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// None of the arguments can be null.
        /// </exception>
        internal void CheckAutomaticAccess(EntityRef permission, KeyValuePair <long, ISet <EntityRef> > entityType,
                                           Dictionary <long, IDictionary <long, bool> > permissionToAccess)
        {
            if (permission == null)
            {
                throw new ArgumentNullException("permission");
            }
            if (permissionToAccess == null)
            {
                throw new ArgumentNullException("permissionToAccess");
            }

            if (Permissions.Read.Equals(permission))
            {
                WellKnownAliases aliases = WellKnownAliases.CurrentTenant;

                long[] autoReadAccessTypes =
                {
                    aliases.Type,
                    aliases.Field,
                    aliases.Relationship
                };

                if (autoReadAccessTypes.Contains(entityType.Key))
                {
                    foreach (EntityRef instance in entityType.Value)
                    {
                        permissionToAccess[permission.Id][instance.Id] = true;
                    }
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     Load relationships.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        IEnumerable <RelationshipEntry> IDataSource.GetRelationships(IProcessingContext context)
        {
            if (_relationshipCache == null)
            {
                WellKnownAliases aliases = WellKnownAliases.CurrentTenant;

                var cardinality = new Dictionary <long, CardinalityEnum_Enumeration>( );

                /////
                // Cache the various types of cardinality.
                /////
                using (new TenantAdministratorContext(TenantId))
                {
                    cardinality [aliases.OneToOne]   = CardinalityEnum_Enumeration.OneToOne;
                    cardinality [aliases.OneToMany]  = CardinalityEnum_Enumeration.OneToMany;
                    cardinality [aliases.ManyToOne]  = CardinalityEnum_Enumeration.ManyToOne;
                    cardinality [aliases.ManyToMany] = CardinalityEnum_Enumeration.ManyToMany;
                }

                var dict = new Dictionary <RelationshipEntryKey, RelationshipEntry>( );

                var toOne   = new Dictionary <RelationshipEntryCardinalityKey, RelationshipEntry>( );
                var fromOne = new Dictionary <RelationshipEntryCardinalityKey, RelationshipEntry>( );

                /////
                // Query entities that are part of the solution
                /////
                using (IDbCommand command = CreateCommand( ))
                {
                    command.CommandText = "spGetTenantAppRelationships";
                    command.CommandType = CommandType.StoredProcedure;
                    command.AddParameterWithValue("@solutionId", SolutionId);
                    command.AddParameterWithValue("@tenant", TenantId);

                    using (IDataReader reader = command.ExecuteReader( ))
                    {
                        /////
                        // Read the base relationships
                        /////
                        ReadRelationships(context, reader, cardinality, dict, toOne, fromOne, false);

                        /////
                        // Move to the discarded install relationships (if there are any)
                        /////
                        if (reader.NextResult( ))
                        {
                            /////
                            // Read discarded relationships
                            /////
                            ReadRelationships(context, reader, cardinality, dict, toOne, fromOne, true);
                        }
                    }
                }

                _relationshipCache = dict.Values.ToList( );
            }

            return(_relationshipCache);
        }