Revize f2275185
Přidáno uživatelem Vojtěch Bartička před téměř 3 roky(ů)
Backend/Backend/Controllers/AnnotationController.cs | ||
---|---|---|
153 | 153 |
// non-existent annotation |
154 | 154 |
try |
155 | 155 |
{ |
156 |
tagService.AddAnnotationInstance(annotationId, occurenceId, clientInfo.LoggedUser, request);
|
|
156 |
tagService.AddNoteToTagInstance(annotationId, occurenceId, clientInfo.LoggedUser, request);
|
|
157 | 157 |
return Ok(); |
158 | 158 |
} |
159 | 159 |
catch (InvalidOperationException e) |
160 | 160 |
{ |
161 |
throw new BadRequestException("Could not find specified annotation");
|
|
161 |
throw new BadRequestException(e.Message);
|
|
162 | 162 |
} |
163 | 163 |
catch (UnauthorizedAccessException) |
164 | 164 |
{ |
... | ... | |
166 | 166 |
} |
167 | 167 |
|
168 | 168 |
} |
169 |
|
|
170 |
[HttpPost("/annotation/{annotationId}/note")] |
|
171 |
[ProducesResponseType((int)HttpStatusCode.OK)] |
|
172 |
[ProducesResponseType((int)HttpStatusCode.Forbidden)] |
|
173 |
public ActionResult AddNoteToTagOccurence([FromServices] ClientInfo clientInfo, Guid annotationId, [FromBody] AddNoteToAnnotationRequest request) |
|
174 |
{ |
|
175 |
if (clientInfo.LoggedUser == null) |
|
176 |
{ |
|
177 |
logger.Warning("ClientInfo has null LoggerUser in [Authorized] controller /annotations"); |
|
178 |
return Problem(); |
|
179 |
} |
|
180 |
|
|
181 |
// Take care of - non-admin user requesting not-assigned annotation |
|
182 |
// non-existent annotation |
|
183 |
try |
|
184 |
{ |
|
185 |
annotationService.AddNoteToAnnotation(annotationId, clientInfo.LoggedUser.Id, clientInfo.LoggedUser.Role, request); |
|
186 |
return Ok(); |
|
187 |
} |
|
188 |
catch (InvalidOperationException e) |
|
189 |
{ |
|
190 |
throw new BadRequestException(e.Message); |
|
191 |
} |
|
192 |
catch (UnauthorizedAccessException) |
|
193 |
{ |
|
194 |
return Forbid(); |
|
195 |
} |
|
196 |
|
|
197 |
} |
|
198 |
|
|
169 | 199 |
} |
170 | 200 |
} |
Backend/Core/Services/AnnotationService/AnnotationServiceEF.cs | ||
---|---|---|
97 | 97 |
}; |
98 | 98 |
} |
99 | 99 |
|
100 |
public void AddNoteToAnnotation(Guid annotationId, Guid userId, ERole userRole, AddNoteToAnnotationRequest request) |
|
101 |
{ |
|
102 |
Annotation annotation = null; |
|
103 |
try |
|
104 |
{ |
|
105 |
annotation = context.Annotations.Include(a => a.User).First(a => a.Id == annotationId); |
|
106 |
} |
|
107 |
catch (Exception) |
|
108 |
{ |
|
109 |
throw new InvalidOperationException("Annotation not found"); |
|
110 |
} |
|
111 |
|
|
112 |
if (userRole < ERole.ADMINISTRATOR && annotation.User.Id != userId) |
|
113 |
{ |
|
114 |
throw new UnauthorizedAccessException("User does not have access to this annotation"); |
|
115 |
} |
|
116 |
|
|
117 |
annotation.Note = request.Note; |
|
118 |
context.SaveChanges(); |
|
119 |
} |
|
120 |
|
|
121 |
|
|
100 | 122 |
public AnnotationInfo GetAnnotation(Guid annotationId, Guid userId, ERole userRole) |
101 | 123 |
{ |
102 | 124 |
var annotation = context.Annotations |
... | ... | |
227 | 249 |
if (sanitizer.AllowedTags.Contains("script")) |
228 | 250 |
{ |
229 | 251 |
sanitizer.AllowedTags.Remove("script"); |
230 |
}
|
|
252 |
} |
|
231 | 253 |
if (!sanitizer.AllowedTags.Contains("style")) |
232 | 254 |
{ |
233 | 255 |
sanitizer.AllowedTags.Add("style"); |
Backend/Core/Services/AnnotationService/IAnnotationService.cs | ||
---|---|---|
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 | 17 |
public void DeleteAnnotationInstance(Guid annotationId, Guid tagInstanceId, Guid loggedUserId, ERole userRole); |
18 |
|
|
18 |
public void AddNoteToAnnotation(Guid annotationId, Guid userId, ERole userRole, AddNoteToAnnotationRequest request); |
|
19 | 19 |
} |
20 | 20 |
} |
Backend/Core/Services/TagService/ITagService.cs | ||
---|---|---|
22 | 22 |
public void CreateSubTag(CreateSubTagRequest request); |
23 | 23 |
public void DeleteSubTag(Guid subtagId); |
24 | 24 |
public void UpdateSubTag(ModifySubTagRequest request, Guid subtagId); |
25 |
public void AddAnnotationInstance(Guid annotationId, Guid occurrenceId, User user, AddNoteToTagOccurenceRequest request);
|
|
25 |
public void AddNoteToTagInstance(Guid annotationId, Guid occurrenceId, User user, AddNoteToTagOccurenceRequest request);
|
|
26 | 26 |
} |
27 | 27 |
} |
Backend/Core/Services/TagService/TagServiceEF.cs | ||
---|---|---|
233 | 233 |
databaseContext.SaveChanges(); |
234 | 234 |
} |
235 | 235 |
|
236 |
public void AddAnnotationInstance(Guid annotationId, Guid occurrenceId, User user, AddNoteToTagOccurenceRequest request)
|
|
236 |
public void AddNoteToTagInstance(Guid annotationId, Guid occurrenceId, User user, AddNoteToTagOccurenceRequest request)
|
|
237 | 237 |
{ |
238 | 238 |
Annotation annotation = null; |
239 | 239 |
try |
Backend/Models/Annotations/AddNoteToAnnotationRequest.cs | ||
---|---|---|
1 |
using System; |
|
2 |
using System.Collections.Generic; |
|
3 |
using System.Linq; |
|
4 |
using System.Text; |
|
5 |
using System.Threading.Tasks; |
|
6 |
|
|
7 |
namespace Models.Annotations |
|
8 |
{ |
|
9 |
public class AddNoteToAnnotationRequest |
|
10 |
{ |
|
11 |
public string Note { get; set; } |
|
12 |
} |
|
13 |
} |
Také k dispozici: Unified diff
Endpoint for adding Notes to annotations in AnnotationController