Skip to content

Commit

Permalink
Expose data source read permission
Browse files Browse the repository at this point in the history
  • Loading branch information
terrypacker committed Mar 12, 2020
1 parent 6a76028 commit b2a08aa
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -249,15 +249,15 @@ public void row(DataPointVO point, int index) {
DataSourceVO newDs = dataSourceDao.get(k);
return newDs;
});
if(!permissionService.hasDataSourcePermission(user, source))
if(!permissionService.hasDataSourceEditPermission(user, source))
hasPermission.setFalse();
}
}else {
DataSourceVO source = sources.computeIfAbsent(point.getDataSourceId(), k -> {
DataSourceVO newDs = dataSourceDao.get(k);
return newDs;
});
if(!permissionService.hasDataSourcePermission(user, source))
if(!permissionService.hasDataSourceEditPermission(user, source))
hasPermission.setFalse();
}
}
Expand Down Expand Up @@ -289,7 +289,7 @@ public void row(DataSourceVO source, int index) {
//short circuit the logic if we already failed
return;
}else {
if(!permissionService.hasDataSourcePermission(user, source))
if(!permissionService.hasDataSourceEditPermission(user, source))
hasPermission.setFalse();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public boolean hasPermission(PermissionHolder user, PermissionService service) {
return false;
else {
for(int dsId : vo.getDataSources())
if(!service.hasDataSourcePermission(user, dsId))
if(!service.hasDataSourceEditPermission(user, dsId))
return false;

for(int dpId : vo.getDataPoints()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ public Map<String, String> setTagsForDataPoint(
DataPointVO dataPoint = dataPointService.get(xid);

PermissionHolder user = Common.getUser();
permissionService.ensureDataSourcePermission(user, dataPoint.getDataSourceId());
permissionService.ensureDataSourceEditPermission(user, dataPoint.getDataSourceId());

dataPoint.setTags(tags);
dataPointTagsDao.saveDataPointTags(dataPoint);
Expand All @@ -285,7 +285,7 @@ public Map<String, String> mergeTagsForDataPoint(
return dataPointTagsDao.doInTransaction(txStatus -> {
DataPointVO dataPoint = dataPointService.get(xid);
PermissionHolder user = Common.getUser();
permissionService.ensureDataSourcePermission(user, dataPoint.getDataSourceId());
permissionService.ensureDataSourceEditPermission(user, dataPoint.getDataSourceId());

Map<String, String> existingTags = dataPointTagsDao.getTagsForDataPointId(dataPoint.getId());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ private List<EventTypeVOModel<?,?,?>> getEventTypesForSubtype(String typeName, S
throw new BadRequestException();

for(DataSourceVO vo : dataSourceDao.getAll()) {
if(permissionService.hasDataSourcePermission(user, vo)) {
if(permissionService.hasDataSourceEditPermission(user, vo)) {
AbstractDataSourceModel<?> dsModel = modelMapper.map(vo, AbstractDataSourceModel.class, user);
DataSourceEventTypeModel model = new DataSourceEventTypeModel(new DataSourceEventType(vo.getId(), 0), dsModel);
types.add(new EventTypeVOModel<DataSourceEventType, AbstractDataSourceModel<?>, String>(model, new TranslatableMessage("event.eventsFor", vo.getName()), false, true, true));
Expand Down Expand Up @@ -420,7 +420,7 @@ private List<EventTypeVOModel<?,?,?>> getEventTypesForSubtypeAndReferenceId1(Str
if(ds == null)
throw new NotFoundException();

permissionService.ensureDataSourcePermission(user, ds);
permissionService.ensureDataSourceEditPermission(user, ds);
AbstractDataSourceModel<?> dsModel = modelMapper.map(ds, AbstractDataSourceModel.class, user);
for(EventTypeVO type : ds.getEventTypes()) {
DataSourceEventType eventType = (DataSourceEventType)type.getEventType();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1195,7 +1195,7 @@ private ResponseEntity<TemporaryResource<PurgePointValuesResponseModel, Abstract
throw new NotFoundException();

//Ensure edit permission
permissionService.ensureDataSourcePermission(user, ds);
permissionService.ensureDataSourceEditPermission(user, ds);

//Do purge based on settings
if(model.isPurgeAll())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public abstract class AbstractDataSourceModel<T extends DataSourceVO> extends Ab
private List<EventTypeAlarmLevelModel> eventAlarmLevels;
private PurgeSettings purgeSettings;
private Set<String> editPermission;
private Set<String> readPermission;

public AbstractDataSourceModel() {

Expand Down Expand Up @@ -102,6 +103,10 @@ public void fromVO(T vo) {
for(Role role : vo.getEditRoles()) {
this.editPermission.add(role.getXid());
}
this.readPermission = new HashSet<>();
for(Role role : vo.getReadRoles()) {
this.readPermission.add(role.getXid());
}
}

@Override
Expand All @@ -118,6 +123,7 @@ public T toVO() {
purgeSettings.toVO(vo);
PermissionService service = Common.getBean(PermissionService.class);
vo.setEditRoles(service.explodeLegacyPermissionGroupsToRoles(editPermission));
vo.setReadRoles(service.explodeLegacyPermissionGroupsToRoles(readPermission));
return vo;
}

Expand Down Expand Up @@ -201,4 +207,12 @@ public void setEditPermission(Set<String> editPermission) {
this.editPermission = editPermission;
}

public Set<String> getReadPermission() {
return readPermission;
}

public void setReadPermission(Set<String> readPermission) {
this.readPermission = readPermission;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public DataPointWebSocketHandler(RestModelMapper mapper, PermissionService permi

@Override
protected boolean hasPermission(PermissionHolder user, DataPointVO vo) {
return user.hasAdminRole() || permissionService.hasDataSourcePermission(user, vo.getDataSourceId());
return user.hasAdminRole() || permissionService.hasDataSourceEditPermission(user, vo.getDataSourceId());
}

@Override
Expand Down

0 comments on commit b2a08aa

Please sign in to comment.