From 1b7296d71e29b80f3f72fb0d995fc922519c3b79 Mon Sep 17 00:00:00 2001 From: Brendan Hansen Date: Mon, 30 Sep 2019 15:28:23 -0500 Subject: [PATCH] Added blacklisting languages for problems --- codebox/controllers/admin/problem/edit.moon | 2 ++ codebox/controllers/problem/submit.moon | 4 ++++ codebox/migrations.moon | 3 +++ codebox/views/admin/problem/edit.moon | 18 ++++++++++++------ codebox/views/problem/problem.moon | 4 ++++ codebox/views/problem/submit.moon | 17 ++++++++++++----- docs/todo | 7 +++---- 7 files changed, 40 insertions(+), 15 deletions(-) diff --git a/codebox/controllers/admin/problem/edit.moon b/codebox/controllers/admin/problem/edit.moon index 9b66dc9..d3f06bb 100644 --- a/codebox/controllers/admin/problem/edit.moon +++ b/codebox/controllers/admin/problem/edit.moon @@ -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) diff --git a/codebox/controllers/problem/submit.moon b/codebox/controllers/problem/submit.moon index db3dc63..12e76b0 100644 --- a/codebox/controllers/problem/submit.moon +++ b/codebox/controllers/problem/submit.moon @@ -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 diff --git a/codebox/migrations.moon b/codebox/migrations.moon index 5bc34be..3c745ec 100644 --- a/codebox/migrations.moon +++ b/codebox/migrations.moon @@ -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: "") } diff --git a/codebox/views/admin/problem/edit.moon b/codebox/views/admin/problem/edit.moon index 45d99c5..d76ed69 100644 --- a/codebox/views/admin/problem/edit.moon +++ b/codebox/views/admin/problem/edit.moon @@ -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 diff --git a/codebox/views/problem/problem.moon b/codebox/views/problem/problem.moon index 6f9a9a4..c7d79d5 100644 --- a/codebox/views/problem/problem.moon +++ b/codebox/views/problem/problem.moon @@ -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}" diff --git a/codebox/views/problem/submit.moon b/codebox/views/problem/submit.moon index c94e9fc..b5844fb 100644 --- a/codebox/views/problem/submit.moon +++ b/codebox/views/problem/submit.moon @@ -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' }, "" diff --git a/docs/todo b/docs/todo index 137165a..0c14d8d 100644 --- 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 -- 2.25.1