Teams/Organizations: Added more code to Admin Panel for saving and editing. In Progress.

Thanks to xet7 !

Related #802
This commit is contained in:
Lauri Ojansivu 2021-02-11 19:07:34 +02:00
parent b8d52a5aa8
commit 1bc07b1b4a
8 changed files with 345 additions and 178 deletions

View file

@ -736,11 +736,11 @@ Cards.helpers({
// at linked cards custom fields definition is not found
ret.sort(
(a, b) =>
a.definition !== undefined &&
b.definition !== undefined &&
a.definition !== undefined &&
b.definition !== undefined &&
a.definition.name !== undefined &&
b.definition.name !== undefined &&
a.definition.name.localeCompare(b.definition.name)
a.definition.name.localeCompare(b.definition.name),
);
return ret;
},

View file

@ -5,27 +5,14 @@ Org = new Mongo.Collection('org');
*/
Org.attachSchema(
new SimpleSchema({
_id: {
/**
* the organization id
*/
type: Number,
optional: true,
// eslint-disable-next-line consistent-return
autoValue() {
if (this.isInsert && !this.isSet) {
return incrementCounter('counters', 'orgId', 1);
}
},
},
displayName: {
orgDisplayName: {
/**
* the name to display for the organization
*/
type: String,
optional: true,
},
desc: {
orgDesc: {
/**
* the description the organization
*/
@ -33,7 +20,7 @@ Org.attachSchema(
optional: true,
max: 190,
},
name: {
orgShortName: {
/**
* short name of the organization
*/
@ -41,7 +28,7 @@ Org.attachSchema(
optional: true,
max: 255,
},
website: {
orgWebsite: {
/**
* website of the organization
*/
@ -49,66 +36,6 @@ Org.attachSchema(
optional: true,
max: 255,
},
teams: {
/**
* List of teams of a organization
*/
type: [Object],
// eslint-disable-next-line consistent-return
autoValue() {
if (this.isInsert && !this.isSet) {
return [
{
teamId: this.teamId,
isAdmin: true,
isActive: true,
isNoComments: false,
isCommentOnly: false,
isWorker: false,
},
];
}
},
},
'teams.$.teamId': {
/**
* The uniq ID of the team
*/
type: String,
},
'teams.$.isAdmin': {
/**
* Is the team an admin of the board?
*/
type: Boolean,
},
'teams.$.isActive': {
/**
* Is the team active?
*/
type: Boolean,
},
'teams.$.isNoComments': {
/**
* Is the team not allowed to make comments
*/
type: Boolean,
optional: true,
},
'teams.$.isCommentOnly': {
/**
* Is the team only allowed to comment on the board
*/
type: Boolean,
optional: true,
},
'teams.$.isWorker': {
/**
* Is the team only allowed to move card, assign himself to card and comment
*/
type: Boolean,
optional: true,
},
createdAt: {
/**
* creation date of the organization
@ -140,6 +67,79 @@ Org.attachSchema(
}),
);
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 },
});
}
},
});
}
if (Meteor.isServer) {
// Index for Organization name.
Meteor.startup(() => {

View file

@ -5,27 +5,14 @@ Team = new Mongo.Collection('team');
*/
Team.attachSchema(
new SimpleSchema({
_id: {
/**
* the organization id
*/
type: Number,
optional: true,
// eslint-disable-next-line consistent-return
autoValue() {
if (this.isInsert && !this.isSet) {
return incrementCounter('counters', 'orgId', 1);
}
},
},
displayName: {
teamDisplayName: {
/**
* the name to display for the team
*/
type: String,
optional: true,
},
desc: {
teamDesc: {
/**
* the description the team
*/
@ -33,7 +20,7 @@ Team.attachSchema(
optional: true,
max: 190,
},
name: {
teamShortName: {
/**
* short name of the team
*/
@ -41,7 +28,7 @@ Team.attachSchema(
optional: true,
max: 255,
},
website: {
teamWebsite: {
/**
* website of the team
*/
@ -80,6 +67,79 @@ Team.attachSchema(
}),
);
if (Meteor.isServer) {
Meteor.methods({
setCreateTeam(
teamDisplayName,
teamDesc,
teamShortName,
teamWebsite,
teamIsActive,
) {
if (Meteor.user() && Meteor.user().isAdmin) {
check(teamDisplayName, String);
check(teamDesc, String);
check(teamShortName, String);
check(teamWebsite, String);
check(teamIsActive, String);
const nTeamNames = Team.find({ teamShortName }).count();
if (nTeamNames > 0) {
throw new Meteor.Error('teamname-already-taken');
} else {
Team.insert({
teamDisplayName,
teamDesc,
teamShortName,
teamWebsite,
teamIsActive,
});
}
}
},
setTeamDisplayName(team, teamDisplayName) {
if (Meteor.user() && Meteor.user().isAdmin) {
check(team, String);
check(teamDisplayName, String);
Team.update(team, {
$set: { teamDisplayName: teamDisplayName },
});
}
},
setTeamDesc(team, teamDesc) {
if (Meteor.user() && Meteor.user().isAdmin) {
check(team, String);
check(teamDesc, String);
Team.update(team, {
$set: { teamDesc: teamDesc },
});
}
},
setTeamShortName(team, teamShortName) {
if (Meteor.user() && Meteor.user().isAdmin) {
check(team, String);
check(teamShortName, String);
Team.update(team, {
$set: { teamShortName: teamShortName },
});
}
},
setTeamIsActive(team, teamIsActive) {
if (Meteor.user() && Meteor.user().isAdmin) {
check(team, String);
check(teamIsActive, String);
Team.update(team, {
$set: { teamIsActive: teamIsActive },
});
}
},
});
}
if (Meteor.isServer) {
// Index for Team name.
Meteor.startup(() => {