Browse code
Hide unapproved links for non-logged-in users, etc.
- Fix logout: clear the session
- Show moderated list for anonymous
- Refactor some of the boilerplate for controllers into :around methods.
Showing 2 changed files
... | ... |
@@ -72,7 +72,9 @@ |
72 | 72 |
|
73 | 73 |
(define-controller logout (params) |
74 | 74 |
(ningle:with-context-variables (session) |
75 |
- (setf (gethash :userinfo session) nil))) |
|
75 |
+ (setf (gethash :userinfo session) nil) |
|
76 |
+ (setf (gethash :app-user session) nil) |
|
77 |
+ (setf session nil))) |
|
76 | 78 |
|
77 | 79 |
(define-view logout (model) |
78 | 80 |
'(302 (:location "/"))) |
... | ... |
@@ -48,9 +48,9 @@ |
48 | 48 |
(with-slots (headline url approved) obj |
49 | 49 |
(format s "H: ~s U: ~s A: ~s" headline url approved)))) |
50 | 50 |
|
51 |
-(defmacro with-submissions (&body b) |
|
51 |
+(defmacro with-submissions ((&key (test nil)) &body b) |
|
52 | 52 |
`(with-db |
53 |
- (let ((*submissions* (postmodern:select-dao 'submission t "date desc"))) |
|
53 |
+ (let ((*submissions* (postmodern:select-dao 'submission ,(or test t) "date desc"))) |
|
54 | 54 |
,@b))) |
55 | 55 |
|
56 | 56 |
(defun submission-alist (submission) |
... | ... |
@@ -65,15 +65,25 @@ |
65 | 65 |
:links (mapcar #'submission-alist links) |
66 | 66 |
:user (when user (inangulis.user:user-alist user))) |
67 | 67 |
|
68 |
-(define-controller root (params) |
|
69 |
- (with-submissions |
|
70 |
- (ningle:with-context-variables (session) |
|
68 |
+(defmethod controller :around ((name (eql 'root)) params &key) |
|
69 |
+ (let* ((session (ningle:context :session)) |
|
70 |
+ (user (gethash :app-user session))) |
|
71 |
+ (format t "~&THE USER IS: ~s~%" user) |
|
72 |
+ (with-submissions (:test (:raw |
|
73 |
+ (if (null user) |
|
74 |
+ (s-sql:sql (:= 'approved "approved")) |
|
75 |
+ (progn |
|
76 |
+ "'t'") |
|
77 |
+ ))) |
|
71 | 78 |
(handler-case |
72 | 79 |
(cl-oid-connect.utils:ensure-logged-in |
73 |
- (cl-oid-connect.utils:redirect-if-necessary session |
|
74 |
- (cons (gethash :app-user session) |
|
75 |
- *submissions*))) |
|
76 |
- (cl-oid-connect.utils:user-not-logged-in (c) (cons nil *submissions*)))))) |
|
80 |
+ (call-next-method)) |
|
81 |
+ (cl-oid-connect.utils:user-not-logged-in (c) (declare (ignore c)) (cons nil *submissions*)))))) |
|
82 |
+ |
|
83 |
+(define-controller root (params) |
|
84 |
+ (ningle:with-context-variables (session) |
|
85 |
+ (cl-oid-connect.utils:redirect-if-necessary session |
|
86 |
+ (cons (gethash :app-user session) *submissions*)))) |
|
77 | 87 |
|
78 | 88 |
(defun submit (params) |
79 | 89 |
(ningle:with-context-variables (session) |