コード例 #1
0
        public Response AssignPermission([FromBody] ResourceModel resourceModel)
        {
            Response reqResponse = new Response();

            int userId = _userService.GetUser(resourceModel.username, resourceModel.password);

            if (userId == -1)
            {
                reqResponse.SetResponse(401, "Not Authorized", "Invalid credentials inserted!", null);
                goto Finish;
            }

            ResourcePathModel resourceInfo = new ResourcePathModel(resourceModel.resourceName);

            if (!_resourceService.IsUserOwner(resourceInfo.fullResourcePath, userId))
            {
                reqResponse.SetResponse(401, "Not Authorized", "You are not allowed to change the permissions of the selected resource.", null);
                goto Finish;
            }

            if (!_resourceService.ResourceExists(resourceModel.resourceName))
            {
                reqResponse.SetResponse(404, "Not Existing", resourceModel.resourceName + " does not exist in the current filesystem.", null);
                goto Finish;
            }

            if (!_permissionService.ExistsPermission(resourceModel.permissionName))
            {
                reqResponse.SetResponse(500, "Not Existing", "Permission '" + resourceModel.permissionName + "' does not exist in the system.", null);
                goto Finish;
            }

            _permissionService.AssignPermissionToResource(resourceModel.permissionName, resourceModel.resourceName);
            reqResponse = new Response();

Finish:
            return(reqResponse);
        }