I have a yaml like this: products: surveys: enabled: true specialconstraints: false…
- User
I have a yaml like this: products: surveys: enabled: true special_constraints: false reviews: enabled: true special_constraints: false goals: enabled: false special_constraints: false one_on_ones: enabled: true special_constraints: true biz_reviews: enabled: false special_constraints: false
And my service looks like this: module Reporting class TabPermissions attr_reader :employee include YmlHelper def initialize(employee) @employee = employee end
codedef call begin get_permissions_object rescue => e Sentry.capture_exception(e) [] end end private=begin if employee is admin return all enabled products as true and all disabled products as false if employee is not an admin then check through permissions if they can access V2 else if a product has special constraints then check if employee meets the criterion and only return true for those products which they can access In our case one_on_ones has special constraints which is that it should be shown if employee is a manager. =end
codedef get_permissions_object config_file = load_yml_file('config/settings/reporting/reporting_products_list.yml') config_file['products'].each_with_object({}) do |key, obj| endend end
Make changes in the service so that it fulfils the comment's requirement. For checking if employee is a manager you can use: employee.direct_reports.any?
- Assistant
To fulfill the requirements stated in the comments, we'll need to modify the
get_permissions_objectmethod to return a permissions hash based on the employee's status (admin, can access V2, or meets special constraints). Here's how you can implement it: