mirror of
https://github.com/vale981/Vulcan
synced 2025-03-06 10:01:40 -05:00
Make upvoted/downvote posts/comments visible to current user only; do not use Accounts.createUser when seeding; small fixes
This commit is contained in:
parent
004945baeb
commit
2b33c05981
8 changed files with 81 additions and 92 deletions
|
@ -63,29 +63,24 @@ var createComment = function (username, body, picImageUrl) {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const createUser = function (username, email) {
|
||||||
|
const user = {
|
||||||
|
username,
|
||||||
|
email,
|
||||||
|
isDummy: true
|
||||||
|
};
|
||||||
|
newMutation({
|
||||||
|
collection: Users,
|
||||||
|
document: user,
|
||||||
|
validate: false
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
var createDummyUsers = function () {
|
var createDummyUsers = function () {
|
||||||
console.log('// creating dummy users');
|
console.log('// inserting dummy users…');
|
||||||
Accounts.createUser({
|
createUser('Bruce', 'dummyuser1@telescopeapp.org');
|
||||||
username: 'Bruce',
|
createUser('Arnold', 'dummyuser2@telescopeapp.org');
|
||||||
email: 'dummyuser1@telescopeapp.org',
|
createUser('Julia', 'dummyuser3@telescopeapp.org');
|
||||||
profile: {
|
|
||||||
isDummy: true
|
|
||||||
}
|
|
||||||
});
|
|
||||||
Accounts.createUser({
|
|
||||||
username: 'Arnold',
|
|
||||||
email: 'dummyuser2@telescopeapp.org',
|
|
||||||
profile: {
|
|
||||||
isDummy: true
|
|
||||||
}
|
|
||||||
});
|
|
||||||
Accounts.createUser({
|
|
||||||
username: 'Julia',
|
|
||||||
email: 'dummyuser3@telescopeapp.org',
|
|
||||||
profile: {
|
|
||||||
isDummy: true
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const createDummyPics = function () {
|
const createDummyPics = function () {
|
||||||
|
|
|
@ -55,29 +55,24 @@ const seedData = [
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
const createUser = function (username, email) {
|
||||||
|
const user = {
|
||||||
|
username,
|
||||||
|
email,
|
||||||
|
isDummy: true
|
||||||
|
};
|
||||||
|
newMutation({
|
||||||
|
collection: Users,
|
||||||
|
document: user,
|
||||||
|
validate: false
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
var createDummyUsers = function () {
|
var createDummyUsers = function () {
|
||||||
console.log('// creating dummy users');
|
console.log('// inserting dummy users…');
|
||||||
Accounts.createUser({
|
createUser('Bruce', 'dummyuser1@telescopeapp.org');
|
||||||
username: 'Bruce',
|
createUser('Arnold', 'dummyuser2@telescopeapp.org');
|
||||||
email: 'dummyuser1@telescopeapp.org',
|
createUser('Julia', 'dummyuser3@telescopeapp.org');
|
||||||
profile: {
|
|
||||||
isDummy: true
|
|
||||||
}
|
|
||||||
});
|
|
||||||
Accounts.createUser({
|
|
||||||
username: 'Arnold',
|
|
||||||
email: 'dummyuser2@telescopeapp.org',
|
|
||||||
profile: {
|
|
||||||
isDummy: true
|
|
||||||
}
|
|
||||||
});
|
|
||||||
Accounts.createUser({
|
|
||||||
username: 'Julia',
|
|
||||||
email: 'dummyuser3@telescopeapp.org',
|
|
||||||
profile: {
|
|
||||||
isDummy: true
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Meteor.startup(function () {
|
Meteor.startup(function () {
|
||||||
|
|
|
@ -623,7 +623,8 @@ export class AccountsLoginForm extends Tracker.Component {
|
||||||
Meteor.loginWithPassword(loginSelector, password, (error, result) => {
|
Meteor.loginWithPassword(loginSelector, password, (error, result) => {
|
||||||
onSubmitHook(error,formState);
|
onSubmitHook(error,formState);
|
||||||
if (error) {
|
if (error) {
|
||||||
this.showMessage(this.context.intl.formatMessage({id: `accounts.error_${error.reason}`}) || this.context.intl.formatMessage({id: 'accounts.error_unknown'}), 'error');
|
const errorId = `accounts.error_${error.reason.toLowerCase().replace(/ /g, '_')}`;
|
||||||
|
this.showMessage(this.context.intl.formatMessage({id: errorId}) || this.context.intl.formatMessage({id: 'accounts.error_unknown'}), 'error');
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
loginResultCallback(() => this.state.onSignedInHook());
|
loginResultCallback(() => this.state.onSignedInHook());
|
||||||
|
@ -685,8 +686,8 @@ export class AccountsLoginForm extends Tracker.Component {
|
||||||
if (error instanceof Accounts.LoginCancelledError) {
|
if (error instanceof Accounts.LoginCancelledError) {
|
||||||
// do nothing
|
// do nothing
|
||||||
} else {
|
} else {
|
||||||
console.warn(error.message || error)
|
const errorId = `accounts.error_${error.reason.toLowerCase().replace(/ /g, '_')}`;
|
||||||
this.showMessage((error.reason && this.context.intl.formatMessage({id: `accounts.error_${error.reason}`})) || this.context.intl.formatMessage({id: 'accounts.error_unknown'}))
|
this.showMessage((error.reason && this.context.intl.formatMessage({id: errorId})) || this.context.intl.formatMessage({id: 'accounts.error_unknown'}))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this.setState({ formState: STATES.PROFILE });
|
this.setState({ formState: STATES.PROFILE });
|
||||||
|
@ -747,7 +748,8 @@ export class AccountsLoginForm extends Tracker.Component {
|
||||||
const SignUp = function(_options) {
|
const SignUp = function(_options) {
|
||||||
Accounts.createUser(_options, (error) => {
|
Accounts.createUser(_options, (error) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
this.showMessage(this.context.intl.formatMessage({id: `accounts.error_${error.reason}`}) || this.context.intl.formatMessage({id: 'accounts.error_unknown'}), 'error');
|
const errorId = `accounts.error_${error.reason.toLowerCase().replace(/ /g, '_')}`;
|
||||||
|
this.showMessage(this.context.intl.formatMessage({id: errorId}) || this.context.intl.formatMessage({id: 'accounts.error_unknown'}), 'error');
|
||||||
if (this.context.intl.formatMessaget({id: `error.accounts_${error.reason}`})) {
|
if (this.context.intl.formatMessaget({id: `error.accounts_${error.reason}`})) {
|
||||||
onSubmitHook(`error.accounts.${error.reason}`, formState);
|
onSubmitHook(`error.accounts.${error.reason}`, formState);
|
||||||
}
|
}
|
||||||
|
@ -798,7 +800,8 @@ export class AccountsLoginForm extends Tracker.Component {
|
||||||
|
|
||||||
Accounts.forgotPassword({ email: email }, (error) => {
|
Accounts.forgotPassword({ email: email }, (error) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
this.showMessage(this.context.intl.formatMessage({id: `accounts_error_${error.reason}`}) || this.context.intl.formatMessage({id: 'accounts.error_unknown'}), 'error');
|
const errorId = `accounts.error_${error.reason.toLowerCase().replace(/ /g, '_')}`;
|
||||||
|
this.showMessage(this.context.intl.formatMessage({id: errorId}) || this.context.intl.formatMessage({id: 'accounts.error_unknown'}), 'error');
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.showMessage(this.context.intl.formatMessage({id: 'accounts.info_email_sent'}), 'success', 5000);
|
this.showMessage(this.context.intl.formatMessage({id: 'accounts.info_email_sent'}), 'success', 5000);
|
||||||
|
@ -831,7 +834,8 @@ export class AccountsLoginForm extends Tracker.Component {
|
||||||
if (token) {
|
if (token) {
|
||||||
Accounts.resetPassword(token, newPassword, (error) => {
|
Accounts.resetPassword(token, newPassword, (error) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
this.showMessage(this.context.intl.formatMessage({id: `accounts.error_${error.reason}`}) || this.context.intl.formatMessage({id: 'accounts.error_unknown'}), 'error');
|
const errorId = `accounts.error_${error.reason.toLowerCase().replace(/ /g, '_')}`;
|
||||||
|
this.showMessage(this.context.intl.formatMessage({id: errorId}) || this.context.intl.formatMessage({id: 'accounts.error_unknown'}), 'error');
|
||||||
onSubmitHook(error, formState);
|
onSubmitHook(error, formState);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -847,7 +851,8 @@ export class AccountsLoginForm extends Tracker.Component {
|
||||||
else {
|
else {
|
||||||
Accounts.changePassword(password, newPassword, (error) => {
|
Accounts.changePassword(password, newPassword, (error) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
this.showMessage(this.context.intl.formatMessage({id: `accounts.error_${error.reason}`}) || this.context.intl.formatMessage({id: 'accounts.error_unknown'}), 'error');
|
const errorId = `accounts.error_${error.reason.toLowerCase().replace(/ /g, '_')}`;
|
||||||
|
this.showMessage(this.context.intl.formatMessage({id: errorId}) || this.context.intl.formatMessage({id: 'accounts.error_unknown'}), 'error');
|
||||||
onSubmitHook(error, formState);
|
onSubmitHook(error, formState);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -860,8 +865,7 @@ export class AccountsLoginForm extends Tracker.Component {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
showMessage(messageId, type, clearTimeout, field){
|
showMessage(message, type, clearTimeout, field){
|
||||||
const message = this.context.intl.formatMessage({id: messageId});
|
|
||||||
if (message) {
|
if (message) {
|
||||||
this.setState(({ messages = [] }) => {
|
this.setState(({ messages = [] }) => {
|
||||||
messages.push({
|
messages.push({
|
||||||
|
|
|
@ -42,11 +42,6 @@ registerFragment(`
|
||||||
postCount
|
postCount
|
||||||
# vulcan:comments
|
# vulcan:comments
|
||||||
commentCount
|
commentCount
|
||||||
# vulcan:newsletter
|
|
||||||
newsletter_subscribeToNewsletter
|
|
||||||
# vulcan:notifications
|
|
||||||
notifications_users
|
|
||||||
notifications_posts
|
|
||||||
# vulcan:voting
|
# vulcan:voting
|
||||||
downvotedComments {
|
downvotedComments {
|
||||||
...VotedItem
|
...VotedItem
|
||||||
|
|
|
@ -78,29 +78,24 @@ var createComment = function (slug, username, body, parentBody) {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const createUser = function (username, email) {
|
||||||
|
const user = {
|
||||||
|
username,
|
||||||
|
email,
|
||||||
|
isDummy: true
|
||||||
|
};
|
||||||
|
newMutation({
|
||||||
|
collection: Users,
|
||||||
|
document: user,
|
||||||
|
validate: false
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
var createDummyUsers = function () {
|
var createDummyUsers = function () {
|
||||||
console.log('// inserting dummy users…');
|
console.log('// inserting dummy users…');
|
||||||
Accounts.createUser({
|
createUser('Bruce', 'dummyuser1@telescopeapp.org');
|
||||||
username: 'Bruce',
|
createUser('Arnold', 'dummyuser2@telescopeapp.org');
|
||||||
email: 'dummyuser1@telescopeapp.org',
|
createUser('Julia', 'dummyuser3@telescopeapp.org');
|
||||||
profile: {
|
|
||||||
isDummy: true
|
|
||||||
}
|
|
||||||
});
|
|
||||||
Accounts.createUser({
|
|
||||||
username: 'Arnold',
|
|
||||||
email: 'dummyuser2@telescopeapp.org',
|
|
||||||
profile: {
|
|
||||||
isDummy: true
|
|
||||||
}
|
|
||||||
});
|
|
||||||
Accounts.createUser({
|
|
||||||
username: 'Julia',
|
|
||||||
email: 'dummyuser3@telescopeapp.org',
|
|
||||||
profile: {
|
|
||||||
isDummy: true
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
var createDummyPosts = function () {
|
var createDummyPosts = function () {
|
||||||
|
|
|
@ -8,6 +8,7 @@ addStrings('en', {
|
||||||
"accounts.error_username_required": "Username required",
|
"accounts.error_username_required": "Username required",
|
||||||
"accounts.error_accounts_": "",
|
"accounts.error_accounts_": "",
|
||||||
"accounts.error_unknown": "Unknown error",
|
"accounts.error_unknown": "Unknown error",
|
||||||
|
"accounts.error_user_not_found": "User not found",
|
||||||
"accounts.enter_username_or_email": "Enter username or email",
|
"accounts.enter_username_or_email": "Enter username or email",
|
||||||
"accounts.username_or_email": "Username or email",
|
"accounts.username_or_email": "Username or email",
|
||||||
"accounts.enter_username": "Enter username",
|
"accounts.enter_username": "Enter username",
|
||||||
|
|
|
@ -25,6 +25,7 @@ const schema = {
|
||||||
type: String,
|
type: String,
|
||||||
optional: true,
|
optional: true,
|
||||||
viewableBy: ['guests'],
|
viewableBy: ['guests'],
|
||||||
|
insertableBy: ['guests'],
|
||||||
},
|
},
|
||||||
emails: {
|
emails: {
|
||||||
type: Array,
|
type: Array,
|
||||||
|
@ -47,6 +48,9 @@ const schema = {
|
||||||
type: Date,
|
type: Date,
|
||||||
optional: true,
|
optional: true,
|
||||||
viewableBy: ['guests'],
|
viewableBy: ['guests'],
|
||||||
|
onInsert: () => {
|
||||||
|
return new Date();
|
||||||
|
}
|
||||||
},
|
},
|
||||||
isAdmin: {
|
isAdmin: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
|
@ -59,8 +63,8 @@ const schema = {
|
||||||
group: adminGroup,
|
group: adminGroup,
|
||||||
onInsert: user => {
|
onInsert: user => {
|
||||||
// if this is not a dummy account, and is the first user ever, make them an admin
|
// if this is not a dummy account, and is the first user ever, make them an admin
|
||||||
const realUsersCount = Users.find({'profile.isDummy': {$ne: true}}).count();
|
const realUsersCount = Users.find({'isDummy': {$ne: true}}).count();
|
||||||
return (!user.profile.isDummy && realUsersCount === 0) ? true : false;
|
return (!user.isDummy && realUsersCount === 0) ? true : false;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
profile: {
|
profile: {
|
||||||
|
@ -102,9 +106,11 @@ const schema = {
|
||||||
editableBy: ['members'],
|
editableBy: ['members'],
|
||||||
viewableBy: ['guests'],
|
viewableBy: ['guests'],
|
||||||
onInsert: (user, options) => {
|
onInsert: (user, options) => {
|
||||||
if (user.profile.username) {
|
if (user.username) {
|
||||||
|
return user.username;
|
||||||
|
} else if (user.profile && user.profile.username) {
|
||||||
return user.profile.username;
|
return user.profile.username;
|
||||||
} else if (user.profile.name) {
|
} else if (user.profile && user.profile.name) {
|
||||||
return user.profile.name;
|
return user.profile.name;
|
||||||
} else if (user.services.linkedin && user.services.linkedin.firstName) {
|
} else if (user.services.linkedin && user.services.linkedin.firstName) {
|
||||||
return user.services.linkedin.firstName + " " + user.services.linkedin.lastName;
|
return user.services.linkedin.firstName + " " + user.services.linkedin.lastName;
|
||||||
|
@ -122,14 +128,12 @@ const schema = {
|
||||||
regEx: SimpleSchema.RegEx.Email,
|
regEx: SimpleSchema.RegEx.Email,
|
||||||
required: true,
|
required: true,
|
||||||
control: "text",
|
control: "text",
|
||||||
insertableBy: ['members'],
|
insertableBy: ['guests'],
|
||||||
editableBy: ['members'],
|
editableBy: ['members'],
|
||||||
viewableBy: ownsOrIsAdmin,
|
viewableBy: ownsOrIsAdmin,
|
||||||
onInsert: (user, options) => {
|
onInsert: (user) => {
|
||||||
// look in a few places for the user email
|
// look in a few places for the user email
|
||||||
if (options.email) {
|
if (user.services['meteor-developer'] && user.services['meteor-developer'].emails) {
|
||||||
return options.email;
|
|
||||||
} else if (user.services['meteor-developer'] && user.services['meteor-developer'].emails) {
|
|
||||||
return _.findWhere(user.services['meteor-developer'].emails, { primary: true }).address;
|
return _.findWhere(user.services['meteor-developer'].emails, { primary: true }).address;
|
||||||
} else if (user.services.facebook && user.services.facebook.email) {
|
} else if (user.services.facebook && user.services.facebook.email) {
|
||||||
return user.services.facebook.email;
|
return user.services.facebook.email;
|
||||||
|
|
|
@ -31,7 +31,7 @@ Users.addField([
|
||||||
fieldSchema: {
|
fieldSchema: {
|
||||||
type: Array,
|
type: Array,
|
||||||
optional: true,
|
optional: true,
|
||||||
viewableBy: ['guests'],
|
viewableBy: Users.owns,
|
||||||
resolveAs: 'upvotedComments: [Vote]',
|
resolveAs: 'upvotedComments: [Vote]',
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -50,7 +50,7 @@ Users.addField([
|
||||||
fieldSchema: {
|
fieldSchema: {
|
||||||
type: Array,
|
type: Array,
|
||||||
optional: true,
|
optional: true,
|
||||||
viewableBy: ['guests'],
|
viewableBy: Users.owns,
|
||||||
resolveAs: 'upvotedPosts: [Vote]',
|
resolveAs: 'upvotedPosts: [Vote]',
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -69,7 +69,7 @@ Users.addField([
|
||||||
fieldSchema: {
|
fieldSchema: {
|
||||||
type: Array,
|
type: Array,
|
||||||
optional: true,
|
optional: true,
|
||||||
viewableBy: ['guests'],
|
viewableBy: Users.owns,
|
||||||
resolveAs: 'downvotedComments: [Vote]',
|
resolveAs: 'downvotedComments: [Vote]',
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -88,7 +88,7 @@ Users.addField([
|
||||||
fieldSchema: {
|
fieldSchema: {
|
||||||
type: Array,
|
type: Array,
|
||||||
optional: true,
|
optional: true,
|
||||||
viewableBy: ['guests'],
|
viewableBy: Users.owns,
|
||||||
resolveAs: 'downvotedPosts: [Vote]',
|
resolveAs: 'downvotedPosts: [Vote]',
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
Loading…
Add table
Reference in a new issue