aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton@traccar.org>2023-01-15 17:37:20 -0800
committerAnton Tananaev <anton@traccar.org>2023-01-15 17:37:30 -0800
commit1417098fa45a3060f17e0cca6d8226b12e7f174e (patch)
treec756c75b102dddb80e1b68190d24128727a3d96a
parentdd25846efc91d53247f76b0afb8ee11b4fa8c341 (diff)
downloadtrackermap-server-1417098fa45a3060f17e0cca6d8226b12e7f174e.tar.gz
trackermap-server-1417098fa45a3060f17e0cca6d8226b12e7f174e.tar.bz2
trackermap-server-1417098fa45a3060f17e0cca6d8226b12e7f174e.zip
Remove default admin
-rw-r--r--schema/changelog-4.0-clean.xml8
-rw-r--r--src/main/java/org/traccar/api/resource/ServerResource.java8
-rw-r--r--src/main/java/org/traccar/api/resource/SessionResource.java5
-rw-r--r--src/main/java/org/traccar/api/resource/UserResource.java5
-rw-r--r--src/main/java/org/traccar/helper/model/UserUtil.java11
-rw-r--r--src/main/java/org/traccar/model/Server.java12
-rw-r--r--src/main/java/org/traccar/storage/query/Request.java6
7 files changed, 43 insertions, 12 deletions
diff --git a/schema/changelog-4.0-clean.xml b/schema/changelog-4.0-clean.xml
index f3f814eba..b4d8ac0ba 100644
--- a/schema/changelog-4.0-clean.xml
+++ b/schema/changelog-4.0-clean.xml
@@ -620,14 +620,6 @@
<column name="zoom" valueNumeric="0" />
</insert>
- <insert tableName="tc_users">
- <column name="name" value="admin" />
- <column name="email" value="admin" />
- <column name="hashedpassword" value="D33DCA55ABD4CC5BC76F2BC0B4E603FE2C6F61F4C1EF2D47" />
- <column name="salt" value="000000000000000000000000000000000000000000000000" />
- <column name="administrator" valueBoolean="true" />
- </insert>
-
</changeSet>
<changeSet author="author" id="changelog-4.0-clean-common">
diff --git a/src/main/java/org/traccar/api/resource/ServerResource.java b/src/main/java/org/traccar/api/resource/ServerResource.java
index e7f0b93ca..4b7ee9189 100644
--- a/src/main/java/org/traccar/api/resource/ServerResource.java
+++ b/src/main/java/org/traccar/api/resource/ServerResource.java
@@ -16,6 +16,7 @@
package org.traccar.api.resource;
import org.traccar.api.BaseResource;
+import org.traccar.helper.model.UserUtil;
import org.traccar.mail.MailManager;
import org.traccar.geocoder.Geocoder;
import org.traccar.helper.Log;
@@ -65,6 +66,13 @@ public class ServerResource extends BaseResource {
server.setEmailEnabled(mailManager.getEmailEnabled());
server.setGeocoderEnabled(geocoder != null);
User user = permissionsService.getUser(getUserId());
+ if (user != null) {
+ if (user.getAdministrator()) {
+ server.setStorageSpace(Log.getStorageSpace());
+ }
+ } else {
+ server.setNewServer(UserUtil.isEmpty(storage));
+ }
if (user != null && user.getAdministrator()) {
server.setStorageSpace(Log.getStorageSpace());
}
diff --git a/src/main/java/org/traccar/api/resource/SessionResource.java b/src/main/java/org/traccar/api/resource/SessionResource.java
index 1e984fbd0..7025d5fa7 100644
--- a/src/main/java/org/traccar/api/resource/SessionResource.java
+++ b/src/main/java/org/traccar/api/resource/SessionResource.java
@@ -110,7 +110,10 @@ public class SessionResource extends BaseResource {
} else {
- return permissionsService.getUser(userId);
+ User user = permissionsService.getUser(userId);
+ if (user != null) {
+ return user;
+ }
}
diff --git a/src/main/java/org/traccar/api/resource/UserResource.java b/src/main/java/org/traccar/api/resource/UserResource.java
index 91875ef51..e41ebbe61 100644
--- a/src/main/java/org/traccar/api/resource/UserResource.java
+++ b/src/main/java/org/traccar/api/resource/UserResource.java
@@ -19,6 +19,7 @@ import org.traccar.api.BaseObjectResource;
import org.traccar.config.Config;
import org.traccar.config.Keys;
import org.traccar.helper.LogAction;
+import org.traccar.helper.model.UserUtil;
import org.traccar.model.ManagedUser;
import org.traccar.model.Permission;
import org.traccar.model.User;
@@ -98,6 +99,10 @@ public class UserResource extends BaseObjectResource<User> {
}
}
+ if (UserUtil.isEmpty(storage)) {
+ entity.setAdministrator(true);
+ }
+
entity.setId(storage.addObject(entity, new Request(new Columns.Exclude("id"))));
storage.updateObject(entity, new Request(
new Columns.Include("hashedPassword", "salt"),
diff --git a/src/main/java/org/traccar/helper/model/UserUtil.java b/src/main/java/org/traccar/helper/model/UserUtil.java
index 9919e1d95..9f93afeae 100644
--- a/src/main/java/org/traccar/helper/model/UserUtil.java
+++ b/src/main/java/org/traccar/helper/model/UserUtil.java
@@ -17,6 +17,11 @@ package org.traccar.helper.model;
import org.traccar.model.Server;
import org.traccar.model.User;
+import org.traccar.storage.Storage;
+import org.traccar.storage.StorageException;
+import org.traccar.storage.query.Columns;
+import org.traccar.storage.query.Order;
+import org.traccar.storage.query.Request;
import java.util.TimeZone;
@@ -25,6 +30,12 @@ public final class UserUtil {
private UserUtil() {
}
+ public static boolean isEmpty(Storage storage) throws StorageException {
+ return storage.getObjects(User.class, new Request(
+ new Columns.Include("id"),
+ new Order("id", false, 1))).isEmpty();
+ }
+
public static String getDistanceUnit(Server server, User user) {
return lookupStringAttribute(server, user, "distanceUnit", "km");
}
diff --git a/src/main/java/org/traccar/model/Server.java b/src/main/java/org/traccar/model/Server.java
index 9e248e7bb..73645721b 100644
--- a/src/main/java/org/traccar/model/Server.java
+++ b/src/main/java/org/traccar/model/Server.java
@@ -249,4 +249,16 @@ public class Server extends ExtendedModel implements UserRestrictions {
this.storageSpace = storageSpace;
}
+ private boolean newServer;
+
+ @QueryIgnore
+ public boolean getNewServer() {
+ return newServer;
+ }
+
+ @QueryIgnore
+ public void setNewServer(boolean newServer) {
+ this.newServer = newServer;
+ }
+
}
diff --git a/src/main/java/org/traccar/storage/query/Request.java b/src/main/java/org/traccar/storage/query/Request.java
index 6e9cecc63..b9c2c963c 100644
--- a/src/main/java/org/traccar/storage/query/Request.java
+++ b/src/main/java/org/traccar/storage/query/Request.java
@@ -33,11 +33,11 @@ public class Request {
this(columns, condition, null);
}
- public Request(Columns columns, Condition condition, Order order) {
- this(columns, condition, order, null);
+ public Request(Columns columns, Order order) {
+ this(columns, null, order);
}
- public Request(Columns columns, Condition condition, Order order, Limit limit) {
+ public Request(Columns columns, Condition condition, Order order) {
this.columns = columns;
this.condition = condition;
this.order = order;