Пример #1
0
        public override JsonOperationResponseBase OnOperation(Arguments arguments, Authentication authentication)
        {
            DeleteCommentRequest request = new DeleteCommentRequest()
            {
                targetCommentId = arguments["targetCommentId"],
                targetModId     = arguments["targetModId"]
            };

            if (!request.IsValidRequest())
            {
                return(new DeleteCommentResponse()
                {
                    Error = "All fields were not filled out"
                });
            }

            if (!authentication.HasAtLeastAuthenticationLevel(AuthenticationLevel.BasicUser))
            {
                return(new DeleteCommentResponse()
                {
                    Error = "You are not signed in"
                });
            }

            if (!UploadedModsManager.Instance.HasModWithIdBeenUploaded(request.targetModId))
            {
                return(new DeleteCommentResponse()
                {
                    Error = "That mod does not exist"
                });
            }

            SpecialModData specialModData = UploadedModsManager.Instance.GetSpecialModInfoFromId(request.targetModId);

            string userId = authentication.UserID;

            Comment comment = specialModData.GetCommentWithCommentID(request.targetCommentId);

            if (comment == null)
            {
                return(new DeleteCommentResponse()
                {
                    Error = "There is no comment with that id on that mod"
                });
            }

            if (userId != comment.PosterUserId && !authentication.HasAtLeastAuthenticationLevel(AuthenticationLevel.Admin))
            {
                return(new DeleteCommentResponse()
                {
                    Error = "You do not have premission to delete this comment"
                });
            }

            specialModData.DeleteCommentWithId(request.targetCommentId);
            specialModData.Save();

            return(new DeleteCommentResponse()
            {
                message = "Comment deleted."
            });
        }