Groundwork for default libraries and slots
This commit is contained in:
@@ -18,6 +18,13 @@ let CreaturePropertySchema = new SimpleSchema({
|
||||
type: String,
|
||||
allowedValues: Object.keys(propertySchemasIndex),
|
||||
},
|
||||
tags: {
|
||||
type: Array,
|
||||
defaultValue: [],
|
||||
},
|
||||
'tags.$': {
|
||||
type: String,
|
||||
},
|
||||
});
|
||||
|
||||
for (let key in propertySchemasIndex){
|
||||
|
||||
@@ -21,7 +21,7 @@ const insertCreature = new ValidatedMethod({
|
||||
|
||||
validate: null,
|
||||
|
||||
run(characterFormData) {
|
||||
run() {
|
||||
if (!this.userId) {
|
||||
throw new Meteor.Error("Creatures.methods.insert.denied",
|
||||
"You need to be logged in to insert a creature");
|
||||
@@ -29,18 +29,9 @@ const insertCreature = new ValidatedMethod({
|
||||
|
||||
// Create the creature document
|
||||
let charId = Creatures.insert({
|
||||
name: characterFormData.name,
|
||||
owner: this.userId,
|
||||
alignment: characterFormData.alignment,
|
||||
gender: characterFormData.gender,
|
||||
race: characterFormData.race,
|
||||
});
|
||||
this.unblock();
|
||||
if (Meteor.isServer){
|
||||
//Add all the required attributes to it
|
||||
let docs = getDefaultCharacterDocs(charId, characterFormData);
|
||||
addDefaultDocs(docs);
|
||||
}
|
||||
return charId;
|
||||
},
|
||||
|
||||
|
||||
@@ -17,6 +17,10 @@ let LibrarySchema = new SimpleSchema({
|
||||
name: {
|
||||
type: String,
|
||||
},
|
||||
isDefault: {
|
||||
type: Boolean,
|
||||
optional: true,
|
||||
},
|
||||
});
|
||||
|
||||
LibrarySchema.extend(SharingSchema);
|
||||
@@ -30,11 +34,30 @@ const insertLibrary = new ValidatedMethod({
|
||||
mixins: [
|
||||
simpleSchemaMixin,
|
||||
],
|
||||
schema: LibrarySchema.omit('owner'),
|
||||
schema: LibrarySchema.omit('owner', 'isDefault'),
|
||||
run(library) {
|
||||
library.owner = this.userId;
|
||||
return Libraries.insert(library);
|
||||
},
|
||||
});
|
||||
|
||||
export { LibrarySchema, insertLibrary };
|
||||
const setLibraryDefault = new ValidatedMethod({
|
||||
name: 'Libraries.methods.makeLibraryDefault',
|
||||
validate: new SimpleSchema({
|
||||
_id: {
|
||||
type: String,
|
||||
regEx: SimpleSchema.RegEx.id
|
||||
},
|
||||
isDefault: {
|
||||
type: Boolean,
|
||||
},
|
||||
}).validator(),
|
||||
run({_id, isDefault}) {
|
||||
if (!Meteor.users.isAdmin()){
|
||||
throw new Meteor.Error('Permission denied', 'User must be admin to set libraries as default');
|
||||
}
|
||||
return Libraries.update(_id, {$set: {isDefault}});
|
||||
},
|
||||
});
|
||||
|
||||
export { LibrarySchema, insertLibrary, setLibraryDefault };
|
||||
|
||||
@@ -13,6 +13,13 @@ let LibraryNodeSchema = new SimpleSchema({
|
||||
type: String,
|
||||
allowedValues: Object.keys(propertySchemasIndex),
|
||||
},
|
||||
tags: {
|
||||
type: Array,
|
||||
defaultValue: [],
|
||||
},
|
||||
'tags.$': {
|
||||
type: String,
|
||||
},
|
||||
});
|
||||
|
||||
for (let key in propertySchemasIndex){
|
||||
|
||||
@@ -107,7 +107,6 @@ export function setLineageOfDocs({docArray, oldParent, newAncestry}){
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Give documents new random ids and transform their references.
|
||||
* Transform collections of re-IDed docs according to the collection map
|
||||
|
||||
@@ -21,6 +21,13 @@ let ClassLevelSchema = new SimpleSchema({
|
||||
type: SimpleSchema.Integer,
|
||||
defaultValue: 1,
|
||||
},
|
||||
nextLevelTags: {
|
||||
type: Array,
|
||||
defaultValue: [],
|
||||
},
|
||||
'nextLevelTags.$': {
|
||||
type: String,
|
||||
},
|
||||
});
|
||||
|
||||
export { ClassLevelSchema };
|
||||
|
||||
13
app/imports/api/properties/Slots.js
Normal file
13
app/imports/api/properties/Slots.js
Normal file
@@ -0,0 +1,13 @@
|
||||
import SimpleSchema from 'simpl-schema';
|
||||
|
||||
let SlotSchema = new SimpleSchema({
|
||||
slotTags: {
|
||||
type: Array,
|
||||
defaultValue: [],
|
||||
},
|
||||
'slotTags.$': {
|
||||
type: String,
|
||||
},
|
||||
});
|
||||
|
||||
export { SlotSchema };
|
||||
@@ -12,8 +12,9 @@ import { FolderSchema } from '/imports/api/properties/Folders.js';
|
||||
import { NoteSchema } from '/imports/api/properties/Notes.js';
|
||||
import { ProficiencySchema } from '/imports/api/properties/Proficiencies.js';
|
||||
import { RollSchema } from '/imports/api/properties/Rolls.js';
|
||||
import { SkillSchema } from '/imports/api/properties/Skills.js';
|
||||
import { SavingThrowSchema } from '/imports/api/properties/SavingThrows.js';
|
||||
import { SkillSchema } from '/imports/api/properties/Skills.js';
|
||||
import { SlotSchema } from '/imports/api/properties/Slots.js';
|
||||
import { SpellListSchema } from '/imports/api/properties/SpellLists.js';
|
||||
import { SpellSchema } from '/imports/api/properties/Spells.js';
|
||||
import { ContainerSchema } from '/imports/api/properties/Containers.js';
|
||||
@@ -35,6 +36,7 @@ const propertySchemasIndex = {
|
||||
roll: RollSchema,
|
||||
savingThrow: SavingThrowSchema,
|
||||
skill: SkillSchema,
|
||||
slot: SlotSchema,
|
||||
spellList: SpellListSchema,
|
||||
spell: SpellSchema,
|
||||
container: ContainerSchema,
|
||||
|
||||
@@ -105,7 +105,7 @@ Meteor.users.sendVerificationEmail = new ValidatedMethod({
|
||||
}).validator(),
|
||||
run(userId, address){
|
||||
userId = this.userId || userId;
|
||||
let user = Meteor.users.findOne();
|
||||
let user = Meteor.users.findOne(userId);
|
||||
if (!user) {
|
||||
throw new Meteor.Error('User not found',
|
||||
'Can\'t send a validation email to a user that does not exist');
|
||||
@@ -114,6 +114,12 @@ Meteor.users.sendVerificationEmail = new ValidatedMethod({
|
||||
throw new Meteor.Error('Email address not found',
|
||||
'The specified email address wasn\'t found on this user account');
|
||||
}
|
||||
Accounts.sendVerificationEmail(this.userId, address);
|
||||
Accounts.sendVerificationEmail(userId, address);
|
||||
}
|
||||
});
|
||||
|
||||
Meteor.users.isAdmin = function(userId){
|
||||
userId = this.userId || userId;
|
||||
let user = Meteor.users.findOne(userId);
|
||||
return user && user.roles.includes('admin');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user