mirror of
https://github.com/traccar/traccar.git
synced 2025-01-07 03:07:01 +08:00
Merge pull request #5409 from lucasleite01/manager-announcement
Allow managers to send announcements
This commit is contained in:
commit
07ce5d82f2
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user