Example #1
0
        public async Task <IActionResult> DeleteUrlAsync([FromBody] DeleteDataSourceResource deleteDataSourceResource)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState.GetErrorMessages()));
            }

            var username = httpContextRetriever.HttpContext.User.Identity.Name;
            var user     = await userService.GetUserByMailAsync(username);

            var dataSource = await _metadataService.GetDataSourceByUuid(deleteDataSourceResource.DataSourceUuid);

            var metadata = await _metadataService.GetByUuidAsync(dataSource.MetadataUuid);

            if (user.MunicipalityName != metadata.MunicipalityName)
            {
                return(Unauthorized("Invalid permissions for given Metadata! User must match Municipality."));
            }

            await _metadataService.DeleteDataSourceAsync(deleteDataSourceResource.DataSourceUuid);

            return(Ok());
        }