domain_create

This commit is contained in:
masnn committed 2020-06-04 23:14:59 +08:00
1 parent faec4744d7
commit 63d55cedf4
7 files changed
+91 -13

No files matched your search

+25 -1
View File
@@ -1,8 +1,31 @@
const user = require('../model/user');
const domain = require('../model/domain');
const system = require('../model/system');
const { Route, Handler } = require('../service/server');
const { PERM_MANAGE } = require('../permission');
const { RoleAlreadyExistError, ValidationError } = require('../error');
const { RoleAlreadyExistError, ValidationError, PermissionError } = require('../error');
class DomainCreateHandler extends Handler {
async prepare() {
if (this.user.priv !== 1) {
if (!await system.get('user.create_domain')) throw new PermissionError('domain_create');
}
}
async get() {
const path = [
['Hydro', '/'],
['domain_create', null],
];
this.response.body = { path };
this.response.template = 'domain_create.html';
}
async post({ id, name }) {
await domain.add(id, this.user._id, name);
this.response.body = { domainId: id };
}
}
class ManageHandler extends Handler {
async prepare({ domainId }) {
@@ -135,6 +158,7 @@ class DomainRoleHandler extends ManageHandler {
}
async function apply() {
Route('/domain/create', DomainCreateHandler);
Route('/domain/dashboard', DomainDashboardHandler);
Route('/domain/edit', DomainEditHandler);
Route('/domain/user', DomainUserHandler);
+11 -3
View File
@@ -2,9 +2,16 @@ const permission = require('../permission');
global.Hydro.ui.nav = [];
const Item = (path, name, prefix, perm) => {
const trueChecker = () => true;
const Item = (path, name, prefix, perm, checker) => {
if (perm && checker) {
checker = ((_chk) => (handler) => _chk(handler) && handler.user.hasPerm(perm))(checker);
} else if (perm) {
checker = (handler) => handler.user.hasPerm(perm);
} else checker = trueChecker;
global.Hydro.ui.nav.push({
path, name, prefix, perm,
path, name, prefix, checker,
});
};
@@ -14,6 +21,7 @@ Item('/t', 'training_main', 'training', permission.PERM_VIEW_TRAINING);
Item('/homework', 'homework_main', 'homework', permission.PERM_VIEW_HOMEWORK);
Item('/discuss', 'discussion_main', 'discussion', permission.PERM_VIEW_DISCUSSION);
Item('/c', 'contest_main', 'contest', permission.PERM_VIEW_CONTEST);
Item('/domain', 'domain_dashboard', 'domain', permission.PERM_MANAGE);
Item('/domain/dashboard', 'domain_dashboard', 'domain', permission.PERM_MANAGE);
Item('/manage/dashboard', 'manage_dashboard', 'manage', null, (handler) => handler.user.priv === 1);
global.Hydro.lib.nav = module.exports = Item;
+4 -2
View File
@@ -15,9 +15,11 @@ const coll = db.collection('domain');
* @param {string} domainId
* @param {number} owner
*/
function add(domainId, owner) {
function add(domainId, owner, name) {
const tasks = [
coll.insertOne({ _id: domainId, owner, bulletin: '' }),
coll.insertOne({
_id: domainId, owner, name, bulletin: '',
}),
];
for (const id in builtin.BUILTIN_ROLES) {
tasks.push(
+1
View File
@@ -45,6 +45,7 @@ for (const setting in SETTINGS) SETTINGS_BY_KEY[setting.key] = setting;
const SYSTEM_SETTINGS = [
Setting('setting_basic', 'user.register', null, false, 'checkbox', 'Allow register'),
Setting('setting_basic', 'user.create_domain', null, true, 'checkbox', 'Allow domain creation'),
Setting('setting_smtp', 'smtp.user', null, null, 'text', 'SMTP Username'),
Setting('setting_smtp', 'smtp.pass', null, null, 'password', 'SMTP Password'),
Setting('setting_smtp', 'smtp.host', null, null, 'text', 'SMTP Server Host'),
+47
View File
@@ -0,0 +1,47 @@
{# No Compression #}
{% extends "layout/basic.html" %}
{% block content %}
<div class="row">
<div class="medium-9 columns">
<div class="section">
<div class="section__header">
<h1 class="section__title" id="create" data-heading>{{ _('Create Domain') }}</h1>
</div>
<div class="section__body">
<blockquote class="note typo">
<p>{{ _('A domain ID cannot be changed after creation. It is supposed to be:') }}</p>
<ul>
<li>{{ _('Unique') }}</li>
<li>{{ _('At least 4 characters') }}</li>
<li>{{ _('Not wrapped with space') }}</li>
<li>{{ _('Not started with a number') }}</li>
<li>{{ _('Only A-Z, a-z, 0-9 and _ are accepted') }}</li>
</ul>
</blockquote>
<form method="post">
{{ form.form_text({
label:'ID',
name:'id',
autofocus:true,
required:true
}) }}
{{ form.form_text({
label:'Name',
name:'name',
required:true
}) }}
<div class="row"><div class="columns">
<input type="hidden" name="csrfToken" value="{{ handler.csrfToken }}">
<button type="submit" class="rounded primary button">
{{ _('Create') }}
</button>
<button type="button" class="rounded button" onclick="window.history.go(-1)">
{{ _('Cancel') }}
</button>
</div></div>
</form>
</div>
</div>
</div>
</div>
{% endblock %}
+2 -2
View File
@@ -11,8 +11,8 @@
</span>
</h1>
<div class="footer__category__expander"><ul class="footer__category__list">
<li class="footer__category__item"><a href="/r">{{ _('Judging Queue') }}</a></li>
<li class="footer__category__item"><a href="#">{{ _('Service Status') }}</a></li>
<li class="footer__category__item"><a href="/record">{{ _('Judging Queue') }}</a></li>
<li class="footer__category__item"><a href="/status">{{ _('Service Status') }}</a></li>
</ul></div>
</div>
<div class="medium-3 large-2 columns footer__category expandable">
+1 -5
View File
@@ -11,11 +11,7 @@
<ol class="nav__list nav__list--main clearfix">
<li class="nav__list-item"><a href="/" class="nav__logo">&nbsp;</a></li>
{% for item in Context.nav %}
{% if item.perm %}
{% if handler.hasPerm(item.perm) %}
{{ nav_item(item.path, item.name, item.prefix) }}
{% endif %}
{% else %}
{% if item.checker(handler) %}
{{ nav_item(item.path, item.name, item.prefix) }}
{% endif %}
{% endfor %}