Ver código fonte

fixes can_read and can_write which didn't check rights at all (missing a condition on owner)

Damien Accorsi 11 anos atrás
pai
commit
b604ccde3e
1 arquivos alterados com 31 adições e 38 exclusões
  1. 31 38
      pboard/pboard/lib/auth.py

+ 31 - 38
pboard/pboard/lib/auth.py Ver arquivo

@@ -4,6 +4,29 @@ from tg.predicates import Predicate
4 4
 from pboard.model import DBSession as session
5 5
 from pboard.model.auth import Permission, User
6 6
 
7
+DIRTY_canReadOrCanWriteSqlQuery = """
8
+SELECT
9
+    node_id
10
+FROM
11
+    pod_group_node AS pgn
12
+    join pod_user_group AS pug on pug.group_id = pgn.group_id
13
+    join pod_user AS pu ON pug.user_id = pu.user_id
14
+WHERE
15
+    rights > :excluded_right_low_level
16
+    AND email_address = :email
17
+    AND node_id = :node_id
18
+UNION
19
+    SELECT
20
+        node_id
21
+    FROM
22
+        pod_nodes AS pnn,
23
+        pod_user AS puu
24
+    WHERE
25
+        pnn.node_id = :node_id
26
+        AND pnn.owner_id = puu.user_id
27
+        AND puu.email_address = :email
28
+"""
29
+
7 30
 class can_read(Predicate):
8 31
     message = ""
9 32
 
@@ -14,25 +37,10 @@ class can_read(Predicate):
14 37
         if 'node_id' in environ['webob.adhoc_attrs']['validation']['values']:
15 38
             node_id = environ['webob.adhoc_attrs']['validation']['values']['node_id']
16 39
             if node_id!=0:
17
-                has_right = session.execute("""
18
-                    select
19
-                        node_id
20
-                    from
21
-                        pod_group_node pgn
22
-                        join pod_user_group pug on pug.group_id = pgn.group_id
23
-                        join pod_user pu on pug.user_id = pu.user_id
24
-                    where
25
-                        rights > 0
26
-                        and email_address = :mail
27
-                        and node_id = :node
28
-                    union
29
-                        select
30
-                            node_id
31
-                        from
32
-                            pod_nodes
33
-                        where
34
-                            node_id = :node
35
-                        """, {"mail":credentials["repoze.who.userid"], "node":node_id})
40
+                has_right = session.execute(
41
+                    DIRTY_canReadOrCanWriteSqlQuery,
42
+                    {"email":credentials["repoze.who.userid"], "node_id":node_id, "excluded_right_low_level": 0}
43
+                )
36 44
                 if has_right.rowcount == 0 :
37 45
                     self.unmet()
38 46
 
@@ -46,25 +54,10 @@ class can_write(Predicate):
46 54
         if 'node_id' in environ['webob.adhoc_attrs']['validation']['values']:
47 55
             node_id = environ['webob.adhoc_attrs']['validation']['values']['node_id']
48 56
             if node_id!=0:
49
-                has_right = session.execute("""
50
-                        select
51
-                            node_id
52
-                        from
53
-                            pod_group_node pgn
54
-                            join pod_user_group pug on pug.group_id = pgn.group_id
55
-                            join pod_user pu on pug.user_id = pu.user_id
56
-                        where
57
-                            rights > 1
58
-                            and email_address = :mail
59
-                            and node_id = :node
60
-                        union
61
-                            select
62
-                                node_id
63
-                            from
64
-                                pod_nodes
65
-                            where
66
-                                node_id = :node
67
-                        """, {"mail":credentials["repoze.who.userid"], "node":node_id})
57
+                has_right = session.execute(
58
+                    DIRTY_canReadOrCanWriteSqlQuery,
59
+                    {"email":credentials["repoze.who.userid"], "node_id":node_id, "excluded_right_low_level": 1}
60
+                )
68 61
                 if has_right.rowcount == 0 :
69 62
                     self.unmet()
70 63