forked from traccar/traccar
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
63 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
/* | ||
* Copyright 2017 Anton Tananaev ([email protected]) | ||
* Copyright 2017 Andrey Kunitsyn ([email protected]) | ||
* Copyright 2017 - 2018 Anton Tananaev ([email protected]) | ||
* Copyright 2017 - 2018 Andrey Kunitsyn ([email protected]) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
|
@@ -33,9 +33,11 @@ | |
import org.traccar.database.SimpleObjectManager; | ||
import org.traccar.helper.LogAction; | ||
import org.traccar.model.BaseModel; | ||
import org.traccar.model.Calendar; | ||
import org.traccar.model.Command; | ||
import org.traccar.model.Device; | ||
import org.traccar.model.Group; | ||
import org.traccar.model.ScheduledModel; | ||
import org.traccar.model.User; | ||
|
||
public abstract class BaseObjectResource<T extends BaseModel> extends BaseResource { | ||
|
@@ -77,6 +79,9 @@ public Response add(T entity) throws SQLException { | |
Context.getPermissionsManager().checkDeviceLimit(getUserId()); | ||
} else if (baseClass.equals(Command.class)) { | ||
Context.getPermissionsManager().checkLimitCommands(getUserId()); | ||
} else if (entity instanceof ScheduledModel) { | ||
Context.getPermissionsManager().checkPermission(Calendar.class, getUserId(), | ||
((ScheduledModel) entity).getCalendarId()); | ||
} | ||
|
||
BaseObjectManager<T> manager = Context.getManager(baseClass); | ||
|
@@ -106,6 +111,9 @@ public Response update(T entity) throws SQLException { | |
Context.getPermissionsManager().checkUserUpdate(getUserId(), before, (User) entity); | ||
} else if (baseClass.equals(Command.class)) { | ||
Context.getPermissionsManager().checkLimitCommands(getUserId()); | ||
} else if (entity instanceof ScheduledModel) { | ||
Context.getPermissionsManager().checkPermission(Calendar.class, getUserId(), | ||
((ScheduledModel) entity).getCalendarId()); | ||
} | ||
Context.getPermissionsManager().checkPermission(baseClass, getUserId(), entity.getId()); | ||
|
||
|
@@ -151,6 +159,9 @@ public Response remove(@PathParam("id") long id) throws SQLException { | |
} else { | ||
Context.getPermissionsManager().refreshAllExtendedPermissions(); | ||
} | ||
} else if (baseClass.equals(Calendar.class)) { | ||
Context.getGeofenceManager().refreshItems(); | ||
Context.getNotificationManager().refreshItems(); | ||
} | ||
return Response.noContent().build(); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
/* | ||
* Copyright 2016 - 2017 Anton Tananaev ([email protected]) | ||
* Copyright 2016 - 2017 Andrey Kunitsyn ([email protected]) | ||
* Copyright 2016 - 2018 Anton Tananaev ([email protected]) | ||
* Copyright 2016 - 2018 Andrey Kunitsyn ([email protected]) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
|
@@ -19,13 +19,15 @@ | |
import java.lang.reflect.Field; | ||
import java.lang.reflect.Modifier; | ||
import java.sql.SQLException; | ||
import java.util.Date; | ||
import java.util.HashSet; | ||
import java.util.Map; | ||
import java.util.Map.Entry; | ||
import java.util.Set; | ||
|
||
import org.traccar.Context; | ||
import org.traccar.helper.Log; | ||
import org.traccar.model.Calendar; | ||
import org.traccar.model.Event; | ||
import org.traccar.model.Notification; | ||
import org.traccar.model.Position; | ||
|
@@ -42,12 +44,16 @@ public NotificationManager(DataManager dataManager) { | |
geocodeOnRequest = Context.getConfig().getBoolean("geocoder.onRequest"); | ||
} | ||
|
||
private Set<Long> getEffectiveNotifications(long userId, long deviceId) { | ||
private Set<Long> getEffectiveNotifications(long userId, long deviceId, Date date) { | ||
Set<Long> result = new HashSet<>(); | ||
Set<Long> deviceNotifications = getAllDeviceItems(deviceId); | ||
for (long itemId : getUserItems(userId)) { | ||
if (getById(itemId).getAlways() || deviceNotifications.contains(itemId)) { | ||
result.add(itemId); | ||
long calendarId = getById(itemId).getCalendarId(); | ||
Calendar calendar = calendarId != 0 ? Context.getCalendarManager().getById(calendarId) : null; | ||
if (calendar == null || calendar.checkMoment(date)) { | ||
result.add(itemId); | ||
} | ||
} | ||
} | ||
return result; | ||
|
@@ -73,7 +79,7 @@ public void updateEvent(Event event, Position position) { | |
boolean sentWeb = false; | ||
boolean sentMail = false; | ||
boolean sentSms = Context.getSmppManager() == null; | ||
for (long notificationId : getEffectiveNotifications(userId, deviceId)) { | ||
for (long notificationId : getEffectiveNotifications(userId, deviceId, event.getServerTime())) { | ||
Notification notification = getById(notificationId); | ||
if (getById(notificationId).getType().equals(event.getType())) { | ||
if (!sentWeb && notification.getWeb()) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* Copyright 2016 Anton Tananaev ([email protected]) | ||
* Copyright 2016 - 2018 Anton Tananaev ([email protected]) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
|
@@ -15,7 +15,7 @@ | |
*/ | ||
package org.traccar.model; | ||
|
||
public class Notification extends ExtendedModel { | ||
public class Notification extends ScheduledModel { | ||
|
||
private boolean always; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Copyright 2018 Anton Tananaev ([email protected]) | ||
* Copyright 2018 Andrey Kunitsyn ([email protected]) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.traccar.model; | ||
|
||
public class ScheduledModel extends ExtendedModel { | ||
|
||
private long calendarId; | ||
|
||
public long getCalendarId() { | ||
return calendarId; | ||
} | ||
|
||
public void setCalendarId(long calendarId) { | ||
this.calendarId = calendarId; | ||
} | ||
} |