This commit is contained in:
Tilman Kamp 2019-01-09 14:49:44 +01:00
Родитель c231b0002c
Коммит fac748a9c9
7 изменённых файлов: 59 добавлений и 53 удалений

Просмотреть файл

@ -6,6 +6,23 @@ var Group = sequelize.define('group', {
title: { type: Sequelize.STRING, allowNull: true }
})
Group.prototype.getGroupDir = () => '/data/groups/' + this.groupname
const groupPrefix = '/data/groups/'
Group.afterCreate(async group => {
let groupDir = groupPrefix + group.id
if (!(await fs.pathExists(groupDir))) {
await fs.mkdirp(groupDir)
}
})
Group.afterDestroy(async group => {
let groupDir = groupPrefix + group.id
if (await fs.pathExists(groupDir)) {
await fs.remove(groupDir)
}
})
Group.getGroupDir = (groupId) => groupPrefix + groupId
Group.prototype.getGroupDir = () => Group.getGroupDir(this.id)
module.exports = Group

Просмотреть файл

@ -39,4 +39,6 @@ User.prototype.canAccessJob = async (resource) => {
return true
}
Job.prototype.getJobDir = () => Pit.getPitDir(this.id)
module.exports = Job

Просмотреть файл

@ -3,12 +3,12 @@ const sequelize = require('./db.js')
const fs = require('fs-extra')
const pitPrefix = '/data/pits/'
var Pit = sequelize.define('pit', {
id: { type: Sequelize.INTEGER, autoIncrement: true, primaryKey: true }
})
const pitPrefix = '/data/pits/'
Pit.afterCreate(async pit => {
let pitDir = pitPrefix + pit.id
if (!(await fs.pathExists(pitDir))) {
@ -23,4 +23,7 @@ Pit.afterDestroy(async pit => {
}
})
Pit.getPitDir = (pitId) => pitPrefix + pitId
Pit.prototype.getPitDir = () => Pit.getPitDir(this.id)
module.exports = Pit

Просмотреть файл

@ -4,8 +4,6 @@ const Group = require('./Group-model.js')
const fs = require('fs-extra')
const homePrefix = '/data/home/'
var User = sequelize.define('user', {
id: { type: Sequelize.STRING, primaryKey: true },
password: { type: Sequelize.STRING, allowNull: false },
@ -17,25 +15,28 @@ var User = sequelize.define('user', {
User.belongsToMany(Group, { through: 'UserGroup' })
Group.belongsToMany(User, { through: 'UserGroup' })
User.beforeCreate(async user => {
let homeDir = homePrefix + user.id
if (!(await fs.pathExists(homeDir))) {
await fs.mkdirp(homeDir)
}
})
User.afterDestroy(async user => {
let homeDir = homePrefix + user.id
if (await fs.pathExists(homeDir)) {
await fs.remove(homeDir)
}
})
const userPrefix = '/data/home/'
User.prototype.isMemberOf = async group => {
group = Group.findById(group)
return group && this.hasGroup(group)
}
User.prototype.getHomeDir = () => homePrefix + this.id
User.afterCreate(async user => {
let userDir = userPrefix + user.id
if (!(await fs.pathExists(userDir))) {
await fs.mkdirp(userDir)
}
})
User.afterDestroy(async user => {
let userDir = userPrefix + user.id
if (await fs.pathExists(userDir)) {
await fs.remove(userDir)
}
})
User.getUserDir = (userId) => userPrefix + userId
User.prototype.getUserDir = () => User.getUserDir(this.id)
module.exports = User

Просмотреть файл

@ -37,19 +37,4 @@ exports.initApp = function(app) {
res.status(403).send()
}
})
app.put('/nodes/:node/resources/:resource/groups/:group', function(req, res) {
_addGroup(_getResource(req), req, res, entity => {
_emitEntityChange('resource', entity)
})
})
app.delete('/nodes/:node/resources/:resource/groups/:group', function(req, res) {
_removeGroup(_getResource(req), req, res, entity => {
_emitEntityChange('resource', entity)
_emitRestricted()
})
})
}

Просмотреть файл

@ -95,7 +95,7 @@ router.put('/:id/groups/:group', (req, res) => {
}
})
router.delete('/:node/groups/:group', (req, res) => {
router.delete('/:id/groups/:group', (req, res) => {
if (req.user.admin) {
let node = db.nodes[req.params.node]
if (node) {
@ -116,3 +116,16 @@ router.delete('/:node/groups/:group', (req, res) => {
}
_emitRestricted()
})
router.put('/:id/resources/:resource/groups/:group', async (req, res) => {
_addGroup(_getResource(req), req, res, entity => {
_emitEntityChange('resource', entity)
})
})
router.delete('/:id/resources/:resource/groups/:group', async (req, res) => {
_removeGroup(_getResource(req), req, res, entity => {
_emitEntityChange('resource', entity)
_emitRestricted()
})
})

Просмотреть файл

@ -70,14 +70,14 @@ function getBasicEnv(job) {
return {
JOB_NUMBER: job.id,
DATA_ROOT: '/data',
JOB_DIR: nodesModule.getPitDir(job.id)
JOB_DIR: job.getJobDir()
}
}
function getPreparationEnv(job) {
let env = getBasicEnv(job)
if (job.continueJob) {
env.CONTINUE_JOB_NUMBER = job.continueJob
if (job.continues) {
env.CONTINUE_JOB_NUMBER = job.continues
}
return env
}
@ -89,21 +89,6 @@ function setJobState(job, state) {
saveJob(job)
}
function loadJob (jobId) {
let job = db.jobs[jobId]
if (job) {
return job
}
let jobPath = path.join(nodesModule.getPitDir(jobId), 'meta.json')
if (fs.existsSync(jobPath)) {
return JSON.parse(fs.readFileSync(jobPath, 'utf8'))
}
}
function saveJob (job) {
fs.writeFileSync(path.join(nodesModule.getPitDir(job.id), 'meta.json'), JSON.stringify(job))
}
function prepareJob(job) {
let env = getPreparationEnv(job)
if (job.origin) {