2424import com .khartec .waltz .model .authoritativesource .Rating ;
2525import com .khartec .waltz .model .changelog .ChangeLog ;
2626import com .khartec .waltz .model .changelog .ImmutableChangeLog ;
27+ import com .khartec .waltz .model .user .Role ;
2728import com .khartec .waltz .service .authoritative_source .AuthoritativeSourceService ;
2829import com .khartec .waltz .service .changelog .ChangeLogService ;
30+ import com .khartec .waltz .service .user .UserRoleService ;
2931import com .khartec .waltz .web .endpoints .Endpoint ;
3032import org .springframework .beans .factory .annotation .Autowired ;
3133import org .springframework .stereotype .Service ;
@@ -44,16 +46,20 @@ public class AuthoritativeSourceEndpoint implements Endpoint {
4446
4547 private final AuthoritativeSourceService authoritativeSourceService ;
4648 private final ChangeLogService changeLogService ;
49+ private final UserRoleService userRoleService ;
4750
4851
4952 @ Autowired
5053 public AuthoritativeSourceEndpoint (
5154 AuthoritativeSourceService authoritativeSourceService ,
55+ UserRoleService userRoleService ,
5256 ChangeLogService changeLogService ) {
5357 checkNotNull (authoritativeSourceService , "authoritativeSourceService must not be null" );
58+ checkNotNull (userRoleService , "userRoleService cannot be null" );
5459 checkNotNull (changeLogService , "changeLogService must not be null" );
5560
5661 this .authoritativeSourceService = authoritativeSourceService ;
62+ this .userRoleService = userRoleService ;
5763 this .changeLogService = changeLogService ;
5864 }
5965
@@ -70,13 +76,15 @@ public void register() {
7076 -> authoritativeSourceService .findByApplicationId (getId (request )));
7177
7278 post (mkPath (BASE_URL , "id" , ":id" ), (request , response ) -> {
79+ requireRole (userRoleService , request , Role .AUTHORITATIVE_SOURCE_EDITOR );
7380 String ratingStr = request .body ();
7481 Rating rating = Rating .valueOf (ratingStr );
7582 authoritativeSourceService .update (getId (request ), rating );
7683 return "done" ;
7784 });
7885
7986 delete (mkPath (BASE_URL , "id" , ":id" ), (request , response ) -> {
87+ requireRole (userRoleService , request , Role .AUTHORITATIVE_SOURCE_EDITOR );
8088 long id = getId (request );
8189 AuthoritativeSource authSource = authoritativeSourceService .getById (id );
8290 if (authSource == null ) {
@@ -103,6 +111,7 @@ public void register() {
103111 });
104112
105113 post (mkPath (BASE_URL , "kind" , ":kind" , ":id" , ":dataType" , ":appId" ), (request , response ) -> {
114+ requireRole (userRoleService , request , Role .AUTHORITATIVE_SOURCE_EDITOR );
106115 EntityReference parentRef = getEntityReference (request );
107116 String dataType = request .params ("dataType" );
108117 Long appId = getLong (request , "appId" );
0 commit comments