Skip to content

Commit

Permalink
Adjust suspicious attribute to suspicious group (#200)
Browse files Browse the repository at this point in the history
* Adjust suspicious attribute to suspicious group

* Frontend for suspicious

- Don't show score & rank for suspicious
- Handle cases when suspicious_words is empty

* Update suspicious wording
  • Loading branch information
taoky authored Oct 31, 2024
1 parent 82a001a commit 69d6ae5
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 75 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,9 @@ Reverse for 'socialaccount_signup' not found. 'socialaccount_signup' is not a va

答:相应用户需要被勾选“工作人员状态”,这个选项和权限无关,仅影响界面显示。

问:“不计分”和“已封禁”两个组别有什么区别
问:“不计分”、“待审核”和“已封禁”这三个组别有什么区别

答:后者不能看到题目,不能做题,不能打开首页。
答:不计分组的分数不计入排行榜;待审核组可以正常参赛,但分数暂时不计入排行榜,在比赛期间及比赛结束后 24 小时内提交审核材料并通过后,分数会重新计入排行榜;已封禁组被禁止参赛,即不能看到题目,不能做题,不能打开首页。

问:加群验证码是什么?

Expand Down
2 changes: 1 addition & 1 deletion frontend/management/commands/fake_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def a():
can_update_profile=True,
)

groups = list(set(User.groups.keys()) - {'noscore', 'banned'})
groups = list(set(User.groups.keys()) - {'noscore', 'banned', 'suspicious'})
for i in range(fake_users):
print('user', i, end='\r')
u = User.create(
Expand Down
29 changes: 1 addition & 28 deletions frontend/templates/admin_user.html
Original file line number Diff line number Diff line change
Expand Up @@ -87,21 +87,9 @@ <h2 v-else>正在创建</h2>
<input class="vTextField" type="text" id="form-aff" name="aff" v-model="opened.aff">
</div>
<div class="form-row">
<label for="form-suspicious">是否标记为第一阶段封禁:</label>
<input class="vCheckboxField" type="checkbox" id="form-suspicious" name="suspicious" v-model="opened.suspicious">
</div>
<div class="form-row">
<label for="form-suspicious-reason">第一阶段封禁原因:</label>
<label for="form-suspicious-reason">待审核原因(仅在用户在待审核组时显示):</label>
<input class="vTextField" type="text" id="form-suspicious-reason" name="suspicious-reason" v-model="opened.suspicious_reason">
</div>
<div class="form-row">
<label for="form-suspicious-ddl">显示的第一阶段封禁联系截止时间:</label>
<input class="vTextField" type="text" id="form-suspicious-ddl" name="suspicious-ddl" v-model="suspicious_ddl_input">
<template v-if="suspicious_ddl_input">
<div class="help" v-if="isNaN(new Date(suspicious_ddl_input).valueOf())"><strong>格式错误!</strong></div>
<div class="help" v-else>本地时间: {{ new Date(suspicious_ddl_input).toLocaleString() }}<br>UTC 时间: {{ new Date(suspicious_ddl_input).toJSON() }}</div>
</template>
</div>
</fieldset>
<div class="submit-row" v-show="!opened_disabled">
<input type="submit" class="default" value="保存">
Expand Down Expand Up @@ -155,9 +143,7 @@ <h2 v-else>正在创建</h2>
<td>{{ obj.major }}</td>
<td>{{ obj.campus }}</td>
<td>{{ obj.aff }}</td>
<td><img v-if="obj.suspicious" src="/static/admin/img/icon-yes.svg" alt="True"><img v-else src="/static/admin/img/icon-no.svg" alt="False"></td>
<td>{{ obj.suspicious_reason }}</td>
<td>{{ obj.suspicious_ddl }}</td>
</tr>
</tbody>
</table>
Expand All @@ -180,7 +166,6 @@ <h2 v-else>正在创建</h2>
},
account_pks: {},
accountlog: {},
suspicious_ddl_input: '',
},
created() {
this.refresh();
Expand All @@ -207,7 +192,6 @@ <h2 v-else>正在创建</h2>
},
open(obj) {
this.opened = {...obj};
this.suspicious_ddl_input = obj.suspicious_ddl || '';
axios.post('/account/', {method: 'account_pk', user: obj.pk})
.then(({data: {value}}) => {
this.$set(this.account_pks, obj.pk, value)
Expand All @@ -219,17 +203,6 @@ <h2 v-else>正在创建</h2>
},
opened_save() {
this.opened_disabled = true;
if (this.suspicious_ddl_input) {
let suspicious_ddl = new Date(this.suspicious_ddl_input);
if (isNaN(suspicious_ddl.valueOf())) {
alert('时间格式错误');
this.opened_disabled = false;
return;
}
this.opened.suspicious_ddl = suspicious_ddl.toJSON();
} else {
this.opened.suspicious_ddl = null;
}
axios.post('.', {method: 'save', args: this.opened})
.then(({data: {value}}) => {
this.opened = undefined;
Expand Down
19 changes: 13 additions & 6 deletions frontend/templates/hub.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,19 @@
<small>{{ new Date(announcement.time).toLocaleString() }}</small>
<a href="/announcements/">查看所有公告</a>
</div>
<div v-if="user.suspicious" class="msg-error">
经裁判组检查,你的账号有以下疑似违规行为:{{ user.suspicious_reason }}。
你的账号将会在 {{ new Date(user.suspicious_ddl).toLocaleString() }} 之后被封禁
如果你有异议,请尽快联系 <a href="mailto:[email protected]">[email protected]</a>
提供你的 Token 以及申诉理由。在封禁之前,你仍可正常参加比赛
<div v-if="user.group==='suspicious'" class="msg-error">
经裁判组检查,你的账号{{ suspicious_words }}。
你的分数暂时不计入排行榜,你仍可继续完成题目
你可以在比赛期间及比赛结束后 24 小时内联系组委会配合审核,审核通过后你的分数会重新计入排行榜。
请发邮件至 <a href="mailto:[email protected]">[email protected]</a>,邮件中包含你的 Token
</div>
<div v-if="user" class="msg-info">
<label for="token">Token:</label>
<button @click="token_show=!token_show">{{ token_show?'隐藏':'显示' }}</button>
<input v-show="token_show" type="text" id="token" :value="user.token" readonly>
<button onclick="token_copy()">{{ token_copy_text }}</button>
Token 是一些题目的登录凭证,禁止分享,否则视为作弊
<template v-if="progress.scores.find(i=>i.category===null)">
<template v-if="progress.scores.find(i=>i.category===null) && user.group!=='suspicious'">
<a href="/board/">
<br>
当前分数:{{ (progress.scores.find(i=>i.category===null)||{score:0}).score }},
Expand Down Expand Up @@ -218,6 +218,13 @@ <h1>{{ opened.name }}</h1>
categories() {
return [...new Set(this.challenges.map(i => i.category))].sort();
},
suspicious_words() {
if (this.user && this.user.suspicious_reason) {
return "有以下疑似违规行为:" + this.user.suspicious_reason;
} else {
return "有疑似违规行为";
}
}
},
methods: {
open(challenge) {
Expand Down
2 changes: 1 addition & 1 deletion frontend/templates/score.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ <h1>分数查询</h1>
</select>
<select v-model="group">
<option value="">总排名</option>
<option v-for="i in coreData.groups" v-if="!['noscore', 'other', 'banned'].includes(i.id)" :value="i.id">{{ i.name }}</option>
<option v-for="i in coreData.groups" v-if="!['noscore', 'other', 'banned', 'suspicious'].includes(i.id)" :value="i.id">{{ i.name }}</option>
</select>
<button type="submit" class="pure-button pure-button-primary">加载</button>
</form>
Expand Down
43 changes: 10 additions & 33 deletions server/user/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ class User:
'display_name', 'nickname', 'name', 'sno', 'tel',
'email', 'gender', 'qq', 'website', 'school',
'grade', 'major', 'campus', 'aff', 'token', 'token_short', 'code',
'suspicious', 'suspicious_reason', 'suspicious_ddl')
'suspicious_reason')
update_fields = ('group', 'nickname', 'name', 'sno', 'tel', 'email',
'gender', 'qq', 'website', 'school', 'grade', 'major', 'campus',
'aff', 'suspicious', 'suspicious_reason', 'suspicious_ddl')
'aff', 'suspicious_reason')
groups = {
'noscore': '不计分',
'ustc': '中国科学技术大学',
Expand All @@ -61,6 +61,7 @@ class User:
'nyist': '南阳理工学院',
'sjtu': '上海交通大学',
'other': '其他选手',
'suspicious': '待审核',
'banned': '已封禁',
}
# XXX:
Expand Down Expand Up @@ -89,11 +90,12 @@ class User:
'nyist': ['nickname', 'name', 'sno', 'school', 'major', 'qq'],
'sjtu': ['nickname', 'name', 'sno'],
'other': ['nickname'],
'suspicious': ['nickname'],
'banned': ['nickname'],
}
no_board_groups = ['noscore', 'other', 'banned']
no_code_groups = ['noscore', 'other', 'banned']
no_score_groups = ['noscore', 'banned']
no_board_groups = ['noscore', 'other', 'suspicious', 'banned']
no_code_groups = ['noscore', 'other', 'suspicious', 'banned']
no_score_groups = ['noscore', 'suspicious', 'banned']
subscribers = []
_validators = {
'group': group_validator,
Expand All @@ -112,9 +114,7 @@ class User:
'major': RegexValidator(r'^.{1,15}$', '专业格式错误'),
'campus': RegexValidator(r'^.{1,15}$', '校区格式错误'),
'aff': RegexValidator(r'^.{1,100}$', '了解比赛的渠道格式错误'),
'suspicious': lambda x: isinstance(x, bool),
'suspicious_reason': None,
'suspicious_ddl': None,
}
_private_key = OpenSSL.crypto.load_privatekey(
OpenSSL.crypto.FILETYPE_PEM, settings.PRIVATE_KEY)
Expand Down Expand Up @@ -210,9 +210,7 @@ def update(self, **kwargs):
except server.trigger.interface.TriggerIsOff:
User.test_permission(self._context, 'user.full')
if ('group' in kwargs and kwargs['group'] != self.group) or \
('suspicious' in kwargs and kwargs['suspicious'] != self.suspicious) or \
('suspicious_reason' in kwargs and kwargs['suspicious_reason'] != self.suspicious_reason) or \
('suspicious_ddl' in kwargs and kwargs['suspicious_ddl'] != self.suspicious_ddl):
('suspicious_reason' in kwargs and kwargs['suspicious_reason'] != self.suspicious_reason):
User.test_permission(self._context, 'user.full')
if self._context.user.pk != self.pk:
User.test_permission(self._context, 'user.full')
Expand All @@ -226,22 +224,13 @@ def _update(self, **kwargs):
for k, v in kwargs.items():
if k in {'group', 'nickname', 'name', 'sno', 'tel', 'email',
'gender', 'qq', 'website', 'school', 'grade', 'major', 'campus',
'aff', 'suspicious_reason', 'suspicious_ddl'}:
'aff', 'suspicious_reason'}:
v = v or None
try:
v is None or (self._validators[k] and self._validators[k](v))
except ValidationError as e:
raise WrongFormat(e.message)
setattr(self._obj, k, v)
elif k in {'suspicious'}:
# non-nullable values should not be set to None like above
if v is None:
raise WrongFormat()
try:
self._validators[k] and self._validators[k](v)
except ValidationError as e:
raise WrongFormat(e.message)
setattr(self._obj, k, v)
else:
raise WrongArguments()
self._obj.save()
Expand All @@ -253,7 +242,7 @@ def _update(self, **kwargs):
**{k: getattr(self._obj, k) for k in {
'user', 'group', 'nickname', 'name', 'sno', 'tel',
'email', 'gender', 'qq', 'website', 'school', 'grade', 'major', 'campus',
'aff', 'token', 'suspicious', 'suspicious_reason', 'suspicious_ddl'
'aff', 'token', 'suspicious_reason'
}},
)

Expand Down Expand Up @@ -448,20 +437,8 @@ def code(self):
token = self._obj.token
return f'{self.pk}-{int(sha256(token.encode()).hexdigest(), 16)%10000:04}'

@property
def suspicious(self):
if self._context.user.pk != self.pk:
User.test_permission(self._context, 'user.full', 'user.view')
return self._obj.suspicious

@property
def suspicious_reason(self):
if self._context.user.pk != self.pk:
User.test_permission(self._context, 'user.full', 'user.view')
return self._obj.suspicious_reason

@property
def suspicious_ddl(self):
if self._context.user.pk != self.pk:
User.test_permission(self._context, 'user.full', 'user.view')
return self._obj.suspicious_ddl
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Generated by Django 4.2.16 on 2024-10-31 06:05

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
("user", "0017_update_groups_2024"),
]

operations = [
migrations.RemoveField(
model_name="user",
name="suspicious",
),
migrations.RemoveField(
model_name="user",
name="suspicious_ddl",
),
migrations.RemoveField(
model_name="userlog",
name="suspicious",
),
migrations.RemoveField(
model_name="userlog",
name="suspicious_ddl",
),
]
4 changes: 0 additions & 4 deletions server/user/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ class User(models.Model):
campus = models.TextField(null=True)
aff = models.TextField(null=True)
token = models.TextField()
suspicious = models.BooleanField(default=False)
suspicious_reason = models.TextField(null=True)
suspicious_ddl = models.DateTimeField(null=True)

class Meta:
default_permissions = ()
Expand Down Expand Up @@ -66,9 +64,7 @@ class UserLog(models.Model):
campus = models.TextField(null=True)
aff = models.TextField(null=True)
token = models.TextField()
suspicious = models.BooleanField(default=False)
suspicious_reason = models.TextField(null=True)
suspicious_ddl = models.DateTimeField(null=True)

class Meta:
default_permissions = ()

0 comments on commit 69d6ae5

Please sign in to comment.