コード例 #1
0
        public Response CreateResource([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.IsPathValid(resourceInfo.resourcePath))
            {
                reqResponse.SetResponse(404, "Not Existing", resourceInfo.resourcePath + " does not exist in the current filesystem.", null);
                goto Finish;
            }

            if (!_resourceService.IsUserOwner(resourceInfo.resourcePath, userId))
            {
                reqResponse.SetResponse(401, "Not Authorized", "You do not have the rights to access this resource. Please contact the owner of the selected resource.", null);
                goto Finish;
            }

            if (_resourceService.ResourceExists(resourceInfo.fullResourcePath))
            {
                reqResponse.SetResponse(500, "Already Existing", resourceInfo.fullResourcePath + " already exists in the current filesystem.", null);
                goto Finish;
            }

            _resourceService.CreateResource(resourceInfo.resourceName, resourceInfo.fullResourcePath, resourceInfo.resourcePath, userId, resourceModel.resourceTypeId, resourceModel.value);
            reqResponse = new Response();

Finish:
            return(reqResponse);
        }
コード例 #2
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);
        }