예제 #1
0
 private static void WriteInvalidActionError(string path, InvalidContentActionReason reason)
 {
     Logger.WriteWarning(EventId.ContentStore.InvalidContentAction, "Invalid content action.",
                         properties:
                         new Dictionary <string, object>
     {
         { "Path", path },
         { "Reason", Enum.GetName(typeof(InvalidContentActionException), reason) }
     });
 }
예제 #2
0
        protected static string GetMessage(InvalidContentActionReason reason, string actionType, string message)
        {
            if (message != null)
            {
                return(message);
            }

            string customMessage = SR.GetString(Error_InvalidContentAction + Enum.GetName(typeof(InvalidContentActionReason), reason));

            if (!String.IsNullOrEmpty(actionType))
            {
                return(customMessage + " " + SR.GetString(ActionString) + " " + actionType);
            }
            else
            {
                return(customMessage);
            }
        }
예제 #3
0
        private bool HasPermission(StateAction stateAction, out InvalidContentActionReason reason)
        {
            // set this as permission error will be the most common reason
            reason = InvalidContentActionReason.NotEnoughPermissions;

            if (this.Node.Id == 0)
            {
                var parent = this.Node.Parent;

                // for new content, creator needs to have AddNew permission for the parent
                if (!parent.Security.HasPermission(PermissionType.AddNew))
                {
                    return(false);
                }

                // if this is a list type, the user must have a manage container permission for the parent
                if (!CheckManageListPermission(this.Node.NodeType, parent))
                {
                    return(false);
                }

                // do not call this.Node.Security.HasPermission method because the node has not exist yet.
                switch (stateAction)
                {
                case StateAction.Save:
                    return(true);

                case StateAction.CheckOut:
                case StateAction.SaveAndCheckIn:
                case StateAction.CheckIn:
                case StateAction.UndoCheckOut:
                case StateAction.Publish:
                case StateAction.Approve:
                case StateAction.Reject:
                    return(false);

                default:
                    throw new SnNotSupportedException("Unknown StateAction: " + stateAction);
                }
            }
            else
            {
                // otherwise the user needs to have Save permission for every action
                if (!this.Node.Security.HasPermission(PermissionType.Save))
                {
                    return(false);
                }

                // if this is a list type, the user must have a manage container permission for the node
                if (!CheckManageListPermission(this.Node.NodeType, this.Node))
                {
                    return(false);
                }

                var checkedOutByAnotherUser = IsCheckedOutByAnotherUser(this.Node);
                if (checkedOutByAnotherUser)
                {
                    reason = InvalidContentActionReason.CheckedOutToSomeoneElse;
                }

                switch (stateAction)
                {
                case StateAction.Save:
                case StateAction.CheckOut:
                case StateAction.SaveAndCheckIn:
                case StateAction.CheckIn:
                    return(!checkedOutByAnotherUser);

                case StateAction.UndoCheckOut:
                    // force and 'normal' undo operations
                    return(!checkedOutByAnotherUser || HasForceUndoCheckOutRight(this.Node));

                case StateAction.Publish:
                    return(this.Node.Security.HasPermission(User.Current, PermissionType.Publish) && !checkedOutByAnotherUser);

                case StateAction.Approve:
                case StateAction.Reject:
                    return(this.Node.Security.HasPermission(User.Current, PermissionType.Approve));

                default:
                    throw new SnNotSupportedException("Unknown StateAction: " + stateAction);
                }
            }
        }
예제 #4
0
        private ActionValidationResult ValidateAction(StateAction stateAction, out InvalidContentActionReason reason)
        {
            if (!HasPermission(stateAction, out reason))
            {
                return(ActionValidationResult.Invalid);
            }

            if (this.Node.SavingState != ContentSavingState.Finalized && (stateAction != StateAction.CheckIn && stateAction != StateAction.UndoCheckOut))
            {
                reason = InvalidContentActionReason.MultistepSaveInProgress;
                return(ActionValidationResult.Invalid);
            }

            reason = InvalidContentActionReason.InvalidStateAction;

            if (this.Node.Id == 0)
            {
                if (stateAction == StateAction.Save || stateAction == StateAction.SaveAndCheckIn)
                {
                    return(ActionValidationResult.Valid);
                }

                return(ActionValidationResult.InvalidOnNewNode);
            }

            var action = 0;

            switch (stateAction)
            {
            case StateAction.Save: action = 0; break;

            case StateAction.CheckOut: action = 1; break;

            case StateAction.CheckIn: action = 2; break;

            case StateAction.UndoCheckOut: action = 3; break;

            case StateAction.Publish: action = 4; break;

            case StateAction.Approve: action = 5; break;

            case StateAction.Reject: action = 6; break;

            case StateAction.SaveAndCheckIn: action = 7; break;

            default:
                throw new SnNotSupportedException("Unknown StateAction: " + stateAction);
            }

            var status        = 0;
            var versionStatus = this.Node.Locked ? VersionStatus.Locked : this.CurrentVersion.Status;

            switch (versionStatus)
            {
            case VersionStatus.Approved: status = 0; break;

            case VersionStatus.Locked: status = 1; break;

            case VersionStatus.Draft: status = 2; break;

            case VersionStatus.Rejected: status = 3; break;

            case VersionStatus.Pending: status = 4; break;

            default:
                throw new SnNotSupportedException("Unknown VersionStatus: " + this.CurrentVersion.Status);
            }

            var mode = 0;

            switch (this.VersioningMode)
            {
            case VersioningMode.None: mode = 0; break;

            case VersioningMode.Major: mode = 1; break;

            case VersioningMode.Full: mode = 2; break;

            default:
                throw new SnNotSupportedException("Unknown VersioningMode: " + this.VersioningMode);
            }
            var approving = this.HasApproving ? 1 : 0;

            if (!EnabledActions[15 * approving + 5 * mode + status][action])
            {
                return(ActionValidationResult.Invalid);
            }
            return(ActionValidationResult.Valid);
        }
 protected static string GetMessage(InvalidContentActionReason reason)
 {
     return(SR.GetString(Error_InvalidContentAction + Enum.GetName(typeof(InvalidContentActionReason), reason)));
 }
 public InvalidContentActionException(InvalidContentActionReason reason, string path, string message) : base(message)
 {
     Reason = reason;
     Path   = path;
 }
 public InvalidContentActionException(InvalidContentActionReason reason, string path) : this(reason, path, GetMessage(reason))
 {
 }
예제 #8
0
 public InvalidContentActionException(InvalidContentActionReason reason, string path, string message = null, string actionType = null) : base(GetMessage(reason, actionType, message))
 {
     Reason     = reason;
     Path       = path;
     ActionType = actionType;
 }