[Lada-commits] [PATCH] Set readonly flag for proben using the mstId as criteria

Wald Commits scm-commit at wald.intevation.org
Tue Dec 17 12:11:02 CET 2013


# HG changeset patch
# User Raimund Renkert <raimund.renkert at intevation.de>
# Date 1387278644 -3600
# Node ID 414534a2c23d8a8ad67b200e6763a25a5575c503
# Parent  6ba7630c7e52a59dbad3afe023086cbe3089e02e
Set readonly flag for proben using the mstId as criteria.

diff -r 6ba7630c7e52 -r 414534a2c23d src/main/java/de/intevation/lada/data/LProbeRepository.java
--- a/src/main/java/de/intevation/lada/data/LProbeRepository.java	Mon Dec 16 11:23:40 2013 +0100
+++ b/src/main/java/de/intevation/lada/data/LProbeRepository.java	Tue Dec 17 12:10:44 2013 +0100
@@ -75,7 +75,8 @@
         String sql,
         List<String> filters,
         List<String> results,
-        MultivaluedMap<String, String> params) {
+        MultivaluedMap<String, String> params,
+        List<String> msts) {
         Query query = em.createNativeQuery(sql);
         for (String filter: filters) {
             List<String> param = params.get(filter);
@@ -89,17 +90,20 @@
         List<Map<String, Object>> res = new ArrayList<Map<String, Object>>();
         for (Object[] row: result) {
             Map<String, Object> set = new HashMap<String, Object>();
+            boolean ro = false;
             for (int i = 0; i < row.length; i++) {
                 set.put(results.get(i), row[i]);
                 if (results.get(i).equals("probeId")) {
                     if (authorization.isReadOnly((String)row[i])) {
-                        set.put("readonly", Boolean.TRUE);
-                    }
-                    else {
-                        set.put("readonly", Boolean.FALSE);
+                    	ro = true;
                     }
                 }
+                if (results.get(i).equals("mstId") &&
+                	!msts.contains((String)row[i])) {
+                	ro = true;
+                }
             }
+            set.put("readonly", ro);
             res.add(set);
         }
         return new Response(true, 200, res);
diff -r 6ba7630c7e52 -r 414534a2c23d src/main/java/de/intevation/lada/rest/LProbeService.java
--- a/src/main/java/de/intevation/lada/rest/LProbeService.java	Mon Dec 16 11:23:40 2013 +0100
+++ b/src/main/java/de/intevation/lada/rest/LProbeService.java	Tue Dec 17 12:10:44 2013 +0100
@@ -121,6 +121,7 @@
                 if (auth.getMst().contains(mstId)) {
                     return response;
                 }
+                p.setReadonly(true);
                 return response;
             }
             return new Response(false, 698, new ArrayList<LProbe>());
@@ -205,7 +206,8 @@
             }
             subselect += "or readonly = true) as lp";
             sql = sql.replace("l_probe", subselect);
-            return lpr.filterFree(sql, filters, results, params);
+            List<String> msts = auth.getMst();
+            return lpr.filterFree(sql, filters, results, params, msts);
         }
         catch(AuthenticationException ae) {
             return new Response(false, 699, new ArrayList<LProbe>());


More information about the Lada-commits mailing list