-
Notifications
You must be signed in to change notification settings - Fork 19
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
[PD-10597] GraphQL Backend Restrictions #57
base: master
Are you sure you want to change the base?
Conversation
Task linked: PD-10597 GraphQL Backend Security Restrictions |
expect(data["createAdvisor"]["resource"]["nickname"]).to be_nil | ||
expect(data["createAdvisor"]["resource"]["optionalOrg"]).to be_nil | ||
expect(data["createAdvisor"]["errors"]["warning"]["advisor"].size).to eql 2 | ||
expect(Advisor.where(name: name).exists?).to eql true |
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.
why was the advisor created if the user had restrictions on those fields? Or was the advisor created but the fields that were restricted just were filled with nil ?
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.
the second description is the correct one, advisor will be created but with restricted attributes filtered. User will receive a warning about the attributes that were not saved because of role's restrictions
restriction = ctx[:current_user]&.restrictions&.detect do |el| | ||
(el.resource.name == name || el.resource.alias == name) && | ||
el.restriction_operation_id == "HasHelpers::RestrictionOperation::::View" && | ||
el.resource.resource_type_id != "HasHelpers::ResourceType::::RequiredField" |
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.
Why do we need to check RequiredField to view?
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.
required fields can't be restricted because this will cause a schema conflict. For example if attribute name is required, the schema assures that this attribute will always be returned as string. If it has a restriction, it will try to return null, causing a query fail for schema error
|
(el.resource.resource_type_id == "HasHelpers::ResourceType::::BaseResource" && | ||
restriction_operations.include?(el.restriction_operation_id)) | ||
end | ||
restrictions |
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.
Why are we using ruby here instead of sql? I would add specs then convert to SQL. Same comment applies to many of the functions in this file.
# restriction_operations is an array of ::HasHelpers::RestrictionOperation | ||
def get_base_restrictions(restriction_operations) | ||
restrictions = context[:current_user]&.restrictions&.select do |el| | ||
(el.resource.resource_type_id == "HasHelpers::ResourceType::::BaseResource" && |
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.
memoize base_restrictions thus is always the same
@base_restrictions ||= context[:current_user]&.restrictions&.select do |el|
(el.resource.resource_type_id == "HasHelpers::ResourceType::::BaseResource")
end
restrictions = @base_restrictions.select { |r| restriction_operations.include?(r.restriction_operation_id) }
Description
Implements access of the following list:
based on role's restrictions. If restrictions doesn't exist, it will display full data.
Result Format
Queries:
if a certain attribute has a view restriction, it will return null. Required fields can't be restricted because this will cause a schema conflict.
Mutations:
following graphql's result structure, warnings will be added inside { errors: warning: ... } and it will contain a list of the attributes/arguments (key) with the restriction (value). In the following example, it displays
Project
restrictions onname
attribute and also restrictions onUser's teamId
attribute, which is aProject Texter's
nested resource:obs:
Checklist