/// <summary>
        /// Assert that the new added container is consistent with the container previously added
        /// </summary>
        /// <param name="lastRoute">container previously added</param>
        /// <param name="newRoute">new container</param>
        /// <returns>true if the new route is consistent with the existing one</returns>
        private bool IsAuthorizedRoute(ClassKind lastRoute, ClassKind newRoute)
        {
            var lastRouteContainerClass = ContainerPropertyHelper.ContainerClassName(lastRoute);

            if (newRoute.ToString() == lastRouteContainerClass)
            {
                return(true);
            }

            // the newRoute may not correspond to the container class because the container class is abstract.
            // Check if the parent of the added container is that abstract class
            var type = Type.GetType("CDP4Common.DTO." + newRoute);

            if (type != null)
            {
                var parent = type.QueryBaseType();
                while (parent != null)
                {
                    if (parent.Name == lastRouteContainerClass)
                    {
                        return(true);
                    }

                    parent = parent.QueryBaseType();
                }
            }

            return(false);
        }
示例#2
0
        /// <summary>
        /// Resolves whether the write operation can be performed on a <see cref="Thing"/> of <see cref="Type"/>
        /// <paramref name="thingType"/> based on the superclass of <paramref name="thingType"/>
        /// </summary>
        /// <param name="containerThing">The container of the <see cref="Thing"/> that the write operation
        /// needs to be performed on.</param>
        /// <param name="thingType">The <see cref="Type"/> of the <see cref="Thing"/> that will be write to.</param>
        /// <returns>True if the permissions of the superclass allow it.</returns>
        private bool CanWriteBasedOnSuperclassClassKind(Thing containerThing, ClassKind thingType)
        {
            var baseType = StaticMetadataProvider.BaseType(thingType.ToString());

            if (string.IsNullOrWhiteSpace(baseType))
            {
                return(false);
            }

            return(Enum.TryParse(baseType, out ClassKind superClassKind) && this.CanWrite(superClassKind, containerThing));
        }
示例#3
0
        /// <summary>
        /// Returns whether a Write operation can be performed by the active user on the current <see cref="ClassKind"/>
        /// based on the supplied <see cref="Container"/>. The <see cref="ClassKind"/> ultimately determines the access. This method is primarily used for
        /// creation of a certain <see cref="SiteDirectory"/> contained <see cref="Thing"/>.
        /// </summary>
        /// <param name="classKind">The <see cref="ClassKind"/> that ultimately determines the permissions.</param>
        /// <param name="containerThing">The <see cref="Thing"/> to write to</param>
        /// <param name="thingType">The <see cref="ClassKind"/> that determine the permission</param>
        /// <returns>True if Write operation can be performed.</returns>
        private bool CanWriteSiteDirectoryContainedThing(ClassKind classKind, Thing containerThing, ClassKind thingType)
        {
            var person = this.Session.ActivePerson;

            if (person == null)
            {
                return(false);
            }

            var personRole = this.Session.ActivePerson.Role;

            if (personRole == null)
            {
                return(false);
            }

            var permission = personRole.PersonPermission.SingleOrDefault(p => p.ObjectClass == classKind);

            // if the permission is not found or superclass derivation is used then get the default one.
            var accessRightKind = permission?.AccessRight ?? StaticDefaultPermissionProvider.GetDefaultPersonPermission(thingType.ToString());

            switch (accessRightKind)
            {
            case PersonAccessRightKind.SAME_AS_CONTAINER:
                return(this.CanWrite(containerThing, containerThing.GetType()));

            case PersonAccessRightKind.SAME_AS_SUPERCLASS:
                return(this.CanWriteBasedOnSuperclassClassKind(containerThing, thingType));

            case PersonAccessRightKind.MODIFY:
                return(true);

            case PersonAccessRightKind.MODIFY_IF_PARTICIPANT:
                if (containerThing is EngineeringModelSetup setup)
                {
                    return(setup.Participant.Any(x => x.Person == this.Session.ActivePerson));
                }

                if (containerThing is SiteReferenceDataLibrary)
                {
                    var rdl =
                        this.Session.RetrieveSiteDirectory()
                        .Model.SelectMany(ems => this.Session.GetEngineeringModelSetupRdlChain(ems));
                    return(rdl.Contains(containerThing));
                }

                return(false);

            default:
                return(false);
            }
        }
示例#4
0
        /// <summary>
        /// Returns whether a Write operation can be performed by the active user on the current <see cref="ClassKind"/>
        /// based on the supplied <see cref="Container"/>. The <see cref="ClassKind"/> ultimately determines the access. This method is primarily used for
        /// creation of a certain <see cref="EngineeringModel"/> contained <see cref="Thing"/>.
        /// </summary>
        /// <param name="classKind">The <see cref="ClassKind"/> that ultimately determines the permissions.</param>
        /// <param name="containerThing">The <see cref="Thing"/> to write to</param>
        /// <param name="thingType">The <see cref="ClassKind"/> that ultimately determines the permissions.</param>
        /// <returns>True if Write operation can be performed.</returns>
        private bool CanWriteEngineeringModelContainedThing(ClassKind classKind, Thing containerThing, ClassKind thingType)
        {
            var engineeringModel = containerThing.TopContainer as EngineeringModel;

            var iteration = containerThing is Iteration it ? it : containerThing.GetContainerOfType <Iteration>();

            if (iteration?.IterationSetup.FrozenOn != null)
            {
                return(false);
            }

            var participant = this.Session.ActivePersonParticipants.FirstOrDefault(p => ((EngineeringModelSetup)p.Container).EngineeringModelIid == engineeringModel.Iid);

            if (participant?.Role == null)
            {
                return(false);
            }

            var permission = participant.Role.ParticipantPermission.SingleOrDefault(perm => perm.ObjectClass == classKind);

            // if the permission is not found then get the default one.
            var right = permission?.AccessRight ?? StaticDefaultPermissionProvider.GetDefaultParticipantPermission(thingType.ToString());

            switch (right)
            {
            case ParticipantAccessRightKind.SAME_AS_CONTAINER:
                return(this.CanWrite(containerThing, containerThing.GetType()));

            case ParticipantAccessRightKind.SAME_AS_SUPERCLASS:
                return(this.CanWriteBasedOnSuperclassClassKind(containerThing, thingType));

            case ParticipantAccessRightKind.MODIFY:
            case ParticipantAccessRightKind.MODIFY_IF_OWNER:
                return(true);

            default:
                return(false);
            }
        }
示例#5
0
 /// <summary>
 /// Returns the name of the container class that contains the provided <see cref="ClassKind"/>
 /// </summary>
 /// <param name="classKind">
 /// the <see cref="ClassKind"/>
 /// </param>
 /// <returns>
 /// The name of the container class
 /// </returns>
 public static string ContainerClassName(ClassKind classKind)
 {
     return(ContainerClassName(classKind.ToString()));
 }