Revize 0f8d6304
Přidáno uživatelem Vojtěch Bartička před asi 3 roky(ů)
Backend/Backend/Controllers/AnnotationController.cs | ||
---|---|---|
102 | 102 |
} |
103 | 103 |
|
104 | 104 |
} |
105 |
|
|
106 |
[HttpDelete("/annotation/{annotationId}/{tagInstanceId}")] |
|
107 |
[ProducesResponseType((int)HttpStatusCode.OK)] |
|
108 |
[ProducesResponseType((int)HttpStatusCode.Forbidden)] |
|
109 |
public ActionResult DeleteAnnotationInstance([FromServices] ClientInfo clientInfo, Guid annotationId, Guid tagInstanceId) |
|
110 |
{ |
|
111 |
if (clientInfo.LoggedUser == null) |
|
112 |
{ |
|
113 |
logger.Warning("ClientInfo has null LoggerUser in [Authorized] controller /annotations"); |
|
114 |
return Problem(); |
|
115 |
} |
|
116 |
|
|
117 |
// Take care of - non-admin user requesting not-assigned annotation |
|
118 |
// non-existent annotation |
|
119 |
try |
|
120 |
{ |
|
121 |
annotationService.DeleteAnnotationInstance(annotationId, tagInstanceId, clientInfo.LoggedUser.Id, clientInfo.LoggedUser.Role); |
|
122 |
return Ok(); |
|
123 |
} |
|
124 |
catch (InvalidOperationException e) |
|
125 |
{ |
|
126 |
throw new BadRequestException("Could not find specified annotation"); |
|
127 |
} |
|
128 |
catch (UnauthorizedAccessException) |
|
129 |
{ |
|
130 |
return Forbid(); |
|
131 |
} |
|
132 |
|
|
133 |
} |
|
105 | 134 |
} |
106 | 135 |
} |
Backend/Core/Services/AnnotationService/AnnotationServiceEF.cs | ||
---|---|---|
244 | 244 |
context.AnnotationTags.Add(annotationTag); |
245 | 245 |
context.SaveChanges(); |
246 | 246 |
} |
247 |
|
|
248 |
public void DeleteAnnotationInstance(Guid annotationId, Guid tagInstanceId, Guid loggedUserId, ERole userRole) |
|
249 |
{ |
|
250 |
Annotation annotation = null; |
|
251 |
try |
|
252 |
{ |
|
253 |
annotation = context.Annotations |
|
254 |
.Where(a => a.Id == annotationId) |
|
255 |
.Include(a => a.User) |
|
256 |
.Include(a => a.Document).ThenInclude(d => d.Content) |
|
257 |
.First(); |
|
258 |
|
|
259 |
} |
|
260 |
catch (Exception ex) |
|
261 |
{ |
|
262 |
throw new InvalidOperationException("Could not find annotation"); |
|
263 |
} |
|
264 |
|
|
265 |
|
|
266 |
if (userRole < ERole.ADMINISTRATOR) |
|
267 |
{ |
|
268 |
if (annotation.User.Id != loggedUserId) |
|
269 |
{ |
|
270 |
throw new UnauthorizedAccessException($"User {loggedUserId} does not have assigned annotation {annotationId}"); |
|
271 |
} |
|
272 |
} |
|
273 |
|
|
274 |
if (!context.AnnotationTags.Any(at => at.Id == tagInstanceId)) |
|
275 |
{ |
|
276 |
throw new InvalidOperationException("Could not find tag instance"); |
|
277 |
} |
|
278 |
|
|
279 |
context.AnnotationTags |
|
280 |
.Where(at => at.Id == tagInstanceId).ToList() |
|
281 |
.ForEach(a => context.AnnotationTags.Remove(a)); |
|
282 |
|
|
283 |
context.SaveChanges(); |
|
284 |
} |
|
247 | 285 |
} |
248 | 286 |
} |
Backend/Core/Services/AnnotationService/IAnnotationService.cs | ||
---|---|---|
14 | 14 |
public AnnotationListResponse GetUserAnnotations(Guid userId); |
15 | 15 |
public AnnotationInfo GetAnnotation(Guid annotationId, Guid userId, ERole userRole); |
16 | 16 |
public void AddAnnotationInstance(Guid annotationId, Guid userId, ERole userRole, AnnotationInstanceAddRequest request); |
17 |
public void DeleteAnnotationInstance(Guid annotationId, Guid tagInstanceId, Guid loggedUserId, ERole userRole); |
|
17 | 18 |
|
18 | 19 |
} |
19 | 20 |
} |
Backend/Models/Tags/TagInstanceInfo.cs | ||
---|---|---|
8 | 8 |
{ |
9 | 9 |
public class TagInstanceInfo |
10 | 10 |
{ |
11 |
/** For database */ |
|
12 |
public Guid Id { get; set; } |
|
11 | 13 |
public string TagName { get; set; } |
12 | 14 |
public Guid TagId { get; set; } |
13 | 15 |
public string TagCategoryName { get; set; } |
Také k dispozici: Unified diff
Endpoint for annotation instance deletion - untested