fix memberships, zones
This commit is contained in:
parent
86bd276d21
commit
012a76ee1f
16
models/db.js
16
models/db.js
@ -93,6 +93,8 @@ module.exports = {
|
||||
space_id: Sequelize.STRING,
|
||||
user_id: Sequelize.STRING,
|
||||
role: Sequelize.STRING,
|
||||
code: Sequelize.STRING,
|
||||
state: {type: Sequelize.STRING, defaultValue: "pending"},
|
||||
created_at: {type: Sequelize.DATE, defaultValue: Sequelize.NOW},
|
||||
updated_at: {type: Sequelize.DATE, defaultValue: Sequelize.NOW}
|
||||
}),
|
||||
@ -212,6 +214,20 @@ module.exports = {
|
||||
as: 'creator'
|
||||
});
|
||||
|
||||
Membership.belongsTo(User, {
|
||||
foreignKey: {
|
||||
name: 'user_id'
|
||||
},
|
||||
as: 'user'
|
||||
});
|
||||
|
||||
Membership.belongsTo(Space, {
|
||||
foreignKey: {
|
||||
name: 'space_id'
|
||||
},
|
||||
as: 'space'
|
||||
});
|
||||
|
||||
Artifact.belongsTo(User, {
|
||||
foreignKey: {
|
||||
name: 'user_id'
|
||||
|
@ -1,12 +1,8 @@
|
||||
"use strict";
|
||||
|
||||
var config = require('config');
|
||||
require('../../models/db');
|
||||
|
||||
var fs = require('fs');
|
||||
var _ = require("underscore");
|
||||
var async = require('async');
|
||||
var request = require('request');
|
||||
var url = require("url");
|
||||
var path = require("path");
|
||||
var crypto = require('crypto');
|
||||
@ -15,38 +11,30 @@ var glob = require('glob');
|
||||
var express = require('express');
|
||||
var router = express.Router();
|
||||
|
||||
var userMapping = { '_id': 1, 'nickname': 1, 'email': 1};
|
||||
var spaceMapping = { '_id': 1, name: 1};
|
||||
const db = require('../../models/db');
|
||||
const Sequelize = require('sequelize');
|
||||
const Op = Sequelize.Op;
|
||||
const uuidv4 = require('uuid/v4');
|
||||
|
||||
router.get('/:membership_id/accept', function(req, res, next) {
|
||||
if (req.user) {
|
||||
Membership.findOne({
|
||||
db.Membership.findOne({where:{
|
||||
_id: req.params.membership_id,
|
||||
state: "pending",
|
||||
code: req.query.code,
|
||||
user: { "$exists": false }
|
||||
}).populate('space').exec((err,mem) => {
|
||||
if (err) res.sendStatus(400);
|
||||
else {
|
||||
if (mem) {
|
||||
if(!mem.user) {
|
||||
mem.code = null;
|
||||
mem.state = "active";
|
||||
mem.user = req.user;
|
||||
code: req.query.code
|
||||
}, include: ['space']}).then((mem) => {
|
||||
if (mem) {
|
||||
if (!mem.user) {
|
||||
mem.state = "active";
|
||||
mem.user_id = req.user._id;
|
||||
|
||||
mem.save(function(err){
|
||||
if (err) res.status(400).json(err);
|
||||
else {
|
||||
console.log(mem);
|
||||
res.status(200).json(mem);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
res.status(400).json({"error": "already_used"});
|
||||
}
|
||||
mem.save().then(function() {
|
||||
res.status(200).json(mem);
|
||||
});
|
||||
} else {
|
||||
res.status(404).json({"error": "not found"});
|
||||
res.status(200).json(mem);
|
||||
}
|
||||
} else {
|
||||
res.status(404).json({"error": "not found"});
|
||||
}
|
||||
});
|
||||
} else {
|
||||
|
@ -15,37 +15,16 @@ var request = require('request');
|
||||
var url = require("url");
|
||||
var path = require("path");
|
||||
var glob = require('glob');
|
||||
var crypto = require('crypto');
|
||||
|
||||
var express = require('express');
|
||||
var router = express.Router({mergeParams: true});
|
||||
|
||||
// JSON MAPPINGS
|
||||
var userMapping = {
|
||||
_id: 1,
|
||||
nickname: 1,
|
||||
email: 1,
|
||||
avatar_thumb_uri: 1
|
||||
};
|
||||
|
||||
var spaceMapping = {
|
||||
_id: 1,
|
||||
name: 1,
|
||||
thumbnail_url: 1
|
||||
};
|
||||
|
||||
var roleMapping = {
|
||||
"none": 0,
|
||||
"viewer": 1,
|
||||
"editor": 2,
|
||||
"admin": 3
|
||||
}
|
||||
|
||||
router.get('/', function(req, res, next) {
|
||||
db.Membership
|
||||
.findAll({where: {
|
||||
space_id: req.space._id
|
||||
}})
|
||||
//.populate("user")
|
||||
}, include: ['user']})
|
||||
.then(memberships => {
|
||||
res.status(200).json(memberships);
|
||||
});
|
||||
@ -54,8 +33,8 @@ router.get('/', function(req, res, next) {
|
||||
router.post('/', function(req, res, next) {
|
||||
if (req.spaceRole == "admin") {
|
||||
var attrs = req.body;
|
||||
attrs['space'] = req.space._id;
|
||||
attrs['state'] = "pending";
|
||||
attrs.space_id = req.space._id;
|
||||
attrs.state = "pending";
|
||||
attrs._id = uuidv4();
|
||||
var membership = attrs;
|
||||
|
||||
@ -64,10 +43,10 @@ router.post('/', function(req, res, next) {
|
||||
if (membership.email_invited != req.user.email) {
|
||||
db.User.findOne({where:{
|
||||
"email": membership.email_invited
|
||||
}}, function(user) {
|
||||
}}).then(function(user) {
|
||||
|
||||
if (user) {
|
||||
membership.user = user;
|
||||
membership.user_id = user._id;
|
||||
membership.state = "active";
|
||||
} else {
|
||||
membership.code = crypto.randomBytes(64).toString('hex').substring(0, 12);
|
||||
@ -119,21 +98,15 @@ router.post('/', function(req, res, next) {
|
||||
router.put('/:membership_id', function(req, res, next) {
|
||||
if (req.user) {
|
||||
if (req.spaceRole == "admin") {
|
||||
Membership.findOne({
|
||||
db.Membership.findOne({ where: {
|
||||
_id: req.params.membership_id
|
||||
}, function(err, mem) {
|
||||
if (err) res.sendStatus(400);
|
||||
else {
|
||||
if (mem) {
|
||||
var attrs = req.body;
|
||||
mem.role = attrs.role;
|
||||
mem.save(function(err) {
|
||||
if (err) res.sendStatus(400);
|
||||
else {
|
||||
res.status(201).json(mem);
|
||||
}
|
||||
});
|
||||
}
|
||||
}}).then(function(mem) {
|
||||
if (mem) {
|
||||
var attrs = req.body;
|
||||
mem.role = attrs.role;
|
||||
mem.save(function() {
|
||||
res.status(201).json(mem);
|
||||
});
|
||||
}
|
||||
});
|
||||
} else {
|
||||
@ -146,20 +119,12 @@ router.put('/:membership_id', function(req, res, next) {
|
||||
|
||||
router.delete('/:membership_id', function(req, res, next) {
|
||||
if (req.user) {
|
||||
Membership.findOne({
|
||||
db.Membership.findOne({ where: {
|
||||
_id: req.params.membership_id
|
||||
}, function(err, mem) {
|
||||
if (err) res.sendStatus(400);
|
||||
else {
|
||||
mem.remove(function(err) {
|
||||
if (err) {
|
||||
res.status(400).json(err);
|
||||
} else {
|
||||
// FIXME might need to delete the user?
|
||||
res.sendStatus(204);
|
||||
}
|
||||
});
|
||||
}
|
||||
}}).then(function(mem) {
|
||||
mem.destroy().then(function() {
|
||||
res.sendStatus(204);
|
||||
});
|
||||
});
|
||||
} else {
|
||||
res.sendStatus(403);
|
||||
|
@ -9,7 +9,7 @@
|
||||
<button v-on:click="add_zone()" class="btn btn-sm btn-primary">[[__("add_zone")]]</button>
|
||||
</div>
|
||||
|
||||
<div class="dialog-section no-p" v-for="z in zones | orderBy 'style.order'" style="white-space: nowrap;text-align:left;cursor:pointer" v-on:click="zoom_to_zone(z)">
|
||||
<div class="dialog-section no-p" v-for="z in zones | orderBy 'order'" style="white-space: nowrap;text-align:left;cursor:pointer" v-on:click="zoom_to_zone(z)">
|
||||
<button class="btn btn-sm btn-transparent">{{{z.description}}}</button>
|
||||
<button v-if="$index==current_zone_idx" v-on:click="sort_zone_up(z)" class="btn btn-sm btn-round btn-transparent btn-icon"><span class="icon icon-triangle-up"></span></button>
|
||||
<button v-if="$index==current_zone_idx" v-on:click="sort_zone_down(z)" class="btn btn-sm btn-round btn-transparent btn-icon"><span class="icon icon-triangle-down"></span></button>
|
||||
|
Loading…
Reference in New Issue
Block a user