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,
|
space_id: Sequelize.STRING,
|
||||||
user_id: Sequelize.STRING,
|
user_id: Sequelize.STRING,
|
||||||
role: Sequelize.STRING,
|
role: Sequelize.STRING,
|
||||||
|
code: Sequelize.STRING,
|
||||||
|
state: {type: Sequelize.STRING, defaultValue: "pending"},
|
||||||
created_at: {type: Sequelize.DATE, defaultValue: Sequelize.NOW},
|
created_at: {type: Sequelize.DATE, defaultValue: Sequelize.NOW},
|
||||||
updated_at: {type: Sequelize.DATE, defaultValue: Sequelize.NOW}
|
updated_at: {type: Sequelize.DATE, defaultValue: Sequelize.NOW}
|
||||||
}),
|
}),
|
||||||
@ -211,6 +213,20 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
as: 'creator'
|
as: 'creator'
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Membership.belongsTo(User, {
|
||||||
|
foreignKey: {
|
||||||
|
name: 'user_id'
|
||||||
|
},
|
||||||
|
as: 'user'
|
||||||
|
});
|
||||||
|
|
||||||
|
Membership.belongsTo(Space, {
|
||||||
|
foreignKey: {
|
||||||
|
name: 'space_id'
|
||||||
|
},
|
||||||
|
as: 'space'
|
||||||
|
});
|
||||||
|
|
||||||
Artifact.belongsTo(User, {
|
Artifact.belongsTo(User, {
|
||||||
foreignKey: {
|
foreignKey: {
|
||||||
|
@ -1,12 +1,8 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var config = require('config');
|
var config = require('config');
|
||||||
require('../../models/db');
|
|
||||||
|
|
||||||
var fs = require('fs');
|
|
||||||
var _ = require("underscore");
|
|
||||||
var async = require('async');
|
var async = require('async');
|
||||||
var request = require('request');
|
|
||||||
var url = require("url");
|
var url = require("url");
|
||||||
var path = require("path");
|
var path = require("path");
|
||||||
var crypto = require('crypto');
|
var crypto = require('crypto');
|
||||||
@ -15,38 +11,30 @@ var glob = require('glob');
|
|||||||
var express = require('express');
|
var express = require('express');
|
||||||
var router = express.Router();
|
var router = express.Router();
|
||||||
|
|
||||||
var userMapping = { '_id': 1, 'nickname': 1, 'email': 1};
|
const db = require('../../models/db');
|
||||||
var spaceMapping = { '_id': 1, name: 1};
|
const Sequelize = require('sequelize');
|
||||||
|
const Op = Sequelize.Op;
|
||||||
|
const uuidv4 = require('uuid/v4');
|
||||||
|
|
||||||
router.get('/:membership_id/accept', function(req, res, next) {
|
router.get('/:membership_id/accept', function(req, res, next) {
|
||||||
if (req.user) {
|
if (req.user) {
|
||||||
Membership.findOne({
|
db.Membership.findOne({where:{
|
||||||
_id: req.params.membership_id,
|
_id: req.params.membership_id,
|
||||||
state: "pending",
|
code: req.query.code
|
||||||
code: req.query.code,
|
}, include: ['space']}).then((mem) => {
|
||||||
user: { "$exists": false }
|
if (mem) {
|
||||||
}).populate('space').exec((err,mem) => {
|
if (!mem.user) {
|
||||||
if (err) res.sendStatus(400);
|
mem.state = "active";
|
||||||
else {
|
mem.user_id = req.user._id;
|
||||||
if (mem) {
|
|
||||||
if(!mem.user) {
|
mem.save().then(function() {
|
||||||
mem.code = null;
|
res.status(200).json(mem);
|
||||||
mem.state = "active";
|
});
|
||||||
mem.user = req.user;
|
|
||||||
|
|
||||||
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"});
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
res.status(404).json({"error": "not found"});
|
res.status(200).json(mem);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
res.status(404).json({"error": "not found"});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
@ -15,37 +15,16 @@ var request = require('request');
|
|||||||
var url = require("url");
|
var url = require("url");
|
||||||
var path = require("path");
|
var path = require("path");
|
||||||
var glob = require('glob');
|
var glob = require('glob');
|
||||||
|
var crypto = require('crypto');
|
||||||
|
|
||||||
var express = require('express');
|
var express = require('express');
|
||||||
var router = express.Router({mergeParams: true});
|
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) {
|
router.get('/', function(req, res, next) {
|
||||||
db.Membership
|
db.Membership
|
||||||
.findAll({where: {
|
.findAll({where: {
|
||||||
space_id: req.space._id
|
space_id: req.space._id
|
||||||
}})
|
}, include: ['user']})
|
||||||
//.populate("user")
|
|
||||||
.then(memberships => {
|
.then(memberships => {
|
||||||
res.status(200).json(memberships);
|
res.status(200).json(memberships);
|
||||||
});
|
});
|
||||||
@ -54,8 +33,8 @@ router.get('/', function(req, res, next) {
|
|||||||
router.post('/', function(req, res, next) {
|
router.post('/', function(req, res, next) {
|
||||||
if (req.spaceRole == "admin") {
|
if (req.spaceRole == "admin") {
|
||||||
var attrs = req.body;
|
var attrs = req.body;
|
||||||
attrs['space'] = req.space._id;
|
attrs.space_id = req.space._id;
|
||||||
attrs['state'] = "pending";
|
attrs.state = "pending";
|
||||||
attrs._id = uuidv4();
|
attrs._id = uuidv4();
|
||||||
var membership = attrs;
|
var membership = attrs;
|
||||||
|
|
||||||
@ -64,10 +43,10 @@ router.post('/', function(req, res, next) {
|
|||||||
if (membership.email_invited != req.user.email) {
|
if (membership.email_invited != req.user.email) {
|
||||||
db.User.findOne({where:{
|
db.User.findOne({where:{
|
||||||
"email": membership.email_invited
|
"email": membership.email_invited
|
||||||
}}, function(user) {
|
}}).then(function(user) {
|
||||||
|
|
||||||
if (user) {
|
if (user) {
|
||||||
membership.user = user;
|
membership.user_id = user._id;
|
||||||
membership.state = "active";
|
membership.state = "active";
|
||||||
} else {
|
} else {
|
||||||
membership.code = crypto.randomBytes(64).toString('hex').substring(0, 12);
|
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) {
|
router.put('/:membership_id', function(req, res, next) {
|
||||||
if (req.user) {
|
if (req.user) {
|
||||||
if (req.spaceRole == "admin") {
|
if (req.spaceRole == "admin") {
|
||||||
Membership.findOne({
|
db.Membership.findOne({ where: {
|
||||||
_id: req.params.membership_id
|
_id: req.params.membership_id
|
||||||
}, function(err, mem) {
|
}}).then(function(mem) {
|
||||||
if (err) res.sendStatus(400);
|
if (mem) {
|
||||||
else {
|
var attrs = req.body;
|
||||||
if (mem) {
|
mem.role = attrs.role;
|
||||||
var attrs = req.body;
|
mem.save(function() {
|
||||||
mem.role = attrs.role;
|
res.status(201).json(mem);
|
||||||
mem.save(function(err) {
|
});
|
||||||
if (err) res.sendStatus(400);
|
|
||||||
else {
|
|
||||||
res.status(201).json(mem);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@ -146,20 +119,12 @@ router.put('/:membership_id', function(req, res, next) {
|
|||||||
|
|
||||||
router.delete('/:membership_id', function(req, res, next) {
|
router.delete('/:membership_id', function(req, res, next) {
|
||||||
if (req.user) {
|
if (req.user) {
|
||||||
Membership.findOne({
|
db.Membership.findOne({ where: {
|
||||||
_id: req.params.membership_id
|
_id: req.params.membership_id
|
||||||
}, function(err, mem) {
|
}}).then(function(mem) {
|
||||||
if (err) res.sendStatus(400);
|
mem.destroy().then(function() {
|
||||||
else {
|
res.sendStatus(204);
|
||||||
mem.remove(function(err) {
|
});
|
||||||
if (err) {
|
|
||||||
res.status(400).json(err);
|
|
||||||
} else {
|
|
||||||
// FIXME might need to delete the user?
|
|
||||||
res.sendStatus(204);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
res.sendStatus(403);
|
res.sendStatus(403);
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
<button v-on:click="add_zone()" class="btn btn-sm btn-primary">[[__("add_zone")]]</button>
|
<button v-on:click="add_zone()" class="btn btn-sm btn-primary">[[__("add_zone")]]</button>
|
||||||
</div>
|
</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 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_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>
|
<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