add moderation_action type
This commit is contained in:
parent
4f73a6e559
commit
7d402914fc
4 changed files with 47 additions and 16 deletions
|
|
@ -1,6 +1,22 @@
|
||||||
open Db
|
open Db
|
||||||
include Bindings
|
include Bindings
|
||||||
|
|
||||||
|
type moderation_action =
|
||||||
|
| Ignore
|
||||||
|
| Delete
|
||||||
|
| Banish
|
||||||
|
|
||||||
|
let moderation_action_to_string = function
|
||||||
|
| Ignore -> "ignore"
|
||||||
|
| Delete -> "delete"
|
||||||
|
| Banish -> "banish"
|
||||||
|
|
||||||
|
let moderation_action_from_string = function
|
||||||
|
| "ignore" -> Some Ignore
|
||||||
|
| "delete" -> Some Delete
|
||||||
|
| "banish" -> Some Banish
|
||||||
|
| _ -> None
|
||||||
|
|
||||||
type thread_data =
|
type thread_data =
|
||||||
{ subject : string
|
{ subject : string
|
||||||
; lng : float
|
; lng : float
|
||||||
|
|
|
||||||
|
|
@ -115,11 +115,13 @@ let admin_post request =
|
||||||
| Error _e as e -> e
|
| Error _e as e -> e
|
||||||
| Ok post -> (
|
| Ok post -> (
|
||||||
let evil_user_id = post.user_id in
|
let evil_user_id = post.user_id in
|
||||||
match action with
|
match Babillard.moderation_action_from_string action with
|
||||||
| "delete" -> Babillard.try_delete_post ~user_id:evil_user_id id
|
| None -> Error "Invalid action"
|
||||||
| "banish" -> User.banish evil_user_id
|
| Some action -> (
|
||||||
| "ignore" -> Babillard.ignore_report id
|
match action with
|
||||||
| a -> Error (Format.sprintf "invalid action: `%s`" a) )
|
| Delete -> Babillard.try_delete_post ~user_id:evil_user_id id
|
||||||
|
| Banish -> User.banish evil_user_id
|
||||||
|
| Ignore -> Babillard.ignore_report id ) )
|
||||||
in
|
in
|
||||||
match res with
|
match res with
|
||||||
| Error e -> render_unsafe e request
|
| Error e -> render_unsafe e request
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,22 @@ include Bindings
|
||||||
include Babillard
|
include Babillard
|
||||||
open Db
|
open Db
|
||||||
|
|
||||||
|
type moderation_action =
|
||||||
|
| Ignore
|
||||||
|
| Delete
|
||||||
|
| Banish
|
||||||
|
|
||||||
|
let moderation_action_to_string = function
|
||||||
|
| Ignore -> "ignore"
|
||||||
|
| Delete -> "delete"
|
||||||
|
| Banish -> "banish"
|
||||||
|
|
||||||
|
let moderation_action_from_string = function
|
||||||
|
| "ignore" -> Some Ignore
|
||||||
|
| "delete" -> Some Delete
|
||||||
|
| "banish" -> Some Banish
|
||||||
|
| _ -> None
|
||||||
|
|
||||||
let pp_post fmt t =
|
let pp_post fmt t =
|
||||||
let thread_data_opt, post =
|
let thread_data_opt, post =
|
||||||
match t with
|
match t with
|
||||||
|
|
@ -177,16 +193,16 @@ let pp_report fmt post report request =
|
||||||
Format.fprintf fmt
|
Format.fprintf fmt
|
||||||
{|<input value="%s" name="post_id" type="hidden"></input>|} id
|
{|<input value="%s" name="post_id" type="hidden"></input>|} id
|
||||||
in
|
in
|
||||||
let button fmt value =
|
let button fmt action =
|
||||||
|
let s = moderation_action_to_string action in
|
||||||
Format.fprintf fmt
|
Format.fprintf fmt
|
||||||
{|<button value="%s" name="action" type="submit" class="btn btn-primary">%s</button>|}
|
{|<button value="%s" name="action" type="submit" class="btn btn-primary">%s</button>|}
|
||||||
value
|
s (String.uppercase_ascii s)
|
||||||
(String.uppercase_ascii value)
|
|
||||||
in
|
in
|
||||||
let form fmt value =
|
let form fmt action =
|
||||||
Format.fprintf fmt {|%s %a %a </form>|}
|
Format.fprintf fmt {|%s %a %a </form>|}
|
||||||
(Dream.form_tag ~action:url request)
|
(Dream.form_tag ~action:url request)
|
||||||
input_post_id id button value
|
input_post_id id button action
|
||||||
in
|
in
|
||||||
|
|
||||||
Format.fprintf fmt
|
Format.fprintf fmt
|
||||||
|
|
@ -210,8 +226,7 @@ let pp_report fmt post report request =
|
||||||
</div>
|
</div>
|
||||||
</div><br>
|
</div><br>
|
||||||
|}
|
|}
|
||||||
pp_post (Post post) reporter_nick reason form "ignore" form "delete" form
|
pp_post (Post post) reporter_nick reason form Ignore form Delete form Banish
|
||||||
"banish"
|
|
||||||
|
|
||||||
let admin_page_content posts reports request =
|
let admin_page_content posts reports request =
|
||||||
let posts_reports = List.combine posts reports in
|
let posts_reports = List.combine posts reports in
|
||||||
|
|
|
||||||
|
|
@ -321,8 +321,7 @@ let update_metadata count label content user_id =
|
||||||
let^ () = Db.exec Q.upload_metadata (user_id, s) in
|
let^ () = Db.exec Q.upload_metadata (user_id, s) in
|
||||||
Ok ()
|
Ok ()
|
||||||
|
|
||||||
let pp_metadata fmt pair =
|
let pp_metadata fmt (label, content) =
|
||||||
let label, content = pair in
|
|
||||||
Format.fprintf fmt
|
Format.fprintf fmt
|
||||||
{|
|
{|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
|
@ -332,8 +331,7 @@ let pp_metadata fmt pair =
|
||||||
|}
|
|}
|
||||||
label content
|
label content
|
||||||
|
|
||||||
let pp_metadata_form fmt is_last count pair request =
|
let pp_metadata_form fmt is_last count (label, content) request =
|
||||||
let label, content = pair in
|
|
||||||
let form_tag = Dream.form_tag ~action:"/profile" request in
|
let form_tag = Dream.form_tag ~action:"/profile" request in
|
||||||
let button_text = if is_last then "Add" else "Save" in
|
let button_text = if is_last then "Add" else "Save" in
|
||||||
Format.fprintf fmt
|
Format.fprintf fmt
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue