kitchen-site
kitchen-site copied to clipboard
No publish for collection users
When I wrote queries to the user collection (find the profile of all users), the kitchen did not create a publish function for them (I guess because you don't need to publish the current user, so it assumes no user publish necessary). I just added the publish myself afterward.
Hi @knathanieltucker
Meteor kitchen treats Users
collection specially. Publications are defined in perak:user-roles
package, and there is only 3 publications:
-
current_user_data
: no arguments, any user can subscribe and receives only own "profile" and "roles" fields. -
admin_user
: with argument user's_id
- only admin can subscribe and receives data from user with given _id -
admin_users
: no arguments, only admin can subscribe, and receives data from all users.
To use these publications, you need to name your query exactly current_user_data
, admin_user
or admin_users
. You can see all of this in example-admin
application supplied with meteor-kitchen.
To became (first) admin, you need to add string "admin" into user document's roles array:
Users.update({ _id: USER_ID }, { $set: { roles: ["admin"] }});
However, I know having only three publications for users is limitation, and maybe I'll enable generator to produce any publication for User collection.
Until then, there is workaround: you can create user_publications.js
file (or name it as you wish) in directory where is your .json input file (or in any subdirectory) and add it into copy_files
array like this:
"copy_files": [
{ "source": "PATH_RELATIVE_TO_INPUT_JSON/user_publications.js", "dest": "SERVER_PUBLISH_DIR/user_publications.js" }
]
SERVER_PUBLISH_DIR
is special alias that generator recognizes and will copy your file into destination directory to /server/publish/
subdirectory.
Now, you can publish anything from this file.
BTW, be careful with security - it's not good idea to expose all user's data to all users.
I hope this helps :)
Ah that clarifies it. I was checking out the example-admin
page and wondering how you were able to add the admin_user
and the admin_users
queries without manually adding in the publication.
Thanks a ton, this really clarifies it. Allowing the generator to do User publications would be nice. But certainly not P0 or P1. I'll go ahead and put the copy_files
attribute to my app. Maybe a word on this in the docs would help though.
Otherwise, awesome stuff. The kitchen is awesome!
(Currently I am using a publication that will expose the user profile to others, so not a huge security risk : )
Hi!
I have tried copy the content in the following to users_collection.js and placed in server_publish_dir as follows but meteor kitchen complained that I did not define the publication when I used the publication q_users in data_view component besides admin
please help as I need to use the users collection to display as contact directory where the users are synced to google g-suite.
thanks
data view components: - name: test type: data_view query_name: q_users query_params: []
content copied
- source_content: >-
Meteor.publish("q_users", function() {
return Users.find({}, {});
});
Meteor.publish("q_user", function(userId) {
return Users.find({_id:userId}, {});
});
Meteor.publish("q_users_null", function() {
return Users.find({_id:null}, {});
});
dest: SERVER_PUBLISH_DIR/users_collection.js
Hi!
It works with defining the query q_users as normal under meteor kitchen
and
copy the source as per above to users_collection.js in server publish folder
thanks
Hi @The-Edge-Malaysia
Sorry for too late answer, glad you solved the problem :+1: