Merge pull request #5409 from lucasleite01/manager-announcement

Allow managers to send announcements
This commit is contained in:
Anton Tananaev 2024-09-18 09:05:44 -07:00 committed by GitHub
commit 07ce5d82f2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -29,6 +29,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.traccar.api.ExtendedObjectResource;
import org.traccar.model.Event;
import org.traccar.model.ManagedUser;
import org.traccar.model.Notification;
import org.traccar.model.Typed;
import org.traccar.model.User;
@ -113,15 +114,26 @@ public class NotificationResource extends ExtendedObjectResource<Notification> {
public Response sendMessage(
@PathParam("notificator") String notificator, @QueryParam("userId") List<Long> userIds,
NotificationMessage message) throws MessageException, StorageException {
permissionsService.checkAdmin(getUserId());
permissionsService.checkManager(getUserId());
List<User> users;
if (userIds.isEmpty()) {
users = storage.getObjects(User.class, new Request(new Columns.All()));
if (permissionsService.notAdmin(getUserId())) {
users = storage.getObjects(User.class, new Request(new Columns.All(),
new Condition.Permission(User.class, getUserId(), ManagedUser.class).excludeGroups()));
} else {
users = storage.getObjects(User.class, new Request(new Columns.All()));
}
} else {
users = new ArrayList<>();
for (long userId : userIds) {
var conditions = new LinkedList<Condition>();
conditions.add(new Condition.Equals("id", userId));
if (permissionsService.notAdmin(getUserId())) {
conditions.add(new Condition.Permission(
User.class, getUserId(), ManagedUser.class).excludeGroups());
}
users.add(storage.getObject(
User.class, new Request(new Columns.All(), new Condition.Equals("id", userId))));
User.class, new Request(new Columns.All(), Condition.merge(conditions))));
}
}
for (User user : users) {