summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMatthias Andreas Benkard <code@mail.matthias.benkard.de>2012-07-03 11:26:15 +0200
committerMatthias Andreas Benkard <code@mail.matthias.benkard.de>2012-07-03 12:45:16 +0200
commit4519ac40237342e0216f5fe7af2029810edc3a6e (patch)
treec47af9d46a9a4143d6e641ea14047236f8f2e70f /src
parent7e409d4ffd7e74a0b1489a298a829ef317596721 (diff)
Lafargue: Migrate to a role-based access control model.
Diffstat (limited to 'src')
-rw-r--r--src/mulk/benki/lazychat.clj28
1 files changed, 9 insertions, 19 deletions
diff --git a/src/mulk/benki/lazychat.clj b/src/mulk/benki/lazychat.clj
index b32e3af..bfee679 100644
--- a/src/mulk/benki/lazychat.clj
+++ b/src/mulk/benki/lazychat.clj
@@ -32,16 +32,11 @@
[message]
(fmt nil "<~A>\n\n~A" (:first_name message) (:content message)))
-(defn determine-targets [message]
- (letfn [(protected-targets []
- (with-dbt
- (map :id (query "SELECT id FROM users WHERE status IN ('admin', 'approved')"))))]
- (into #{}
- (concat (:targets message)
- (case (keyword (:visibility message))
- :personal nil
- :protected (protected-targets)
- :public (cons nil (protected-targets)))))))
+(defn determine-targets [message-id]
+ (with-dbt
+ (map :user (query "SELECT \"user\" FROM user_visible_lazychat_messages
+ WHERE message = ?"
+ message-id))))
(defn fill-in-author-details [x]
x)
@@ -83,7 +78,7 @@
(create-lazychat-message-by-user! *user* msg))
(defn push-message-to-xmpp [msg]
- (let [targets (filter integer? (determine-targets msg))]
+ (let [targets (filter integer? (determine-targets {:id msg}))]
(enqueue xmpp/messages {:message msg,
:targets targets})))
@@ -137,15 +132,10 @@
["SELECT m.id, m.author, m.date, m.content, m.format, u.first_name, u.last_name
FROM lazychat_messages m
JOIN users u ON (author = u.id)
- WHERE (visibility = 'public'
- OR (visibility = 'protected' AND (?::INTEGER) IS NOT NULL)
- OR (visibility = 'personal'
- AND EXISTS (SELECT *
- FROM lazychat_targets t
- WHERE t.target = (?::INTEGER)
- AND message = m.id)))
+ JOIN user_visible_lazychat_messages uvlm ON (uvlm.message = m.id)
+ WHERE uvlm.user IS NOT DISTINCT FROM ?
ORDER BY m.date DESC"
- ~user ~user]
+ ~user]
~@body))