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

Doesn't seem to work in allow/deny rules #19

Open
ndarilek opened this issue Mar 19, 2016 · 6 comments
Open

Doesn't seem to work in allow/deny rules #19

ndarilek opened this issue Mar 19, 2016 · 6 comments

Comments

@ndarilek
Copy link
Contributor

Normally I use methods for RPC, but I'm using CollectionFS which uses the insert/update/remove methods directly. I tried something like:

Books.allow
  insert: ->
    console.log(@connection)
    if @connection?.sandstormUser()?.permissions.indexOf("modify") != -1
      true
    else
      false
  update: ->
    if @connection?.sandstormUser()?.permissions.indexOf("modify") != -1
      true
    else
      false
  remove: ->
    if @connection?.sandstormUser()?.permissions.indexOf("modify") != -1
      true
    else
      false

but unfortunately this.connection doesn't appear to exist in this context.

@kentonv
Copy link
Member

kentonv commented Mar 19, 2016

Hmm, I suspect you can do DDP._CurrentInvocation.get().connection, but that is of course using a Meteor private API. Maybe we should add a Meteor.sandstormUser() server-side that calls this?

FWIW I highly recommend defining explicit methods to do mutations rather than allow/deny rules. With methods it's much easier to reason about whether the call fits the expected pattern, whether the parameter types are correct, etc. But we shouldn't be imposing that style in meteor-accounts-sandstorm.

@ndarilek
Copy link
Contributor Author

ndarilek commented Mar 19, 2016 via email

@simonv3
Copy link
Contributor

simonv3 commented Mar 23, 2016

Just wanted to pipe up that I was running into this as well and left scratching my head a bit until I came here. I'll look at the workaround.

(This is for annotate, so I'm also working with CollectionFS, though I saw @ndarilek comment somewhere that it's now depricated, sooooo)

@ndarilek
Copy link
Contributor Author

ndarilek commented Mar 23, 2016 via email

@kentonv
Copy link
Member

kentonv commented Mar 23, 2016

If DDP._CurrentInvocation.get() doesn't work (and there's no other way to get at the connection) then I think we're out of luck. I don't know of anywhere else where we can stash the permissions. You'll need to rely on the user being logged in I guess?

@simonv3
Copy link
Contributor

simonv3 commented Mar 23, 2016

DDP._CurrentInvocation.get() seemed to work fine for me in permissions, but somehow adding this package broke file uploading on CollectionFS in general. (linked to above). I'll have to investigate more later.

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

No branches or pull requests

3 participants