- Add server-wide "device readonly" flag

- Allow "device readonly" users send commands
This commit is contained in:
Abyss777
2017-02-27 11:22:56 +05:00
parent 61a1bae779
commit bb0a5ccd64
5 changed files with 16 additions and 2 deletions

View File

@@ -16,6 +16,10 @@
<column name="sms" type="BOOLEAN" defaultValueBoolean="false" />
</addColumn>
<addColumn tableName="server">
<column name="devicereadonly" type="BOOLEAN" defaultValueBoolean="false" />
</addColumn>
</changeSet>
</databaseChangeLog>

View File

@@ -41,6 +41,7 @@
UPDATE server SET
registration = :registration,
readonly = :readonly,
deviceReadonly = :deviceReadonly,
map = :map,
bingKey = :bingKey,
mapUrl = :mapUrl,

View File

@@ -34,7 +34,6 @@ public class CommandResource extends BaseResource {
@POST
public Response add(Command entity) {
Context.getPermissionsManager().checkReadonly(getUserId());
Context.getPermissionsManager().checkDeviceReadonly(getUserId());
Context.getPermissionsManager().checkDevice(getUserId(), entity.getDeviceId());
Context.getConnectionManager().getActiveDevice(entity.getDeviceId()).sendCommand(entity);
return Response.ok(entity).build();

View File

@@ -223,7 +223,7 @@ public class PermissionsManager {
}
public void checkDeviceReadonly(long userId) throws SecurityException {
if (!isAdmin(userId) && isDeviceReadonly(userId)) {
if (!isAdmin(userId) && (server.getDeviceReadonly() || isDeviceReadonly(userId))) {
throw new SecurityException("Account is device readonly");
}
}

View File

@@ -46,6 +46,16 @@ public class Server extends Extensible {
this.readonly = readonly;
}
private boolean deviceReadonly;
public boolean getDeviceReadonly() {
return deviceReadonly;
}
public void setDeviceReadonly(boolean deviceReadonly) {
this.deviceReadonly = deviceReadonly;
}
private String map;
public String getMap() {