mirror of
https://github.com/vale981/Vulcan
synced 2025-03-06 10:01:40 -05:00
fixing get/set user setting
This commit is contained in:
parent
1dea1083ba
commit
c268d142cb
12 changed files with 61 additions and 55 deletions
|
@ -79,7 +79,6 @@ mobile-status-bar@1.0.3
|
||||||
momentjs:moment@2.10.3
|
momentjs:moment@2.10.3
|
||||||
mongo@1.1.0
|
mongo@1.1.0
|
||||||
mongo-livedata@1.0.8
|
mongo-livedata@1.0.8
|
||||||
mrt:cookies@0.3.0
|
|
||||||
npm-bcrypt@0.7.8_2
|
npm-bcrypt@0.7.8_2
|
||||||
oauth@1.1.4
|
oauth@1.1.4
|
||||||
oauth1@1.1.4
|
oauth1@1.1.4
|
||||||
|
|
|
@ -9,6 +9,8 @@ Just a couple minor bug fixes.
|
||||||
* Fixed video lightbox issue.
|
* Fixed video lightbox issue.
|
||||||
* Updated Getting Started content.
|
* Updated Getting Started content.
|
||||||
* Enforcing better URL formatting for Site URL setting.
|
* Enforcing better URL formatting for Site URL setting.
|
||||||
|
* Fixed notification settings.
|
||||||
|
* Reworked user settings.
|
||||||
|
|
||||||
## v0.20.4 “RefactorScope”
|
## v0.20.4 “RefactorScope”
|
||||||
|
|
||||||
|
|
|
@ -95,7 +95,7 @@ function adminUserCreationNotification (user) {
|
||||||
// send notifications to admins
|
// send notifications to admins
|
||||||
var admins = Users.adminUsers();
|
var admins = Users.adminUsers();
|
||||||
admins.forEach(function(admin){
|
admins.forEach(function(admin){
|
||||||
if (Users.getSetting(admin, "telescope.notifications.users", false)) {
|
if (Users.getSetting(admin, "notifications.users", false)) {
|
||||||
var emailProperties = {
|
var emailProperties = {
|
||||||
profileUrl: Users.getProfileUrl(user),
|
profileUrl: Users.getProfileUrl(user),
|
||||||
username: Users.getUserName(user)
|
username: Users.getUserName(user)
|
||||||
|
|
|
@ -125,7 +125,7 @@
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td class="footer-container">
|
<td class="footer-container">
|
||||||
<!-- <a href="{{accountLink}}">Change your notifications settings</a><br/><br/> -->
|
<a href="{{accountLink}}">Change your notifications settings</a><br/><br/>
|
||||||
{{{footer}}}
|
{{{footer}}}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
|
@ -49,7 +49,8 @@ Package.onUse(function (api) {
|
||||||
'dburles:collection-helpers@1.0.3',
|
'dburles:collection-helpers@1.0.3',
|
||||||
'jparker:gravatar@0.3.1',
|
'jparker:gravatar@0.3.1',
|
||||||
'sanjo:meteor-files-helpers@1.1.0_4',
|
'sanjo:meteor-files-helpers@1.1.0_4',
|
||||||
'cmather:handlebars-server@0.2.0'
|
'cmather:handlebars-server@0.2.0',
|
||||||
|
'chuangbo:cookie@1.1.0'
|
||||||
];
|
];
|
||||||
|
|
||||||
api.use(packages);
|
api.use(packages);
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
{{#if isNotConnected}}
|
{{#if isNotConnected}}
|
||||||
<input class="newsletter-email" type="email" placeholder="Your Email">
|
<input class="newsletter-email" type="email" placeholder="Your Email">
|
||||||
{{/if}}
|
{{/if}}
|
||||||
<button class="button newsletter-button btn btn-primary">{{_ "get_newsletter"}}<span class="button-loader"><img src="/img/loading-balls.svg"/></span></button>
|
<button class="button newsletter-button btn btn-primary">{{_ "get_newsletter"}}<span class="button-loader"><img src="/packages/telescope_core/public/img/loading-balls.svg"/></span></button>
|
||||||
</form>
|
</form>
|
||||||
<h4 class="newsletter-subscribed">{{_ "thanks_for_subscribing"}}</h4>
|
<h4 class="newsletter-subscribed">{{_ "thanks_for_subscribing"}}</h4>
|
||||||
<a href="#" class="newsletter-dismiss banner-dismiss">×</a>
|
<a href="#" class="newsletter-dismiss banner-dismiss">×</a>
|
||||||
|
|
|
@ -11,7 +11,7 @@ var dismissBanner = function () {
|
||||||
$('.newsletter-banner').fadeOut('fast', function () {
|
$('.newsletter-banner').fadeOut('fast', function () {
|
||||||
if(Meteor.user()){
|
if(Meteor.user()){
|
||||||
// if user is connected, change setting in their account
|
// if user is connected, change setting in their account
|
||||||
Users.setUserSetting('showBanner', false);
|
Users.setSetting(Meteor.user(), 'newsletter.showBanner', false);
|
||||||
}else{
|
}else{
|
||||||
// set cookie
|
// set cookie
|
||||||
Cookie.set('showBanner', "no");
|
Cookie.set('showBanner', "no");
|
||||||
|
@ -34,8 +34,8 @@ Meteor.startup(function () {
|
||||||
|| !Users.can.view(Meteor.user())
|
|| !Users.can.view(Meteor.user())
|
||||||
|| Router.current().location.get().path !== '/'
|
|| Router.current().location.get().path !== '/'
|
||||||
|| Cookie.get('showBanner') === "no"
|
|| Cookie.get('showBanner') === "no"
|
||||||
|| (Meteor.user() && Meteor.user().getSetting('telescope.newsletter.showBanner', true) === false)
|
|| (Meteor.user() && Meteor.user().getSetting('newsletter.showBanner', true) === false)
|
||||||
|| (Meteor.user() && Meteor.user().getSetting('telescope.newsletter.subscribeToNewsletter', false) === true)
|
|| (Meteor.user() && Meteor.user().getSetting('newsletter.subscribeToNewsletter', false) === true)
|
||||||
){
|
){
|
||||||
return false;
|
return false;
|
||||||
}else{
|
}else{
|
||||||
|
|
|
@ -114,7 +114,7 @@ addToMailChimpList = function(userOrEmail, confirm, done){
|
||||||
|
|
||||||
// mark user as subscribed
|
// mark user as subscribed
|
||||||
if(!!user)
|
if(!!user)
|
||||||
Users.setUserSetting('subscribedToNewsletter', true, user);
|
Users.setSetting(user, 'newsletter.subscribeToNewsletter', true);
|
||||||
|
|
||||||
console.log("// User subscribed");
|
console.log("// User subscribed");
|
||||||
|
|
||||||
|
|
|
@ -16,20 +16,7 @@ Package.onUse(function (api) {
|
||||||
api.use([
|
api.use([
|
||||||
'telescope:core@0.20.5',
|
'telescope:core@0.20.5',
|
||||||
'miro:mailchimp@1.0.4',
|
'miro:mailchimp@1.0.4',
|
||||||
], ['client', 'server']);
|
]);
|
||||||
|
|
||||||
api.use([
|
|
||||||
'jquery',
|
|
||||||
'underscore',
|
|
||||||
'templating',
|
|
||||||
'telescope:messages@0.1.0',
|
|
||||||
'mrt:cookies@0.3.0'
|
|
||||||
], 'client');
|
|
||||||
|
|
||||||
api.use([
|
|
||||||
'percolatestudio:synced-cron@1.1.0',
|
|
||||||
'cmather:handlebars-server@0.2.0'
|
|
||||||
], ['server']);
|
|
||||||
|
|
||||||
api.addFiles([
|
api.addFiles([
|
||||||
'package-tap.i18n',
|
'package-tap.i18n',
|
||||||
|
|
|
@ -41,7 +41,7 @@ function addCommentNotification (comment) {
|
||||||
|
|
||||||
// 1. Notify author of post (if they have new comment notifications turned on)
|
// 1. Notify author of post (if they have new comment notifications turned on)
|
||||||
// but do not notify author of post if they're the ones posting the comment
|
// but do not notify author of post if they're the ones posting the comment
|
||||||
if (Users.getSetting(postAuthor, "telescope.notifications.comments", true) && comment.userId !== postAuthor._id) {
|
if (Users.getSetting(postAuthor, "notifications.comments", true) && comment.userId !== postAuthor._id) {
|
||||||
Herald.createNotification(post.userId, {courier: 'newComment', data: notificationData});
|
Herald.createNotification(post.userId, {courier: 'newComment', data: notificationData});
|
||||||
userIdsNotified.push(post.userId);
|
userIdsNotified.push(post.userId);
|
||||||
}
|
}
|
||||||
|
@ -58,7 +58,7 @@ function addCommentNotification (comment) {
|
||||||
var parentCommentAuthor = Users.findOne(parentComment.userId);
|
var parentCommentAuthor = Users.findOne(parentComment.userId);
|
||||||
|
|
||||||
// do not notify parent comment author if they have reply notifications turned off
|
// do not notify parent comment author if they have reply notifications turned off
|
||||||
if (Users.getSetting(parentCommentAuthor, "telescope.notifications.replies", true)) {
|
if (Users.getSetting(parentCommentAuthor, "notifications.replies", true)) {
|
||||||
|
|
||||||
// add parent comment to notification data
|
// add parent comment to notification data
|
||||||
notificationData.parentComment = _.pick(parentComment, '_id', 'userId', 'author');
|
notificationData.parentComment = _.pick(parentComment, '_id', 'userId', 'author');
|
||||||
|
|
|
@ -8,4 +8,6 @@ Just a couple minor bug fixes.
|
||||||
* Generate public user properties list from schema.
|
* Generate public user properties list from schema.
|
||||||
* Fixed video lightbox issue.
|
* Fixed video lightbox issue.
|
||||||
* Updated Getting Started content.
|
* Updated Getting Started content.
|
||||||
* Enforcing better URL formatting for Site URL setting.
|
* Enforcing better URL formatting for Site URL setting.
|
||||||
|
* Fixed notification settings.
|
||||||
|
* Reworked user settings.
|
|
@ -133,14 +133,55 @@ Users.userProfileCompleteById = function (userId) {return Users.userProfileCompl
|
||||||
Users.getSetting = function (user, settingName, defaultValue) {
|
Users.getSetting = function (user, settingName, defaultValue) {
|
||||||
user = user || Meteor.user();
|
user = user || Meteor.user();
|
||||||
defaultValue = defaultValue || null;
|
defaultValue = defaultValue || null;
|
||||||
if (user.telescope && user.telescope.settings) {
|
|
||||||
var settingValue = this.getProperty(user.telescope.settings, settingName);
|
// all settings should be in the user.telescope namespace, so add "telescope." if needed
|
||||||
|
settingName = settingName.slice(0,10) === "telescope." ? settingName : "telescope." + settingName;
|
||||||
|
|
||||||
|
if (user.telescope) {
|
||||||
|
var settingValue = this.getProperty(user, settingName);
|
||||||
return (settingValue === null) ? defaultValue : settingValue;
|
return (settingValue === null) ? defaultValue : settingValue;
|
||||||
} else {
|
} else {
|
||||||
return defaultValue;
|
return defaultValue;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
Users.helpers({getSetting: function () {return Users.getSetting(this);}});
|
Users.helpers({getSetting: function (settingName, defaultValue) {return Users.getSetting(this, settingName, defaultValue);}});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set a user setting
|
||||||
|
* @param {Object} user
|
||||||
|
* @param {String} settingName
|
||||||
|
* @param {Object} defaultValue
|
||||||
|
*/
|
||||||
|
Users.setSetting = function (userArgument, settingName, value) {
|
||||||
|
// note: for some very weird reason, doesn't work when called from Accounts.onCreateUser
|
||||||
|
|
||||||
|
var user;
|
||||||
|
|
||||||
|
if(Meteor.isClient){
|
||||||
|
user = (typeof userArgument === "undefined") ? Meteor.user() : userArgument; // on client, default to current user
|
||||||
|
}else if (Meteor.isServer){
|
||||||
|
user = userArgument; // on server, use argument
|
||||||
|
}
|
||||||
|
if(!user)
|
||||||
|
throw new Meteor.Error(500, 'User not defined');
|
||||||
|
|
||||||
|
Meteor.call('setUserSetting', settingName, value, user);
|
||||||
|
};
|
||||||
|
Users.helpers({setSetting: function () {return Users.setSetting(this);}});
|
||||||
|
|
||||||
|
|
||||||
|
Meteor.methods({
|
||||||
|
setUserSetting: function (settingName, value, user) {
|
||||||
|
console.log('Setting user setting "' + settingName + '" to "' + value + '" for ' + Users.getUserName(user));
|
||||||
|
|
||||||
|
// all settings should be in the user.telescope namespace, so add "telescope." if needed
|
||||||
|
var field = settingName.slice(0,10) === "telescope." ? settingName : "telescope." + settingName;
|
||||||
|
|
||||||
|
var modifier = {$set: {}};
|
||||||
|
modifier.$set[field] = value;
|
||||||
|
Meteor.users.update(user._id, modifier);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
///////////////////
|
///////////////////
|
||||||
// Other Helpers //
|
// Other Helpers //
|
||||||
|
@ -169,32 +210,6 @@ Users.numberOfItemsInPast24Hours = function (user, collection) {
|
||||||
return items.count();
|
return items.count();
|
||||||
};
|
};
|
||||||
|
|
||||||
Users.setUserSetting = function (settingName, value, userArgument) {
|
|
||||||
// note: for some very weird reason, doesn't work when called from Accounts.onCreateUser
|
|
||||||
|
|
||||||
var user;
|
|
||||||
|
|
||||||
if(Meteor.isClient){
|
|
||||||
user = (typeof userArgument === "undefined") ? Meteor.user() : userArgument; // on client, default to current user
|
|
||||||
}else if (Meteor.isServer){
|
|
||||||
user = userArgument; // on server, use argument
|
|
||||||
}
|
|
||||||
if(!user)
|
|
||||||
throw new Meteor.Error(500, 'User not defined');
|
|
||||||
|
|
||||||
Meteor.call('setUserSetting', settingName, value, user);
|
|
||||||
};
|
|
||||||
|
|
||||||
Meteor.methods({
|
|
||||||
setUserSetting: function (settingName, value, user) {
|
|
||||||
// console.log('Setting user setting "' + setting + '" to "' + value + '" for ' + Users.getUserName(user));
|
|
||||||
var field = 'telescope.settings.'+settingName;
|
|
||||||
var modifier = {$set: {}};
|
|
||||||
modifier.$set[field] = value;
|
|
||||||
Meteor.users.update(user._id, modifier);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
Users.getProperty = function (object, property) {
|
Users.getProperty = function (object, property) {
|
||||||
// recursive function to get nested properties
|
// recursive function to get nested properties
|
||||||
var array = property.split('.');
|
var array = property.split('.');
|
||||||
|
|
Loading…
Add table
Reference in a new issue