예제 #1
0
        public async Task <IActionResult> DeleteEmbeddedProject(string guid)
        {
            EmbeddedProject embeddedProject = await embedService.FindAsync(new Guid(guid));

            if (embeddedProject == null)
            {
                ProblemDetails problem = new ProblemDetails
                {
                    Title    = "Embedded project not found.",
                    Detail   = "There was no embedded project found with this GUID.",
                    Instance = "35730158-1DED-4767-9C70-253C7A975715"
                };
                return(NotFound(problem));
            }

            string identity  = HttpContext.User.GetIdentityId(HttpContext);
            bool   isAllowed = userService.UserHasScope(identity, nameof(Defaults.Scopes.EmbedWrite));

            if (!(embeddedProject.User.IdentityId == identity || isAllowed))
            {
                ProblemDetails problem = new ProblemDetails
                {
                    Title    = "User is not allowed to delete the embedded project.",
                    Detail   = "The user does not own the project and does not have enough privileges to delete an embed project.",
                    Instance = "35730158-1DED-4767-9C70-253C7A975715"
                };
                return(Unauthorized(problem));
            }

            await embedService.RemoveAsync(embeddedProject.Id);

            embedService.Save();
            return(Ok());
        }