-
Notifications
You must be signed in to change notification settings - Fork 2
Rename 'fields' to 'projection' #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -3,7 +3,7 @@ let allowDirectIdSelectors = false; | |||||
|
||||||
// Publish admin and group for users that have it | ||||||
Meteor.publish(null, function () { | ||||||
return this.userId && Meteor.users._partitionerDirect.find(this.userId, {fields: {admin: 1, group: 1}}); | ||||||
return this.userId && Meteor.users._partitionerDirect.find(this.userId, {projection: {admin: 1, group: 1}}); | ||||||
}); | ||||||
|
||||||
// Special hook for Meteor.users to scope for each group | ||||||
|
@@ -21,7 +21,7 @@ function userFindHook(userId, selector /*, options*/) { | |||||
if (!userId && !groupId) return true; | ||||||
|
||||||
if (!groupId) { | ||||||
const user = Meteor.users._partitionerDirect.findOne(userId, {fields: {group: 1}}); | ||||||
const user = Meteor.users._partitionerDirect.findOne(userId, {projection: {group: 1}}); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
// user will be undefined inside reactive publish when user is deleted while subscribed | ||||||
if (!user) return false; | ||||||
|
@@ -30,7 +30,7 @@ function userFindHook(userId, selector /*, options*/) { | |||||
|
||||||
// If user is admin and not in a group, proceed as normal (select all users) | ||||||
// do user2 findOne separately so that the findOne above can hit the cache | ||||||
if (!groupId && Meteor.users._partitionerDirect.findOne(userId, {fields: {admin: 1}}).admin) return true; | ||||||
if (!groupId && Meteor.users._partitionerDirect.findOne(userId, {projection: {admin: 1}}).admin) return true; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
// Normal users need to be in a group | ||||||
if (!groupId) throw new Meteor.Error(403, ErrMsg.groupErr); | ||||||
|
@@ -100,11 +100,11 @@ function findHook(userId, selector, options) { | |||||
|
||||||
// Adjust options to not return _groupId | ||||||
if (options == null) { | ||||||
this.args[1] = {fields: {_groupId: 0}}; | ||||||
this.args[1] = {projection: {_groupId: 0}}; | ||||||
} else { | ||||||
// If options already exist, add {_groupId: 0} unless fields has {foo: 1} somewhere | ||||||
if (options.fields == null) options.fields = {}; | ||||||
if (!Object.values(options.fields).some(v => v)) options.fields._groupId = 0; | ||||||
// If options already exist, add {_groupId: 0} unless projection has {foo: 1} somewhere | ||||||
if (options.projection == null) options.projection = {}; | ||||||
if (!Object.values(options.projection).some(v => v)) options.projection._groupId = 0; | ||||||
Comment on lines
+105
to
+107
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this whole block could be: // Adjust options to not return _groupId
// Pre Meteor 2.16 we will get options?.fields, post Meteor 2.16 we might get either.
let projectionField = options?.fields ? 'fields' : 'projection';
if (options == null) {
this.args[1] = {[defaultProjectionField]: {_groupId: 0}};
} else if (!options[projectionField]) {
options[defaultProjectionField] = {_groupId: 0};
} else if (!Object.values(options[projectionField]).some(v => v)) {
// If projection/fields already exist, add {_groupId: 0} unless it already has {foo: 1} somewhere
options[projectionField]._groupId = 0;
} |
||||||
} | ||||||
|
||||||
return true; | ||||||
|
@@ -178,7 +178,7 @@ Partitioner = { | |||||
check(userId, String); | ||||||
check(groupId, String); | ||||||
|
||||||
if (Meteor.users._partitionerDirect.findOne(userId, {fields: {group: 1}}).group) { | ||||||
if (Meteor.users._partitionerDirect.findOne(userId, {projection: {group: 1}}).group) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
throw new Meteor.Error(403, "User is already in a group"); | ||||||
} | ||||||
|
||||||
|
@@ -187,7 +187,7 @@ Partitioner = { | |||||
|
||||||
getUserGroup(userId) { | ||||||
check(userId, String); | ||||||
return (Meteor.users._partitionerDirect.findOne(userId, {fields: {group: 1}}) || {}).group; | ||||||
return (Meteor.users._partitionerDirect.findOne(userId, {projection: {group: 1}}) || {}).group; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
}, | ||||||
|
||||||
clearUserGroup(userId) { | ||||||
|
@@ -227,15 +227,15 @@ Partitioner = { | |||||
}, | ||||||
|
||||||
_isAdmin(_id) { | ||||||
return !!Meteor.users._partitionerDirect.findOne({_id, admin: true}, {fields: {_id: 1}}); | ||||||
return !!Meteor.users._partitionerDirect.findOne({_id, admin: true}, {projection: {_id: 1}}); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
}, | ||||||
|
||||||
addToGroup(collection, entityId, groupId) { | ||||||
if (!multipleGroupCollections[collection._name]) { | ||||||
throw new Meteor.Error(403, ErrMsg.multiGroupErr); | ||||||
} | ||||||
|
||||||
let currentGroupIds = collection._partitionerDirect.findOne(entityId, {fields: {_groupId: 1}})?._groupId; | ||||||
let currentGroupIds = collection._partitionerDirect.findOne(entityId, {projection: {_groupId: 1}})?._groupId; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
if (!currentGroupIds) { | ||||||
currentGroupIds = [groupId]; | ||||||
} else if (typeof currentGroupIds == 'string') { | ||||||
|
@@ -254,7 +254,7 @@ Partitioner = { | |||||
throw new Meteor.Error(403, ErrMsg.multiGroupErr); | ||||||
} | ||||||
|
||||||
let currentGroupIds = collection._partitionerDirect.findOne(entityId, {fields: {_groupId: 1}})?._groupId; | ||||||
let currentGroupIds = collection._partitionerDirect.findOne(entityId, {projection: {_groupId: 1}})?._groupId; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
if (!currentGroupIds) { | ||||||
return []; | ||||||
} | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the a reason you check for 2.16 instead of 2.6 here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, my mistake. I was testing this on a project on 2.16, so I had that number in my head when I wrote this. The test, when converted to floating point, should be
parseFloat(release) >= 2.06
.Well spotted, thanks.