2019-07-15 19:39:30 +03:00
|
|
|
Org = new Mongo.Collection('org');
|
|
|
|
|
|
|
|
/**
|
2020-12-28 21:08:27 +02:00
|
|
|
* A Organization in Wekan. A Enterprise in Trello.
|
2019-07-15 19:39:30 +03:00
|
|
|
*/
|
|
|
|
Org.attachSchema(
|
|
|
|
new SimpleSchema({
|
2021-02-11 19:07:34 +02:00
|
|
|
orgDisplayName: {
|
2019-07-15 19:39:30 +03:00
|
|
|
/**
|
2020-12-28 21:08:27 +02:00
|
|
|
* the name to display for the organization
|
2019-07-15 19:39:30 +03:00
|
|
|
*/
|
2020-12-28 21:08:27 +02:00
|
|
|
type: String,
|
2019-07-15 19:39:30 +03:00
|
|
|
optional: true,
|
|
|
|
},
|
2021-02-11 19:07:34 +02:00
|
|
|
orgDesc: {
|
2019-07-15 19:39:30 +03:00
|
|
|
/**
|
2020-12-28 21:08:27 +02:00
|
|
|
* the description the organization
|
2019-07-15 19:39:30 +03:00
|
|
|
*/
|
|
|
|
type: String,
|
|
|
|
optional: true,
|
|
|
|
max: 190,
|
|
|
|
},
|
2021-02-11 19:07:34 +02:00
|
|
|
orgShortName: {
|
2019-07-15 19:39:30 +03:00
|
|
|
/**
|
2020-12-28 21:08:27 +02:00
|
|
|
* short name of the organization
|
2019-07-15 19:39:30 +03:00
|
|
|
*/
|
|
|
|
type: String,
|
|
|
|
optional: true,
|
|
|
|
max: 255,
|
|
|
|
},
|
2021-02-11 19:07:34 +02:00
|
|
|
orgWebsite: {
|
2019-07-15 19:39:30 +03:00
|
|
|
/**
|
2020-12-28 21:08:27 +02:00
|
|
|
* website of the organization
|
2019-07-15 19:39:30 +03:00
|
|
|
*/
|
|
|
|
type: String,
|
|
|
|
optional: true,
|
|
|
|
max: 255,
|
|
|
|
},
|
|
|
|
createdAt: {
|
|
|
|
/**
|
|
|
|
* creation date of the organization
|
|
|
|
*/
|
|
|
|
type: Date,
|
|
|
|
// eslint-disable-next-line consistent-return
|
|
|
|
autoValue() {
|
|
|
|
if (this.isInsert) {
|
|
|
|
return new Date();
|
2019-09-05 12:29:45 -05:00
|
|
|
} else if (this.isUpsert) {
|
|
|
|
return { $setOnInsert: new Date() };
|
2019-07-15 19:39:30 +03:00
|
|
|
} 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();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
|
2021-02-11 19:07:34 +02:00
|
|
|
if (Meteor.isServer) {
|
|
|
|
Meteor.methods({
|
|
|
|
setCreateOrg(
|
|
|
|
orgDisplayName,
|
|
|
|
orgDesc,
|
|
|
|
orgShortName,
|
|
|
|
orgWebsite,
|
|
|
|
orgIsActive,
|
|
|
|
) {
|
|
|
|
if (Meteor.user() && Meteor.user().isAdmin) {
|
|
|
|
check(orgDisplayName, String);
|
|
|
|
check(orgDesc, String);
|
|
|
|
check(orgShortName, String);
|
|
|
|
check(orgWebsite, String);
|
|
|
|
check(orgIsActive, String);
|
|
|
|
|
|
|
|
const nOrgNames = Org.find({ orgShortName }).count();
|
|
|
|
if (nOrgNames > 0) {
|
|
|
|
throw new Meteor.Error('orgname-already-taken');
|
|
|
|
} else {
|
|
|
|
Org.insert({
|
|
|
|
orgDisplayName,
|
|
|
|
orgDesc,
|
|
|
|
orgShortName,
|
|
|
|
orgWebsite,
|
|
|
|
orgIsActive,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
setOrgDisplayName(org, orgDisplayName) {
|
|
|
|
if (Meteor.user() && Meteor.user().isAdmin) {
|
|
|
|
check(org, String);
|
|
|
|
check(orgDisplayName, String);
|
|
|
|
Org.update(org, {
|
|
|
|
$set: { orgDisplayName: orgDisplayName },
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
setOrgDesc(org, orgDesc) {
|
|
|
|
if (Meteor.user() && Meteor.user().isAdmin) {
|
|
|
|
check(org, String);
|
|
|
|
check(orgDesc, String);
|
|
|
|
Org.update(org, {
|
|
|
|
$set: { orgDesc: orgDesc },
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
setOrgShortName(org, orgShortName) {
|
|
|
|
if (Meteor.user() && Meteor.user().isAdmin) {
|
|
|
|
check(org, String);
|
|
|
|
check(orgShortName, String);
|
|
|
|
Org.update(org, {
|
|
|
|
$set: { orgShortName: orgShortName },
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
setOrgIsActive(org, orgIsActive) {
|
|
|
|
if (Meteor.user() && Meteor.user().isAdmin) {
|
|
|
|
check(org, String);
|
|
|
|
check(orgIsActive, String);
|
|
|
|
Org.update(org, {
|
|
|
|
$set: { orgIsActive: orgIsActive },
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-07-15 22:47:30 +03:00
|
|
|
if (Meteor.isServer) {
|
|
|
|
// Index for Organization name.
|
|
|
|
Meteor.startup(() => {
|
|
|
|
Org._collection._ensureIndex({ name: -1 });
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-07-15 19:39:30 +03:00
|
|
|
export default Org;
|