use of com.serotonin.m2m2.vo.permission.Permissions in project ma-modules-public by infiniteautomation.
the class ReportsDwr method init.
@DwrPermission(custom = ReportPermissionDefinition.PERMISSION)
public ProcessResult init() {
ProcessResult response = new ProcessResult();
ReportDao reportDao = ReportDao.instance;
User user = Common.getUser();
response.addData("points", getReadablePoints());
response.addData("mailingLists", MailingListDao.instance.getMailingLists());
if (Permissions.hasAdmin(user)) {
response.addData("users", UserDao.instance.getUsers());
response.addData("reports", reportDao.getReports());
response.addData("instances", getReportInstances(user));
} else {
response.addData("reports", reportDao.getReports(user.getId()));
response.addData("instances", getReportInstances(user));
// Filter User's available to Email on User Permissions
List<User> users = UserDao.instance.getUsers();
List<User> availableForEmail = new ArrayList<User>();
String currentUserPermissions = user.getPermissions();
for (User u : users) {
// Check to see if there are any overlapping privs, if so then add them to the view
Set<String> permissions = Permissions.findMatchingPermissions(u.getPermissions(), currentUserPermissions);
if (permissions.size() > 0)
availableForEmail.add(u);
}
response.addData("users", availableForEmail);
}
response.addData("templates", getTemplateList());
return response;
}
use of com.serotonin.m2m2.vo.permission.Permissions in project ma-modules-public by infiniteautomation.
the class WatchListDwr method addToWatchList.
@DwrPermission(user = true)
public WatchListState addToWatchList(int pointId) {
HttpServletRequest request = WebContextFactory.get().getHttpServletRequest();
User user = Common.getUser();
DataPointVO point = DataPointDao.instance.getDataPoint(pointId);
if (point == null)
return null;
WatchListVO watchList = getWatchList(user);
// Check permissions.
Permissions.ensureDataPointReadPermission(user, point);
WatchListCommon.ensureWatchListEditPermission(user, watchList);
// Add it to the watch list.
watchList.getPointList().add(point);
WatchListDao.instance.saveWatchList(watchList);
updateSetPermission(point, user);
// Return the watch list state for it.
return createWatchListState(request, point, Common.runtimeManager, new HashMap<String, Object>(), user);
}
use of com.serotonin.m2m2.vo.permission.Permissions in project ma-modules-public by infiniteautomation.
the class WatchlistSqlVisitorTest method testRQL.
@Test
public void testRQL() throws IOException {
// Create a User
User user = new User();
user.setUsername("test");
user.setName("test");
user.setEmail("test@test.com");
user.setPassword("usernametest");
user.setPermissions("user,test,permission1");
validate(user);
UserDao.instance.saveUser(user);
// Insert some watchlists
for (int i = 0; i < 120; i++) {
WatchListVO wl = new WatchListVO();
wl.setXid(WatchListDao.instance.generateUniqueXid());
wl.setName("Watchilst " + i);
wl.setUserId(user.getId());
wl.setReadPermission("permission1");
WatchListDao.instance.saveWatchList(wl);
}
String rql = "limit(100,0)";
RQLParser parser = new RQLParser();
ASTNode root = null;
ASTNode queryNode = parser.parse(rql);
// Combine the existing query with an AND node
if (queryNode == null) {
root = new ASTNode("eq", "userId", user.getId());
} else {
// Filter by Permissions
Set<String> permissions = Permissions.explodePermissionGroups(user.getPermissions());
ASTNode permRQL = new ASTNode("in", "readPermission", permissions);
root = new ASTNode("or", new ASTNode("eq", "userId", user.getId()), permRQL, queryNode);
}
final AtomicLong selectCounter = new AtomicLong();
final AtomicLong countValue = new AtomicLong();
StreamableRowCallback<WatchListVO> selectCallback = new StreamableRowCallback<WatchListVO>() {
@Override
public void row(WatchListVO row, int index) throws Exception {
selectCounter.incrementAndGet();
}
};
StreamableRowCallback<Long> countCallback = new StreamableRowCallback<Long>() {
@Override
public void row(Long row, int index) throws Exception {
countValue.set(row);
}
};
StreamableSqlQuery<WatchListVO> query = WatchListDao.instance.createQuery(root, selectCallback, countCallback, modelMap, appenders, true);
query.query();
query.count();
assertEquals(100L, selectCounter.get());
assertEquals(120L, countValue.get());
}
use of com.serotonin.m2m2.vo.permission.Permissions in project ma-core-public by infiniteautomation.
the class BaseDwr method getUserPermissionInfo.
/**
* Power tools for user permissions.
*/
@DwrPermission(user = true)
public List<PermissionDetails> getUserPermissionInfo(String query) {
List<PermissionDetails> ds = new ArrayList<>();
User currentUser = Common.getUser();
for (User user : UserDao.instance.getActiveUsers()) {
PermissionDetails deets = Permissions.getPermissionDetails(currentUser, query, user);
if (deets != null)
ds.add(deets);
}
return ds;
}
use of com.serotonin.m2m2.vo.permission.Permissions in project ma-core-public by infiniteautomation.
the class BaseDwr method setPoint.
/**
* Allows the setting of a given data point. Used by the watch list and
* point details pages. Views implement their own version to accommodate
* anonymous users.
*
* @param pointId
* @param valueStr
* @return
*/
@DwrPermission(user = true)
public int setPoint(int pointId, int componentId, String valueStr) {
User user = Common.getUser();
DataPointVO point = DataPointDao.instance.getDataPoint(pointId);
// Check permissions.
Permissions.ensureDataPointSetPermission(user, point);
setPointImpl(point, valueStr, user);
return componentId;
}
Aggregations