Created
June 7, 2022 19:53
-
-
Save emailrhoads/4dc0f139164af09c74f1699c0d59e33c to your computer and use it in GitHub Desktop.
Role permissions report
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data = Netzke::Base.descendants.map do |component| | |
next unless component.respond_to?(:marty_permissions) | |
# ancestors includes self | |
component_permissions = {} | |
component.ancestors.each do |ancestor| | |
next unless ancestor.respond_to?(:marty_permissions) | |
ancestor.marty_permissions.each do |action, roles| | |
component_permissions[action] ||= roles | |
end | |
end | |
component_permissions.map do |action, roles| | |
roles = [roles] if roles.is_a?(Symbol) | |
{ | |
component: component.to_s, | |
action: action, | |
roles: roles.present? ? roles : "none" | |
} | |
end | |
end.flatten(1).compact | |
CSV.open("permissions.csv", "w", headers: data.first.keys) do |csv| | |
csv << data.first.keys | |
data.each do |h| | |
csv << h.values | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment