Merge branch 'kaleidos-issues/23/deleting-space-user-is-not-possible'

This commit is contained in:
Lukas F. Hartmann 2018-07-17 12:17:56 +02:00
commit 9889aaa34c
3 changed files with 123 additions and 25 deletions

View File

@ -1,7 +1,4 @@
//'use strict'; const Umzug = require('umzug');
//var mongoose = require('mongoose');
//const sqlite3 = require('sqlite3').verbose();
function sequel_log(a,b,c) { function sequel_log(a,b,c) {
console.log(a); console.log(a);
@ -81,13 +78,13 @@ module.exports = {
height: Sequelize.INTEGER, height: Sequelize.INTEGER,
background_color: Sequelize.STRING, background_color: Sequelize.STRING,
background_uri: Sequelize.STRING, background_uri: Sequelize.STRING,
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},
thumbnail_url: Sequelize.STRING, thumbnail_url: Sequelize.STRING,
thumbnail_updated_at: {type: Sequelize.DATE} thumbnail_updated_at: {type: Sequelize.DATE}
}), }),
Membership: sequelize.define('membership', { Membership: sequelize.define('membership', {
_id: {type: Sequelize.STRING, primaryKey: true}, _id: {type: Sequelize.STRING, primaryKey: true},
space_id: Sequelize.STRING, space_id: Sequelize.STRING,
@ -98,7 +95,7 @@ module.exports = {
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}
}), }),
Message: sequelize.define('message', { Message: sequelize.define('message', {
_id: {type: Sequelize.STRING, primaryKey: true}, _id: {type: Sequelize.STRING, primaryKey: true},
space_id: Sequelize.STRING, space_id: Sequelize.STRING,
@ -108,7 +105,7 @@ module.exports = {
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}
}), }),
Artifact: sequelize.define('artifact', { Artifact: sequelize.define('artifact', {
_id: {type: Sequelize.STRING, primaryKey: true}, _id: {type: Sequelize.STRING, primaryKey: true},
space_id: Sequelize.STRING, space_id: Sequelize.STRING,
@ -121,7 +118,7 @@ module.exports = {
last_update_editor_name: Sequelize.STRING, last_update_editor_name: Sequelize.STRING,
description: Sequelize.TEXT, description: Sequelize.TEXT,
state: {type: Sequelize.STRING, default: "idle"}, state: {type: Sequelize.STRING, default: "idle"},
//linked_to: Sequelize.STRING, //linked_to: Sequelize.STRING,
title: Sequelize.STRING, title: Sequelize.STRING,
tags: Sequelize.TEXT, tags: Sequelize.TEXT,
@ -142,16 +139,16 @@ module.exports = {
//}], //}],
control_points: Sequelize.TEXT, control_points: Sequelize.TEXT,
group: Sequelize.STRING, group: Sequelize.STRING,
locked: {type: Sequelize.BOOLEAN, default: false}, locked: {type: Sequelize.BOOLEAN, default: false},
payload_uri: Sequelize.STRING, payload_uri: Sequelize.STRING,
payload_thumbnail_web_uri: Sequelize.STRING, payload_thumbnail_web_uri: Sequelize.STRING,
payload_thumbnail_medium_uri: Sequelize.STRING, payload_thumbnail_medium_uri: Sequelize.STRING,
payload_thumbnail_big_uri: Sequelize.STRING, payload_thumbnail_big_uri: Sequelize.STRING,
payload_size: Sequelize.INTEGER, // file size in bytes payload_size: Sequelize.INTEGER, // file size in bytes
fill_color: {type: Sequelize.STRING, default: "transparent"}, fill_color: {type: Sequelize.STRING, default: "transparent"},
stroke_color: {type: Sequelize.STRING, default: "#000000"}, stroke_color: {type: Sequelize.STRING, default: "#000000"},
text_color: Sequelize.STRING, text_color: Sequelize.STRING,
@ -176,7 +173,7 @@ module.exports = {
border_radius: Sequelize.INTEGER, border_radius: Sequelize.INTEGER,
align: {type: Sequelize.STRING, default: "left"}, align: {type: Sequelize.STRING, default: "left"},
valign: {type: Sequelize.STRING, default: "top"}, valign: {type: Sequelize.STRING, default: "top"},
brightness: Sequelize.DECIMAL, brightness: Sequelize.DECIMAL,
contrast: Sequelize.DECIMAL, contrast: Sequelize.DECIMAL,
saturation: Sequelize.DECIMAL, saturation: Sequelize.DECIMAL,
@ -185,7 +182,7 @@ module.exports = {
opacity: Sequelize.DECIMAL, opacity: Sequelize.DECIMAL,
payload_alternatives: Sequelize.TEXT, payload_alternatives: Sequelize.TEXT,
/*payload_alternatives: [{ /*payload_alternatives: [{
mime: String, mime: String,
payload_uri: String, payload_uri: String,
@ -194,12 +191,12 @@ module.exports = {
payload_thumbnail_big_uri: String, payload_thumbnail_big_uri: String,
payload_size: Number payload_size: Number
}],*/ }],*/
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}
}), }),
init: function() { init: async function() {
User = this.User; User = this.User;
Session = this.Session; Session = this.Session;
Space = this.Space; Space = this.Space;
@ -220,49 +217,69 @@ module.exports = {
}, },
as: 'user' as: 'user'
}); });
Membership.belongsTo(Space, { Membership.belongsTo(Space, {
foreignKey: { foreignKey: {
name: 'space_id' name: 'space_id'
}, },
as: 'space' as: 'space'
}); });
Artifact.belongsTo(User, { Artifact.belongsTo(User, {
foreignKey: { foreignKey: {
name: 'user_id' name: 'user_id'
}, },
as: 'user' as: 'user'
}); });
Artifact.belongsTo(Space, { Artifact.belongsTo(Space, {
foreignKey: { foreignKey: {
name: 'space_id' name: 'space_id'
}, },
as: 'space' as: 'space'
}); });
Message.belongsTo(User, { Message.belongsTo(User, {
foreignKey: { foreignKey: {
name: 'user_id' name: 'user_id'
}, },
as: 'user' as: 'user'
}); });
Message.belongsTo(Space, { Message.belongsTo(Space, {
foreignKey: { foreignKey: {
name: 'space_id' name: 'space_id'
}, },
as: 'space' as: 'space'
}); });
sequelize.sync(); await sequelize.sync();
var umzug = new Umzug({
storage: 'sequelize',
storageOptions: {
sequelize: sequelize
},
migrations: {
params: [
sequelize.getQueryInterface(),
Sequelize
],
path: './models/migrations',
pattern: /\.js$/
}
});
umzug.up().then(function(migrations) {
console.log('Migration complete up!');
});
}, },
getUserRoleInSpace: (originalSpace, user, cb) => { getUserRoleInSpace: (originalSpace, user, cb) => {
originalSpace.path = []; originalSpace.path = [];
console.log("getUserRoleInSpace",originalSpace._id,user._id,user.home_folder_id); console.log("getUserRoleInSpace",originalSpace._id,user._id,user.home_folder_id);
if (originalSpace._id == user.home_folder_id || (originalSpace.creator_id && originalSpace.creator_id == user._id)) { if (originalSpace._id == user.home_folder_id || (originalSpace.creator_id && originalSpace.creator_id == user._id)) {
cb("admin"); cb("admin");
} else { } else {

View File

@ -0,0 +1,80 @@
'use strict';
module.exports = {
up: function(migration, DataTypes) {
return [
migration.changeColumn('memberships', 'space_id',
{
type: DataTypes.STRING,
references: {
model: 'spaces',
key: '_id'
},
onDelete: 'CASCADE',
onUpdate: 'CASCADE'
}
),
migration.changeColumn('artifacts', 'space_id',
{
type: DataTypes.STRING,
references: {
model: 'spaces',
key: '_id'
},
onDelete: 'CASCADE',
onUpdate: 'CASCADE'
}
),
migration.changeColumn('messages', 'space_id',
{
type: DataTypes.STRING,
references: {
model: 'spaces',
key: '_id'
},
onDelete: 'CASCADE',
onUpdate: 'CASCADE'
}
)
]
},
down: function(migration, DataTypes) {
return [
migration.changeColumn('memberships', 'space_id',
{
type: DataTypes.STRING,
references: {
model: 'spaces',
key: '_id'
},
onDelete: 'CASCADE',
onUpdate: 'NO ACTION'
}
),
,
migration.changeColumn('artifacts', 'space_id',
{
type: DataTypes.STRING,
references: {
model: 'spaces',
key: '_id'
},
onDelete: 'CASCADE',
onUpdate: 'NO ACTION'
}
),
migration.changeColumn('messages', 'space_id',
{
type: DataTypes.STRING,
references: {
model: 'spaces',
key: '_id'
},
onDelete: 'CASCADE',
onUpdate: 'NO ACTION'
}
)
]
}
};

View File

@ -40,6 +40,7 @@
"slug": "0.9.1", "slug": "0.9.1",
"sqlite3": "^4.0.0", "sqlite3": "^4.0.0",
"swig": "1.4.2", "swig": "1.4.2",
"umzug": "^2.1.0",
"underscore": "1.8.3", "underscore": "1.8.3",
"uuid": "^3.2.1", "uuid": "^3.2.1",
"validator": "7.0.0", "validator": "7.0.0",