Esempio n. 1
0
        private static void CheckRight(DummyFileInfoWrapper fileInfo, string action)
        {
            bool isActionAllowed = false;

            int userId = Security.CurrentUser.UserID;

            if (fileInfo.ContainerKey.StartsWith("ForumNodeId_"))
            {
                // Extract forumNodeId
                int forumNodeId = int.Parse(fileInfo.ContainerKey.Split('_')[1]);

                // Find incidentId by ForumNodeId
                string forumContainerKey = ForumThreadNodeInfo.GetOwnerContainerKey(forumNodeId);
                int    incidentId        = int.Parse(forumContainerKey.Split('_')[1]);

                // Check Security
                switch (action)
                {
                case "Read":
                    isActionAllowed = Incident.CanRead(incidentId);
                    break;

                case "Write":
                    isActionAllowed = Incident.CanUpdate(incidentId);
                    break;
                }
            }
            else if (fileInfo.ContainerKey.StartsWith("DocumentVers_"))
            {
                // Extract documentVersionId
                int documentId = int.Parse(fileInfo.ContainerKey.Split('_')[1]);

                // Check Security
                switch (action)
                {
                case "Read":
                    isActionAllowed = Document.CanRead(documentId);
                    break;

                case "Write":
                    isActionAllowed = Document.CanAddVersion(documentId);
                    break;
                }
            }
            else
            {
                isActionAllowed = FileStorage.CanUserRunAction(userId, fileInfo.ContainerKey, fileInfo.ParrentDirectoryId, action);
                //retVal = FileStorage.CanUserRead(Security.CurrentUser.UserID, fileInfo.ContainerKey, fileInfo.ParrentDirectoryId);
            }

            if (!isActionAllowed)
            {
                throw new HttpException(403, "Operation '" + action + "' is forbidden.");
            }
        }
Esempio n. 2
0
        private static bool CheckFileStorageRight(FileInfo fileInfo, string action, int userId)
        {
            bool isActionAllowed = false;

            if (fileInfo.ContainerKey.StartsWith("ForumNodeId_"))
            {
                // Extract forumNodeId
                int forumNodeId = int.Parse(fileInfo.ContainerKey.Split('_')[1]);

                // Find incidentId by ForumNodeId
                string forumContainerKey = ForumThreadNodeInfo.GetOwnerContainerKey(forumNodeId);
                int    incidentId        = int.Parse(forumContainerKey.Split('_')[1]);

                // Check Security
                switch (action)
                {
                case "Read":
                    isActionAllowed = Incident.CanRead(incidentId);
                    break;

                case "Write":
                    isActionAllowed = Incident.CanUpdate(incidentId);
                    break;
                }
            }
            else if (fileInfo.ContainerKey.StartsWith("DocumentVers_"))
            {
                // Extract documentVersionId
                int documentId = int.Parse(fileInfo.ContainerKey.Split('_')[1]);

                // Check Security
                switch (action)
                {
                case "Read":
                    isActionAllowed = Document.CanRead(documentId);
                    break;

                case "Write":
                    isActionAllowed = Document.CanAddVersion(documentId);
                    break;
                }
            }
            else
            {
                isActionAllowed = FileStorage.CanUserRunAction(userId, fileInfo.ContainerKey, fileInfo.ParentDirectoryId, action);
            }

            return(isActionAllowed);
        }