Search in sources :

Example 76 with Permissions

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;
}
Also used : User(com.serotonin.m2m2.vo.User) ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) ArrayList(java.util.ArrayList) ReportDao(com.serotonin.m2m2.reports.ReportDao) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 77 with Permissions

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);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) DataPointVO(com.serotonin.m2m2.vo.DataPointVO) User(com.serotonin.m2m2.vo.User) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 78 with Permissions

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());
}
Also used : User(com.serotonin.m2m2.vo.User) AtomicLong(java.util.concurrent.atomic.AtomicLong) RQLParser(net.jazdw.rql.parser.RQLParser) ASTNode(net.jazdw.rql.parser.ASTNode) AtomicLong(java.util.concurrent.atomic.AtomicLong) StreamableRowCallback(com.infiniteautomation.mango.db.query.StreamableRowCallback) Test(org.junit.Test)

Example 79 with Permissions

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;
}
Also used : User(com.serotonin.m2m2.vo.User) PermissionDetails(com.serotonin.m2m2.vo.permission.PermissionDetails) ArrayList(java.util.ArrayList) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 80 with Permissions

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;
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) User(com.serotonin.m2m2.vo.User) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Aggregations

User (com.serotonin.m2m2.vo.User)61 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)43 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)43 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)40 RestProcessResult (com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult)36 ArrayList (java.util.ArrayList)27 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)20 PermissionException (com.serotonin.m2m2.vo.permission.PermissionException)17 DwrPermission (com.serotonin.m2m2.web.dwr.util.DwrPermission)16 NotFoundRestException (com.infiniteautomation.mango.rest.v2.exception.NotFoundRestException)15 HashMap (java.util.HashMap)15 List (java.util.List)14 ProcessResult (com.serotonin.m2m2.i18n.ProcessResult)10 ASTNode (net.jazdw.rql.parser.ASTNode)10 PointValueTime (com.serotonin.m2m2.rt.dataImage.PointValueTime)9 RestValidationFailedException (com.serotonin.m2m2.web.mvc.rest.v1.exception.RestValidationFailedException)8 DataPointModel (com.serotonin.m2m2.web.mvc.rest.v1.model.DataPointModel)8 URI (java.net.URI)8 Map (java.util.Map)8 ResponseEntity (org.springframework.http.ResponseEntity)7