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

Field access control #178

Open
pekarja5 opened this issue Aug 23, 2017 · 10 comments
Open

Field access control #178

pekarja5 opened this issue Aug 23, 2017 · 10 comments

Comments

@pekarja5
Copy link

Q A
Bug report? no
Feature request? maybe
BC Break report? no
RFC? no
Version/Branch x.y.z

I am trying to define field access control on my types, but I need to use the whole object for this decision, not only the value of protected field (which is accessible in expression by object).

Example:

Advert:
    type: object
    config:
        fields:
            id:
                type: Int
            userId:
                type: Int
            description:
                type: String
                access: "@= ???"

In my example I want to allow access to description property only for owner (based on userId) of the Advert object and to forbid it for all others. All other properties should remain accessible for all users.

Is this possible using Expression language with available variables? Or I have to create custom resolvers, where I can check against this condition, for all my fields?

@calvera
Copy link

calvera commented Aug 23, 2017

i use this

 User:
    type: object
    config:
        fields:
            id:
                type: "ID!"
                builder: "Relay::GlobalId"
                builderConfig:
                    typeName: User
            username:
                type: "String!"
                deprecationReason: "Using e-mail only"
            email:
                type: "String!"
            cards:
                type: "[Card]"
                resolve: "@=resolver('user_card_list', [value])"
                access: "@=value === user"

so you could use

access: "@=value.getOwner() === user"

@pekarja5
Copy link
Author

OK, so the value variable is also available in the access control, not only in the resolve context as said in docs?
Does that mean, that access is evaluated in the resolve context and all resolve variables are therefore accessible as well? If so, there should be some information about that in docs.

@mcg-web
Copy link
Member

mcg-web commented Aug 24, 2017

hi, in access mode you should use object and not value (even if value can be in some case accessible). Note that object is not accessible in mutation because mutation is executed only if access is true vs query that is execute before executing access...
Here the flow:

  • in query mode: execute resolver -> execute access -> manage result in function of access
  • in mutation mode: execute access -> execute resolver if access result is true

@mcg-web
Copy link
Member

mcg-web commented Aug 24, 2017

need some documentation I think this part is not enough clear...

@calvera
Copy link

calvera commented Aug 24, 2017

but object is value of the field, so you cannot check the access as I and @pekarja5 need it

@mcg-web
Copy link
Member

mcg-web commented Aug 24, 2017

@calvera that's right, my bad 👍

@pekarja5
Copy link
Author

@mcg-web So, what is the proposed solution for this? In which cases the value variable will be available to use?

@mcg-web
Copy link
Member

mcg-web commented Aug 24, 2017

the solution of @calvera is the best but not sure it will work for mutation operation... Maybe this is not your use case.

@pekarja5
Copy link
Author

OK, thx

@calvera
Copy link

calvera commented Aug 25, 2017

not sure it will work for mutation operation

i'm fine with this because mutation has no 'parent' entity

@mcg-web mcg-web added this to the v0.12 milestone Jan 27, 2018
@mcg-web mcg-web modified the milestones: v0.12, v0.13 May 26, 2019
@mcg-web mcg-web removed this from the v0.13 milestone Dec 7, 2019
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