Added blacklisting languages for problems
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Mon, 30 Sep 2019 20:28:23 +0000 (15:28 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Mon, 30 Sep 2019 20:28:23 +0000 (15:28 -0500)
codebox/controllers/admin/problem/edit.moon
codebox/controllers/problem/submit.moon
codebox/migrations.moon
codebox/views/admin/problem/edit.moon
codebox/views/problem/problem.moon
codebox/views/problem/submit.moon
docs/todo

index 9b66dc9e794404adfde0eb5d93c4270086d35190..d3f06bbd04688e53245ff2348cbba3e2286f2e06 100644 (file)
@@ -39,6 +39,7 @@ make_controller
                        { "description", exists: true }
                        { "time_limit", exists: true, is_integer: true }
             { "kind", exists: true }
+                       { "blacklisted_langs", exists: true }
                }
 
                @problem = Problems\find @params.problem_id
@@ -52,6 +53,7 @@ make_controller
                        description: @params.description
                        time_limit: @params.time_limit
             kind: Problems.kinds\for_db @params.kind
+                       blacklisted_langs: @params.blacklisted_langs
                }
 
                redirect_to: (@url_for "admin.problem.edit", problem_name: @params.short_name)
index db3dc634f203b2ad2223c6ca89f7542c099db8ec..12e76b01a503996b1b8032c73fa14ec3b367eb10 100644 (file)
@@ -33,6 +33,10 @@ make_controller
         unless problem
             return json: { status: 'problem not found' }
 
+               blacklisted = string.split problem.blacklisted_langs, ','
+               if table.contains blacklisted, @params.lang
+                       return json: { status: 'Language is blacklisted for this problem' }
+
         test_cases = problem\get_test_cases!
 
         id = @executer\request @params.lang, @params.code, @user.id, problem.id, @competition.id, test_cases, problem.time_limit
index 5bc34bef8545dfb238e2a9156c16303825ebeaf1..3c745ec2f6f56b670ec7992e2ec59c76d596ba32 100644 (file)
@@ -114,4 +114,7 @@ import insert, query from require "lapis.db"
                        { "competition_id", types.foreign_key }
                        { "user_id", types.foreign_key }
                }
+
+       [13]: =>
+               add_column "problems", "blacklisted_langs", (types.varchar default: "")
 }
index 45d99c5bded7adc802f7ac2089b73b83fb924540..d76ed695d4714846f29962397cb001119772b5e0 100644 (file)
@@ -13,25 +13,31 @@ class AdminProblemEdit extends html.Widget
                                        input type: 'hidden', name: 'csrf_token', value: @csrf_token
                                        input type: 'hidden', name: 'problem_id', value: @problem.id
 
-                                       label for: 'name', 'Problem name'
-                                       input type: 'text', name: 'name', placeholder: 'Problem name', value: @problem.name, ""
-
-                                       div class: 'split-3', ->
+                                       div class: 'split-2-1', ->
                                                div class: 'mar-r-12', ->
+                                                       label for: 'name', 'Problem name'
+                                                       input type: 'text', name: 'name', placeholder: 'Problem name', value: @problem.name, ""
+
+                                               div class: 'mar-l-12', ->
                                                        label for: 'name', 'Short name'
                                                        input type: 'text', name: 'short_name', placeholder: 'Short URL name', value: @problem.short_name, ""
 
-                                               div class: 'mar-l-12 mar-r-12', ->
+                                       div class: 'split-3', ->
+                                               div class: 'mar-r-12', ->
                                                        label for: 'name', 'Time limit'
                                                        input type: 'number', value: 500, name: 'time_limit', value: @problem.time_limit, ""
 
-                        div class: 'mar-l-12', ->
+                        div class: 'mar-l-12 mar-r-12', ->
                             label for: 'kind', 'Problem kind'
                             element 'select', name: 'kind', ->
                                 option { value: 'code', selected: @problem.kind == Problems.kinds.code }, 'Programming'
                                 option { value: 'golf', selected: @problem.kind == Problems.kinds.golf }, 'Code Golf'
                                 option { value: 'word', selected: @problem.kind == Problems.kinds.word }, 'Word'
 
+                                               div class: 'mar-l-12', ->
+                                                       label for: 'blacklisted_langs', 'Language blacklist (comma separated)'
+                                                       input type: 'text', name: 'blacklisted_langs', value: @problem.blacklisted_langs, ""
+
                                        div class: 'header-line', -> div 'Problem description'
                                        pre { style: 'height: 32rem;', id: 'code-editor', 'data-lang': 'markdown' }, @problem.description
 
index 6f9a9a4b5531b47b0e3b75b2026aa27a8a78b26f..c7d79d5284d417b45493045afda2a36826b7938d 100644 (file)
@@ -25,6 +25,10 @@ class ProblemsView extends html.Widget
                                 div "Problem kind:"
                                 kind = Problems.kinds\to_name @problem.kind
                                 div "#{kind}"
+                                                       unless @problem.blacklisted_langs == ""
+                                                               div class: 'split-lr pad-12', ->
+                                                                       div "Language blacklist:"
+                                                                       div "#{@problem.blacklisted_langs}"
 
                                                div style: 'font-size: 1.3rem;', class: 'header-line', -> text "Stats for #{@problem.name}"
 
index c94e9fc5ee4e27622ee642d3f17785950ba6f31f..b5844fb5ba3b28b44a1c2ff63e2f8c12194d5dbd 100644 (file)
@@ -1,4 +1,5 @@
 html = require 'lapis.html'
+require 'utils.string'
 
 class ProblemSubmit extends html.Widget
     content: =>
@@ -14,12 +15,18 @@ class ProblemSubmit extends html.Widget
                     div class: 'split-lr', ->
                         div class: 'mar-l-12', ->
                             span -> text "Language: "
+
+                                                       blacklisted = string.split @problem.blacklisted_langs, ','
                             element 'select', id: 'language', ->
-                                option value: 'c', -> text 'C'
-                                option value: 'cpp', -> text 'C++'
-                                option value: 'py', -> text 'Python 3'
-                                option value: 'lua', -> text 'Lua'
+                                                               unless table.contains blacklisted, 'c'
+                                                                       option value: 'c', -> text 'C'
+                                                               unless table.contains blacklisted, 'cpp'
+                                                                       option value: 'cpp', -> text 'C++'
+                                                               unless table.contains blacklisted, 'py'
+                                                                       option value: 'py', -> text 'Python 3'
+                                                               unless table.contains blacklisted, 'lua'
+                                                                       option value: 'lua', -> text 'Lua'
                         div class: 'button-list', ->
                             button id: 'submit-btn', -> text "Submit"
 
-                    pre { style: 'height: 40rem', id: 'code-editor', 'data-lang': 'c_cpp' }, ""
\ No newline at end of file
+                    pre { style: 'height: 40rem', id: 'code-editor', 'data-lang': 'c_cpp' }, ""
index 137165afe329b47a45fa699eeb37b44d7b7522e8..0c14d8d321ac9d0fa99ba059b9b8ebf1c904ba23 100644 (file)
--- a/docs/todo
+++ b/docs/todo
@@ -1,8 +1,7 @@
 [X] Highlight logged in user on leaderboard
-[ ] Competition users table for enrolled users
-[ ] Competition settings table
-       * Active languages
-       * Points per problem type
+[X] Competition users table for enrolled users
+[X] Problem language blacklist
+[ ] Leaderboard timer and just better looking
 [ ] Word problems
        * Use test case 1 for answer
        * input doesn't matter