Skip to content
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

PUT /apis Error: Meteor.userId can only be invoked in method calls or publications #3151

Closed
matleppa opened this issue Nov 24, 2017 · 8 comments
Assignees

Comments

@matleppa
Copy link
Member

matleppa commented Nov 24, 2017

Description

Method PUT fails

Environment

Postman testing
Catalog API, method PUT

Result in localhost

Note! Replaced previous erroneous (unrelated, copy-paste error by me) errors with correct one

Error: Meteor.userId can only be invoked in method calls or publications.
at AccountsServer.userId (packages/accounts-base/accounts_server.js:79:13)
at Object.Meteor.userId (packages/accounts-base/accounts_common.js:263:19)
at Object.Apis.schema.SimpleSchema.updated_by.autoValue (apinf_packages/apis/collection/schema.js:104:27)
at Object.runAV (packages\aldeed_simple-schema.js:1282:26)
at packages\aldeed_simple-schema.js:1383:13
at Array.forEach (native)
at Function..each..forEach (packages\underscore.js:139:11)
at packages\aldeed_simple-schema.js:1382:7
at Function..each..forEach (packages\underscore.js:147:22)
at [object Object].getAutoValues (packages\aldeed_simple-schema.js:1345:5)
at [object Object].SimpleSchema.clean (packages\aldeed_simple-schema.js:1763:42)
at doClean (packages\aldeed_collection2-core.js:350:12)
at [object Object].doValidate (packages\aldeed_collection2-core.js:372:3)
at [object Object].Mongo.Collection.(anonymous function) [as update] (packages\aldeed_collection2-core.js:214:25)
at Object.CatalogV1.addCollection.endpoints.put.action (apinf_packages/apis/server/api.js:668:14)
at Route.share.Route.Route._callEndpoint (packages/nimble_restivus/lib/route.coffee:149:25)
at packages/nimble_restivus/lib/route.coffee:59:33
at packages\simple_json-routes.js:98:9

Result in nightly

500 Internal Server Error

Testing with Swagger

TypeError: Failed to fetch
@matleppa matleppa changed the title Error: Meteor.userId can only be invoked in method calls or publications PUT /apis Error: Meteor.userId can only be invoked in method calls or publications Nov 24, 2017
@matleppa
Copy link
Member Author

Before PR #3093 the functionality was OK.

@marla-singer
Copy link
Contributor

@matleppa Attention please this issue #3139

@matleppa
Copy link
Member Author

matleppa commented Nov 27, 2017

@marla-singer Sorry, I had wrong error list here. So I think this is not related to #3139.

@marla-singer
Copy link
Contributor

@matleppa Can't agree with you. Based on error trace the 4 line shows the field with error
at Object.Apis.schema.SimpleSchema.updated_by.autoValue

My hypothesis is that it has started working incorrectly after PR #3099 and changing collection schema

updated_by: {
type: String,
optional: true,
autoValue () {
let updateBy;
if (this.isUpdate) {
updateBy = Meteor.userId();
}
return updateBy;
},
},

@matleppa
Copy link
Member Author

Yes, I agree with you.
I made a check by removing the #3093 functionality concerning PUT method, but the problem remained.

PR #3099 is clearly the culprit.

@marla-singer
Copy link
Contributor

marla-singer commented Nov 27, 2017

@matleppa Also please check if a filed "created_by" contains the correct value if API is added via REST API. I have feeling It will not work as expected

@matleppa
Copy link
Member Author

@marla-singer You are right, the created_by field is no updated, when an API card is created by Catalog API.

It seems, that at least following corrections should be made:

Catalog API

  • method POST /apis
    • add filling of user_id to field bodyParams.created_by
  • method PUT /apis/{}
    • add filling of user_id to field bodyParams.updated_by
    • also optimization
      • no need to update Apis, in case only given parameters were related to documentation

Apis schema

  • field updated_by
    • get return value for autovalue function either from filled value (that's why in Catalog API the bodyParams.updated_by is filled) or from Meteor.userId()

@matleppa matleppa self-assigned this Nov 28, 2017
@marla-singer
Copy link
Contributor

field updated_by
get return value for autovalue function either from filled value (that's why in Catalog API the bodyParams.updated_by is filled) or from Meteor.userId()

Please make the same thing for created_by field

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants