From 0e324a3cce05664d67cd0aee49d8a271be03dac9 Mon Sep 17 00:00:00 2001 From: cuom1999 Date: Sun, 26 Jun 2022 12:07:34 +0700 Subject: [PATCH] Only allow open org to show members --- judge/admin/problem.py | 2 +- judge/migrations/0128_auto_20220620_2210.py | 15 ++++-- judge/migrations/0129_auto_20220622_1424.py | 50 ++++++++++++++++--- judge/utils/problem_data.py | 4 +- judge/views/organization.py | 11 ++++ templates/organization/org-left-sidebar.html | 4 +- templates/organization/org-right-sidebar.html | 4 +- 7 files changed, 75 insertions(+), 15 deletions(-) diff --git a/judge/admin/problem.py b/judge/admin/problem.py index b52c63a..0cab70a 100644 --- a/judge/admin/problem.py +++ b/judge/admin/problem.py @@ -70,7 +70,7 @@ class ProblemForm(ModelForm): ), "types": AdminSelect2MultipleWidget, "group": AdminSelect2Widget, - "memory_limit": TextInput(attrs={'size':'20'}), + "memory_limit": TextInput(attrs={"size": "20"}), } if HeavyPreviewAdminPageDownWidget is not None: widgets["description"] = HeavyPreviewAdminPageDownWidget( diff --git a/judge/migrations/0128_auto_20220620_2210.py b/judge/migrations/0128_auto_20220620_2210.py index ef74ad5..27fed32 100644 --- a/judge/migrations/0128_auto_20220620_2210.py +++ b/judge/migrations/0128_auto_20220620_2210.py @@ -7,13 +7,20 @@ from django.db import migrations, models class Migration(migrations.Migration): dependencies = [ - ('judge', '0127_auto_20220616_1442'), + ("judge", "0127_auto_20220616_1442"), ] operations = [ migrations.AlterField( - model_name='problem', - name='memory_limit', - field=models.PositiveIntegerField(help_text='The memory limit for this problem, in kilobytes (e.g. 256mb = 262144 kilobytes).', validators=[django.core.validators.MinValueValidator(0), django.core.validators.MaxValueValidator(1048576)], verbose_name='memory limit'), + model_name="problem", + name="memory_limit", + field=models.PositiveIntegerField( + help_text="The memory limit for this problem, in kilobytes (e.g. 256mb = 262144 kilobytes).", + validators=[ + django.core.validators.MinValueValidator(0), + django.core.validators.MaxValueValidator(1048576), + ], + verbose_name="memory limit", + ), ), ] diff --git a/judge/migrations/0129_auto_20220622_1424.py b/judge/migrations/0129_auto_20220622_1424.py index 601bb85..ab1356a 100644 --- a/judge/migrations/0129_auto_20220622_1424.py +++ b/judge/migrations/0129_auto_20220622_1424.py @@ -6,18 +6,54 @@ from django.db import migrations, models class Migration(migrations.Migration): dependencies = [ - ('judge', '0128_auto_20220620_2210'), + ("judge", "0128_auto_20220620_2210"), ] operations = [ migrations.AlterField( - model_name='problemdata', - name='checker', - field=models.CharField(blank=True, choices=[('standard', 'Standard'), ('floats', 'Floats'), ('floatsabs', 'Floats (absolute)'), ('floatsrel', 'Floats (relative)'), ('rstripped', 'Non-trailing spaces'), ('sorted', 'Unordered'), ('identical', 'Byte identical'), ('linecount', 'Line-by-line'), ('custom', 'Custom checker (PY)'), ('customval', 'Custom validator (CPP)'), ('interact', 'Interactive'), ('testlib', 'Testlib')], max_length=10, verbose_name='checker'), + model_name="problemdata", + name="checker", + field=models.CharField( + blank=True, + choices=[ + ("standard", "Standard"), + ("floats", "Floats"), + ("floatsabs", "Floats (absolute)"), + ("floatsrel", "Floats (relative)"), + ("rstripped", "Non-trailing spaces"), + ("sorted", "Unordered"), + ("identical", "Byte identical"), + ("linecount", "Line-by-line"), + ("custom", "Custom checker (PY)"), + ("customval", "Custom validator (CPP)"), + ("interact", "Interactive"), + ("testlib", "Testlib"), + ], + max_length=10, + verbose_name="checker", + ), ), migrations.AlterField( - model_name='problemtestcase', - name='checker', - field=models.CharField(blank=True, choices=[('standard', 'Standard'), ('floats', 'Floats'), ('floatsabs', 'Floats (absolute)'), ('floatsrel', 'Floats (relative)'), ('rstripped', 'Non-trailing spaces'), ('sorted', 'Unordered'), ('identical', 'Byte identical'), ('linecount', 'Line-by-line'), ('custom', 'Custom checker (PY)'), ('customval', 'Custom validator (CPP)'), ('interact', 'Interactive'), ('testlib', 'Testlib')], max_length=10, verbose_name='checker'), + model_name="problemtestcase", + name="checker", + field=models.CharField( + blank=True, + choices=[ + ("standard", "Standard"), + ("floats", "Floats"), + ("floatsabs", "Floats (absolute)"), + ("floatsrel", "Floats (relative)"), + ("rstripped", "Non-trailing spaces"), + ("sorted", "Unordered"), + ("identical", "Byte identical"), + ("linecount", "Line-by-line"), + ("custom", "Custom checker (PY)"), + ("customval", "Custom validator (CPP)"), + ("interact", "Interactive"), + ("testlib", "Testlib"), + ], + max_length=10, + verbose_name="checker", + ), ), ] diff --git a/judge/utils/problem_data.py b/judge/utils/problem_data.py index 95b5a12..6ace1bc 100644 --- a/judge/utils/problem_data.py +++ b/judge/utils/problem_data.py @@ -232,7 +232,9 @@ class ProblemDataCompiler(object): if self.data.checker == "interact": interactor_path = split_path_first(self.data.interactive_judge.name) if len(interactor_path) != 2: - raise ProblemDataError(_("How did you corrupt the interactor path?")) + raise ProblemDataError( + _("How did you corrupt the interactor path?") + ) init["interactive"] = { "files": interactor_path[1], "feedback": True, diff --git a/judge/views/organization.py b/judge/views/organization.py index 1afd2e0..8154eb9 100644 --- a/judge/views/organization.py +++ b/judge/views/organization.py @@ -306,6 +306,17 @@ class OrganizationUsers(QueryStringSortMixin, OrganizationDetailView): default_desc = all_sorts default_sort = "-performance_points" + def dispatch(self, request, *args, **kwargs): + res = super(OrganizationUsers, self).dispatch(request, *args, **kwargs) + if self.can_access(self.organization) or self.organization.is_open: + return res + return generic_message( + request, + _("Can't access organization"), + _("You are not allowed to access this organization."), + status=403, + ) + def get_context_data(self, **kwargs): context = super(OrganizationUsers, self).get_context_data(**kwargs) context["title"] = _("%s Members") % self.object.name diff --git a/templates/organization/org-left-sidebar.html b/templates/organization/org-left-sidebar.html index 8f2c442..9e7ab6d 100644 --- a/templates/organization/org-left-sidebar.html +++ b/templates/organization/org-left-sidebar.html @@ -5,7 +5,9 @@ {{ make_tab_item('contests', 'fa fa-trophy', organization.get_contests_url(), _('Contests')) }} {{ make_tab_item('submissions', 'fa fa-book', organization.get_submissions_url(), _('Submissions')) }} {% endif %} - {{ make_tab_item('users', 'fa fa-user', organization.get_users_url(), _('Members')) }} + {% if is_member or can_edit or organization.is_open %} + {{ make_tab_item('users', 'fa fa-user', organization.get_users_url(), _('Members')) }} + {% endif %} {% if perms.judge.change_organization %} {{ make_tab_item('admin', 'fa fa-edit', url('admin:judge_organization_change', organization.id), _('Admin')) }} {% endif %} diff --git a/templates/organization/org-right-sidebar.html b/templates/organization/org-right-sidebar.html index 496115b..22db950 100644 --- a/templates/organization/org-right-sidebar.html +++ b/templates/organization/org-right-sidebar.html @@ -70,5 +70,7 @@ {% endif %} - {% include 'top-users.html' %} + {% if is_member or can_edit or organization.is_open %} + {% include 'top-users.html' %} + {% endif %} \ No newline at end of file