mirror of
https://github.com/wekan/wekan.git
synced 2025-12-17 07:50:12 +01:00
Teams/Organizations part 3, in progress. Table: org_user, and indexes.
Thanks to xet7 ! Related #802
This commit is contained in:
parent
583f32e5c5
commit
41950ba4de
2 changed files with 83 additions and 0 deletions
80
models/orgUser.js
Normal file
80
models/orgUser.js
Normal file
|
|
@ -0,0 +1,80 @@
|
||||||
|
OrgUser = new Mongo.Collection('org_user');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Organization User in wekan
|
||||||
|
*/
|
||||||
|
OrgUser.attachSchema(
|
||||||
|
new SimpleSchema({
|
||||||
|
id: {
|
||||||
|
/**
|
||||||
|
* the organization user's id
|
||||||
|
*/
|
||||||
|
type: Number,
|
||||||
|
optional: true,
|
||||||
|
// eslint-disable-next-line consistent-return
|
||||||
|
autoValue() {
|
||||||
|
if (this.isInsert && !this.isSet) {
|
||||||
|
return incrementCounter('counters', 'org_user_id', 1);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
org_id: {
|
||||||
|
/**
|
||||||
|
* the organization id
|
||||||
|
*/
|
||||||
|
type: Number,
|
||||||
|
optional: true,
|
||||||
|
},
|
||||||
|
user_id: {
|
||||||
|
/**
|
||||||
|
* the user id
|
||||||
|
*/
|
||||||
|
type: Number,
|
||||||
|
optional: true,
|
||||||
|
},
|
||||||
|
role: {
|
||||||
|
/**
|
||||||
|
* the role of user
|
||||||
|
*/
|
||||||
|
type: String,
|
||||||
|
optional: true,
|
||||||
|
max: 20,
|
||||||
|
},
|
||||||
|
createdAt: {
|
||||||
|
/**
|
||||||
|
* creation date of the organization user
|
||||||
|
*/
|
||||||
|
type: Date,
|
||||||
|
// eslint-disable-next-line consistent-return
|
||||||
|
autoValue() {
|
||||||
|
if (this.isInsert) {
|
||||||
|
return new Date();
|
||||||
|
} else {
|
||||||
|
this.unset();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
modifiedAt: {
|
||||||
|
type: Date,
|
||||||
|
denyUpdate: false,
|
||||||
|
// eslint-disable-next-line consistent-return
|
||||||
|
autoValue() {
|
||||||
|
if (this.isInsert || this.isUpsert || this.isUpdate) {
|
||||||
|
return new Date();
|
||||||
|
} else {
|
||||||
|
this.unset();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
if (Meteor.isServer) {
|
||||||
|
// Index for Organization User.
|
||||||
|
Meteor.startup(() => {
|
||||||
|
OrgUser._collection._ensureIndex({ org_id: -1 });
|
||||||
|
OrgUser._collection._ensureIndex({ org_id: -1, user_id: -1 });
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export default OrgUser;
|
||||||
|
|
@ -18,6 +18,7 @@ import Triggers from '../models/triggers';
|
||||||
import UnsavedEdits from '../models/unsavedEdits';
|
import UnsavedEdits from '../models/unsavedEdits';
|
||||||
import Users from '../models/users';
|
import Users from '../models/users';
|
||||||
import Org from '../models/org';
|
import Org from '../models/org';
|
||||||
|
import OrgUser from '../models/orgUser';
|
||||||
|
|
||||||
// Anytime you change the schema of one of the collection in a non-backward
|
// Anytime you change the schema of one of the collection in a non-backward
|
||||||
// compatible way you have to write a migration in this file using the following
|
// compatible way you have to write a migration in this file using the following
|
||||||
|
|
@ -705,6 +706,7 @@ const firstBatchOfDbsToAddCreatedAndUpdated = [
|
||||||
Triggers,
|
Triggers,
|
||||||
UnsavedEdits,
|
UnsavedEdits,
|
||||||
Org,
|
Org,
|
||||||
|
OrgUser,
|
||||||
];
|
];
|
||||||
|
|
||||||
firstBatchOfDbsToAddCreatedAndUpdated.forEach(db => {
|
firstBatchOfDbsToAddCreatedAndUpdated.forEach(db => {
|
||||||
|
|
@ -740,6 +742,7 @@ const modifiedAtTables = [
|
||||||
UnsavedEdits,
|
UnsavedEdits,
|
||||||
Users,
|
Users,
|
||||||
Org,
|
Org,
|
||||||
|
OrgUser,
|
||||||
];
|
];
|
||||||
|
|
||||||
Migrations.add('add-missing-created-and-modified', () => {
|
Migrations.add('add-missing-created-and-modified', () => {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue