Vulcan/packages/nova-settings/lib/collection.js
Comus Leong 464e20a96c eslint & clean up code, also fixed some bugs (#1515)
* [eslint] update eslint rules & add .eslintignore to ignore non-ready nova packages

* [clean-up] nova-voting

* [clean-up] [bug] nova-users: missing user parameter

* [clean-up] nova-users

* [clean-up] nova-subscribe

* [clean-up] nova-settings

* [clean-up] nova-rss

* [clean-up] [bug] nova-posts: correct UsersRemoveDeletePosts

* [clean-up] nova-posts

* [clean-up] nova-notifications

* [clean-up] [bug] nova-newsletter: no error.message on throw error

* [clean-up] nova-newsletter

* [clean-up] nova-lib

* [clean-up] nova-kadira

* [clean-up] nova-inject-data

* [clean-up] nova-getting-started

* [clean-up] nova-forms

* [clean-up] nova-events

* [clean-up] [bug] nova-embedly: no FlowRouter

* [clean-up] nova-embedly

* [clean-up] nova-email-templates

* [clean-up] nova-email

* [clean-up] nova-debug

* [clean-up] nova-core

* [clean-up] [bug] nova-comments: correct UsersRemoveDeleteComments

* [clean-up] nova-comments

* [clean-up] [bug] nova-cloudinary: use Telescope.settings.collection instand

* [clean-up] nova-cloudinary

* [clean-up] nova-categories

* [clean-up] nova-base-components

* [clean-up] nova-api

* [eslint] extends react recommended

* [clean-up] for jsx files

* [eslint] extends meteor recommended

* i forgot this one little change
2016-11-25 13:46:55 -05:00

375 lines
8.6 KiB
JavaScript

import Telescope from 'meteor/nova:lib';
import Users from 'meteor/nova:users';
import { SimpleSchema } from 'meteor/aldeed:simple-schema';
const isInSettingsJSON = function () {
// settings can either be in settings json's public, or in the special object we publish only for admins for private settings
return typeof Telescope.settings.getFromJSON(this.name) !== "undefined" || typeof Telescope.settings.settingsJSON[this.name] !== "undefined";
};
const getFromJSON = function () {
return Telescope.settings.getFromJSON(this.name) || Telescope.settings.settingsJSON[this.name];
};
Telescope.settings.collection = new Mongo.Collection("settings");
const canEdit = user => Users.canDo(user, "settings.edit");
Telescope.settings.schema = new SimpleSchema({
title: {
type: String,
optional: true,
insertableIf: canEdit,
editableIf: canEdit,
publish: true,
form: {
disabled: isInSettingsJSON,
prefill: getFromJSON,
instructions: "Your site's title.",
group: "01_general"
}
},
siteUrl: {
type: String,
optional: true,
publish: true,
// regEx: SimpleSchema.RegEx.Url,
insertableIf: canEdit,
editableIf: canEdit,
form: {
disabled: isInSettingsJSON,
prefill: getFromJSON,
group: "01_general",
type: "bootstrap-url",
instructions: 'Your site\'s URL (with trailing "/"). Will default to Meteor.absoluteUrl()'
}
},
tagline: {
type: String,
optional: true,
publish: true,
insertableIf: canEdit,
editableIf: canEdit,
form: {
disabled: isInSettingsJSON,
prefill: getFromJSON,
group: "01_general"
}
},
description: {
type: String,
optional: true,
publish: true,
insertableIf: canEdit,
editableIf: canEdit,
form: {
disabled: isInSettingsJSON,
prefill: getFromJSON,
group: "01_general",
rows: 5,
instructions: 'A short description used for SEO purposes.'
}
},
siteImage: {
type: String,
optional: true,
publish: true,
insertableIf: canEdit,
editableIf: canEdit,
regEx: SimpleSchema.RegEx.Url,
form: {
disabled: isInSettingsJSON,
prefill: getFromJSON,
group: "01_general",
instructions: "URL to an image for the open graph image tag for all pages"
}
},
requireViewInvite: {
type: Boolean,
optional: true,
publish: true,
insertableIf: canEdit,
editableIf: canEdit,
control: "checkbox",
form: {
disabled: isInSettingsJSON,
prefill: getFromJSON,
group: 'invites',
leftLabel: 'Require View Invite'
}
},
requirePostInvite: {
type: Boolean,
optional: true,
publish: true,
insertableIf: canEdit,
editableIf: canEdit,
control: "checkbox",
form: {
disabled: isInSettingsJSON,
prefill: getFromJSON,
group: 'invites',
leftLabel: 'Require Post Invite'
}
},
requirePostsApproval: {
type: Boolean,
optional: true,
publish: true,
insertableIf: canEdit,
editableIf: canEdit,
control: "checkbox",
form: {
disabled: isInSettingsJSON,
prefill: getFromJSON,
group: "01_general",
instructions: "Posts must be approved by admin",
leftLabel: "Require Posts Approval"
}
},
defaultEmail: {
type: String,
optional: true,
insertableIf: canEdit,
editableIf: canEdit,
form: {
disabled: isInSettingsJSON,
prefill: getFromJSON,
group: "06_email",
instructions: 'The address all outgoing emails will be sent from.',
class: "private-field"
}
},
mailUrl: {
type: String,
optional: true,
insertableIf: canEdit,
editableIf: canEdit,
form: {
disabled: isInSettingsJSON,
prefill: getFromJSON,
group: "06_email",
instructions: 'MAIL_URL environment variable (requires restart).',
class: "private-field"
}
},
scoreUpdateInterval: {
type: Number,
optional: true,
defaultValue: 30,
insertableIf: canEdit,
editableIf: canEdit,
form: {
disabled: isInSettingsJSON,
prefill: getFromJSON,
group: '01_general',
instructions: 'How often to recalculate scores, in seconds (default to 30)',
class: "private-field"
}
},
postInterval: {
type: Number,
optional: true,
publish: true,
defaultValue: 30,
insertableIf: canEdit,
editableIf: canEdit,
form: {
disabled: isInSettingsJSON,
prefill: getFromJSON,
group: "02_posts",
instructions: 'Minimum time between posts, in seconds (defaults to 30)'
}
},
RSSLinksPointTo: {
type: String,
optional: true,
publish: true,
insertableIf: canEdit,
editableIf: canEdit,
control: "radiogroup",
form: {
disabled: isInSettingsJSON,
prefill: getFromJSON,
group: "02_posts",
options: [
{value: 'page', label: 'Discussion page'},
{value: 'link', label: 'Outgoing link'}
]
}
},
commentInterval: {
type: Number,
optional: true,
publish: true,
defaultValue: 15,
insertableIf: canEdit,
editableIf: canEdit,
form: {
disabled: isInSettingsJSON,
prefill: getFromJSON,
group: "03_comments",
instructions: 'Minimum time between comments, in seconds (defaults to 15)'
}
},
maxPostsPerDay: {
type: Number,
optional: true,
publish: true,
defaultValue: 30,
insertableIf: canEdit,
editableIf: canEdit,
form: {
disabled: isInSettingsJSON,
prefill: getFromJSON,
group: "02_posts",
instructions: 'Maximum number of posts a user can post in a day (default to 30).'
}
},
startInvitesCount: {
type: Number,
defaultValue: 3,
optional: true,
publish: true,
insertableIf: canEdit,
editableIf: canEdit,
form: {
disabled: isInSettingsJSON,
prefill: getFromJSON,
group: 'invites'
}
},
postsPerPage: {
type: Number,
defaultValue: 10,
optional: true,
publish: true,
insertableIf: canEdit,
editableIf: canEdit,
form: {
disabled: isInSettingsJSON,
prefill: getFromJSON,
group: "02_posts"
}
},
logoUrl: {
type: String,
optional: true,
publish: true,
insertableIf: canEdit,
editableIf: canEdit,
form: {
disabled: isInSettingsJSON,
prefill: getFromJSON,
group: "04_logo"
}
},
logoHeight: {
type: Number,
optional: true,
publish: true,
insertableIf: canEdit,
editableIf: canEdit,
form: {
disabled: isInSettingsJSON,
prefill: getFromJSON,
group: "04_logo"
}
},
logoWidth: {
type: Number,
optional: true,
publish: true,
insertableIf: canEdit,
editableIf: canEdit,
form: {
disabled: isInSettingsJSON,
prefill: getFromJSON,
group: "04_logo"
}
},
faviconUrl: {
type: String,
optional: true,
publish: true,
insertableIf: canEdit,
editableIf: canEdit,
form: {
disabled: isInSettingsJSON,
prefill: getFromJSON,
group: "04_logo"
}
},
// language: {
// type: String,
// defaultValue: 'en',
// optional: true,
// insertableIf: canEdit,
// editableIf: canEdit,
// form: {
// group: "01_general",
// instructions: 'The app\'s language. Defaults to English.',
// options: function () {
// var languages = _.map(TAPi18n.getLanguages(), function (item, key) {
// return {
// value: key,
// label: item.name
// };
// });
// return languages;
// }
// }
// },
twitterAccount: {
type: String,
optional: true,
publish: true,
insertableIf: canEdit,
editableIf: canEdit,
form: {
disabled: isInSettingsJSON,
prefill: getFromJSON,
group: "07_integrations"
}
},
facebookPage: {
type: String,
optional: true,
publish: true,
insertableIf: canEdit,
editableIf: canEdit,
form: {
disabled: isInSettingsJSON,
prefill: getFromJSON,
group: "07_integrations"
}
},
googleAnalyticsId: {
type: String,
optional: true,
publish: true,
insertableIf: canEdit,
editableIf: canEdit,
form: {
disabled: isInSettingsJSON,
prefill: getFromJSON,
group: "07_integrations"
}
},
locale: {
type: String,
optional: true,
publish: true,
insertableIf: canEdit,
editableIf: canEdit,
form: {
disabled: isInSettingsJSON,
prefill: getFromJSON,
group: "01_general"
}
}
});
Telescope.settings.collection.attachSchema(Telescope.settings.schema);
Telescope.subscriptions.preload("settings");