Skip to content

Commit 45b9fac

Browse files
authored
Merge pull request #4817 from gchq/gh-4815
#4815 Fix annotation initial assignedTo
2 parents 2ffcc5d + 45bab60 commit 45b9fac

File tree

22 files changed

+437
-138
lines changed

22 files changed

+437
-138
lines changed

Diff for: stroom-app/src/main/resources/ui/noauth/swagger/stroom.json

+30
Original file line numberDiff line numberDiff line change
@@ -10455,6 +10455,36 @@
1045510455
"tags" : [ "Authorisation" ]
1045610456
}
1045710457
},
10458+
"/userRef/v1/getUserByUuid" : {
10459+
"post" : {
10460+
"operationId" : "getUserByUuid",
10461+
"requestBody" : {
10462+
"content" : {
10463+
"application/json" : {
10464+
"schema" : {
10465+
"type" : "string"
10466+
}
10467+
}
10468+
},
10469+
"description" : "uuid",
10470+
"required" : true
10471+
},
10472+
"responses" : {
10473+
"default" : {
10474+
"content" : {
10475+
"application/json" : {
10476+
"schema" : {
10477+
"$ref" : "#/components/schemas/UserRef"
10478+
}
10479+
}
10480+
},
10481+
"description" : "default response"
10482+
}
10483+
},
10484+
"summary" : "Resolve a user ref by UUID",
10485+
"tags" : [ "Authorisation" ]
10486+
}
10487+
},
1045810488
"/users/v1/createGroup" : {
1045910489
"post" : {
1046010490
"operationId" : "createGroup",

Diff for: stroom-app/src/main/resources/ui/noauth/swagger/stroom.yaml

+20
Original file line numberDiff line numberDiff line change
@@ -7176,6 +7176,26 @@ paths:
71767176
user is admin or has Manage Users permission then they can see all users.
71777177
tags:
71787178
- Authorisation
7179+
/userRef/v1/getUserByUuid:
7180+
post:
7181+
operationId: getUserByUuid
7182+
requestBody:
7183+
content:
7184+
application/json:
7185+
schema:
7186+
type: string
7187+
description: uuid
7188+
required: true
7189+
responses:
7190+
default:
7191+
content:
7192+
application/json:
7193+
schema:
7194+
$ref: "#/components/schemas/UserRef"
7195+
description: default response
7196+
summary: Resolve a user ref by UUID
7197+
tags:
7198+
- Authorisation
71797199
/users/v1/createGroup:
71807200
post:
71817201
operationId: createGroup

Diff for: stroom-core-client/src/main/java/stroom/annotation/client/AnnotationEditPresenter.java

+11-9
Original file line numberDiff line numberDiff line change
@@ -265,15 +265,17 @@ private void changeAssignedTo(final UserRef selected) {
265265
}
266266

267267
private void setAssignedTo(final UserRef assignedTo) {
268-
currentAssignedTo = assignedTo;
269-
getView().setAssignedTo(assignedTo);
270-
// if (currentAssignedTo == null) {
271-
// assignedToPresenter.setClearSelectionText(null);
272-
// } else {
273-
// assignedToPresenter.setClearSelectionText("Clear");
274-
// }
275-
// assignedToPresenter.clearFilter();
276-
assignedToPresenter.setSelected(currentAssignedTo);
268+
assignedToPresenter.resolve(assignedTo, userRef -> {
269+
currentAssignedTo = userRef;
270+
getView().setAssignedTo(userRef);
271+
// if (currentAssignedTo == null) {
272+
// assignedToPresenter.setClearSelectionText(null);
273+
// } else {
274+
// assignedToPresenter.setClearSelectionText("Clear");
275+
// }
276+
// assignedToPresenter.clearFilter();
277+
assignedToPresenter.setSelected(currentAssignedTo);
278+
});
277279
}
278280

279281
private void changeComment(final String selected) {

Diff for: stroom-core-client/src/main/java/stroom/dashboard/client/table/AnnotationManager.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import stroom.query.api.v2.Column;
2828
import stroom.query.client.presenter.TableRow;
2929
import stroom.svg.shared.SvgImage;
30+
import stroom.util.shared.UserRef;
3031
import stroom.widget.menu.client.presenter.IconMenuItem;
3132
import stroom.widget.menu.client.presenter.Item;
3233
import stroom.widget.menu.client.presenter.ShowMenuEvent;
@@ -237,14 +238,16 @@ private void createAnnotation(final List<EventId> eventIdList) {
237238
final String title = getValue(tableComponentSettings, selectedItems, "title");
238239
final String subject = getValue(tableComponentSettings, selectedItems, "subject");
239240
final String status = getValue(tableComponentSettings, selectedItems, "status");
240-
// final String assignedTo = getValue(tableComponentSettings, selectedItems, "assignedTo");
241+
final String assignedTo = getValue(tableComponentSettings, selectedItems, "assignedTo");
241242
final String comment = getValue(tableComponentSettings, selectedItems, "comment");
242243

243244
final Annotation annotation = new Annotation();
244245
annotation.setTitle(title);
245246
annotation.setSubject(subject);
246247
annotation.setStatus(status);
247-
// annotation.setAssignedTo(optUserName);
248+
if (assignedTo != null) {
249+
annotation.setAssignedTo(UserRef.builder().uuid(assignedTo).build());
250+
}
248251
annotation.setComment(comment);
249252

250253
ShowAnnotationEvent.fire(changeStatusPresenter, annotation, eventIdList);

Diff for: stroom-core-client/src/main/java/stroom/hyperlink/client/HyperlinkEventHandlerImpl.java

+21-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@
1717
import stroom.pipeline.shared.stepping.StepType;
1818
import stroom.pipeline.stepping.client.event.BeginPipelineSteppingEvent;
1919
import stroom.task.client.TaskMonitorFactory;
20+
import stroom.util.client.Console;
2021
import stroom.util.shared.DefaultLocation;
2122
import stroom.util.shared.TextRange;
23+
import stroom.util.shared.UserRef;
2224
import stroom.widget.popup.client.event.RenamePopupEvent;
2325
import stroom.widget.popup.client.event.ShowPopupEvent;
2426
import stroom.widget.popup.client.presenter.PopupSize;
@@ -154,10 +156,11 @@ private void openAnnotation(final String href, final TaskMonitorFactory taskMoni
154156
final Long annotationId = getLongParam(href, "annotationId");
155157
final Long streamId = getLongParam(href.toLowerCase(Locale.ROOT), "streamId".toLowerCase(Locale.ROOT));
156158
final Long eventId = getLongParam(href.toLowerCase(Locale.ROOT), "eventId".toLowerCase(Locale.ROOT));
159+
final String eventIdList = getParam(href, "eventIdList");
157160
final String title = getParam(href, "title");
158161
final String subject = getParam(href, "subject");
159162
final String status = getParam(href, "status");
160-
// final String assignedTo = getParam(href, "assignedTo");
163+
final String assignedTo = getParam(href, "assignedTo");
161164
final String comment = getParam(href, "comment");
162165

163166
// assignedTo is a display name so have to convert it back to a unique username
@@ -166,14 +169,30 @@ private void openAnnotation(final String href, final TaskMonitorFactory taskMoni
166169
annotation.setTitle(title);
167170
annotation.setSubject(subject);
168171
annotation.setStatus(status);
169-
// annotation.setAssignedTo(assignedTo);
172+
if (assignedTo != null) {
173+
annotation.setAssignedTo(UserRef.builder().uuid(assignedTo).build());
174+
}
170175
annotation.setComment(comment);
171176

172177
final List<EventId> linkedEvents = new ArrayList<>();
173178
if (streamId != null && eventId != null) {
174179
linkedEvents.add(new EventId(streamId, eventId));
175180
}
176181

182+
if (eventIdList != null && !eventIdList.isBlank()) {
183+
final String[] eventIdStringArray = eventIdList.split(",");
184+
for (final String eventIdString : eventIdStringArray) {
185+
try {
186+
final EventId eventId1 = EventId.parse(eventIdString);
187+
if (eventId1 != null) {
188+
linkedEvents.add(eventId1);
189+
}
190+
} catch (final RuntimeException e) {
191+
Console.log(e::getMessage, e);
192+
}
193+
}
194+
}
195+
177196
ShowAnnotationEvent.fire(this, annotation, linkedEvents);
178197
}
179198

Diff for: stroom-core-client/src/main/java/stroom/security/client/presenter/UserRefPopupPresenter.java

+15
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import stroom.data.client.presenter.RestDataProvider;
2222
import stroom.data.grid.client.MyDataGrid;
2323
import stroom.data.grid.client.PagerView;
24+
import stroom.dispatch.client.DefaultErrorHandler;
2425
import stroom.dispatch.client.RestErrorHandler;
2526
import stroom.dispatch.client.RestFactory;
2627
import stroom.query.api.v2.ExpressionOperator;
@@ -220,6 +221,20 @@ public void setSelected(final UserRef userRef) {
220221
selectionModel.setSelected(userRef);
221222
}
222223

224+
public void resolve(final UserRef userRef, final Consumer<UserRef> consumer) {
225+
if (userRef == null || userRef.getUuid() == null) {
226+
consumer.accept(userRef);
227+
} else {
228+
restFactory
229+
.create(RESOURCE)
230+
.method(res -> res.getUserByUuid(userRef.getUuid()))
231+
.onSuccess(consumer)
232+
.onFailure(new DefaultErrorHandler(this, () -> consumer.accept(userRef)))
233+
.taskMonitorFactory(pagerView)
234+
.exec();
235+
}
236+
}
237+
223238
public void refresh() {
224239
if (dataProvider == null) {
225240
//noinspection Convert2Diamond // GWT

Diff for: stroom-core-shared/src/main/java/stroom/annotation/shared/EventId.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public boolean equals(final Object o) {
6161
}
6262
final EventId eventId1 = (EventId) o;
6363
return streamId == eventId1.streamId &&
64-
eventId == eventId1.eventId;
64+
eventId == eventId1.eventId;
6565
}
6666

6767
@Override

Diff for: stroom-core-shared/src/main/java/stroom/security/shared/UserRefResource.java

+9-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,15 @@ public interface UserRefResource extends RestResource, DirectRestService {
2525
@Path("/find")
2626
@Operation(
2727
summary = "Find the users and groups matching the supplied criteria of users who belong to at least " +
28-
"one of the same groups as the current user. If the current user is admin or has " +
29-
"Manage Users permission then they can see all users.",
28+
"one of the same groups as the current user. If the current user is admin or has " +
29+
"Manage Users permission then they can see all users.",
3030
operationId = "findUserRefs")
3131
ResultPage<UserRef> find(@Parameter(description = "criteria", required = true) FindUserCriteria criteria);
32+
33+
@POST
34+
@Path("/getUserByUuid")
35+
@Operation(
36+
summary = "Resolve a user ref by UUID",
37+
operationId = "getUserByUuid")
38+
UserRef getUserByUuid(@Parameter(description = "uuid", required = true) String uuid);
3239
}

Diff for: stroom-query/stroom-query-common/src/main/java/stroom/query/common/v2/ResultStoreManager.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -260,11 +260,13 @@ private SearchRequest addQueryKey(final SearchRequest searchRequest) {
260260
}
261261

262262
private SearchRequest addCurrentUserParam(final SearchRequest searchRequest) {
263-
// Add a param for `currentUser()`
264263
final List<Param> params = NullSafe.mutableList(searchRequest.getQuery().getParams());
265-
266264
final UserRef userRef = securityContext.getUserRef();
265+
params.add(new Param(ParamKeys.CURRENT_USER_UUID, userRef.getUuid()));
267266
params.add(new Param(ParamKeys.CURRENT_USER, userRef.toDisplayString()));
267+
if (userRef.getDisplayName() != null) {
268+
params.add(new Param(ParamKeys.CURRENT_USER_DISPLAY_NAME, userRef.getDisplayName()));
269+
}
268270
if (userRef.getSubjectId() != null) {
269271
params.add(new Param(ParamKeys.CURRENT_USER_SUBJECT_ID, userRef.getSubjectId()));
270272
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright 2017 Crown Copyright
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package stroom.query.language.functions;
18+
19+
import stroom.query.language.token.Param;
20+
21+
import java.text.ParseException;
22+
import java.util.Map;
23+
24+
abstract class AbstractCurrentUser extends AbstractFunction {
25+
26+
private Generator gen = Null.GEN;
27+
28+
public AbstractCurrentUser(final String name) {
29+
super(name, 0, 0);
30+
}
31+
32+
@Override
33+
public void setParams(final Param[] params) throws ParseException {
34+
super.setParams(params);
35+
}
36+
37+
@Override
38+
public void setStaticMappedValues(final Map<String, String> staticMappedValues) {
39+
final String v = staticMappedValues.get(getKey());
40+
if (v != null) {
41+
gen = new StaticValueGen(ValString.create(v));
42+
}
43+
}
44+
45+
@Override
46+
public Generator createGenerator() {
47+
return gen;
48+
}
49+
50+
@Override
51+
public boolean hasAggregate() {
52+
return false;
53+
}
54+
55+
abstract String getKey();
56+
}

0 commit comments

Comments
 (0)