Skip to content

Commit

Permalink
PR Feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
Koshroy-Abbey committed Nov 21, 2023
1 parent a691a1d commit fbbe036
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/abbey/functions/has_attribute.rego
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ package abbey.functions

import future.keywords.if

# Function which checks whether a user has a given attribute
# Attributes are found under a custom_attributes object under the
# abbey.identities object
has_attribute(name, value) := true if {
data.system.abbey.identities.directory_sync_users.custom_attributes[name] == value
}
19 changes: 19 additions & 0 deletions src/abbey/functions/has_attribute_test.rego
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package abbey.functions

import future.keywords.if

test_has_cost_center_engineering if {
has_attribute("cost_center_name", "Engineering") with data.system.abbey.identities.directory_sync_users.custom_attributes as {"department_name": "Engineering", "cost_center_name": "Engineering", "employee_type": "Manager"}
}

test_has_department_engineering if {
has_attribute("department_name", "Engineering") with data.system.abbey.identities.directory_sync_users.custom_attributes as {"department_name": "Engineering", "cost_center_name": "Engineering", "employee_type": "Manager"}
}

test_does_not_have_department_marketing if {
not has_attribute("department_name", "Marketing") with data.system.abbey.identities.directory_sync_users.custom_attributes as {"department_name": "Engineering", "cost_center_name": "Engineering", "employee_type": "Manager"}
}

test_does_not_have_employee_type_ic if {
not has_attribute("employee_type", "IC") with data.system.abbey.identities.directory_sync_users.custom_attributes as {"department_name": "Engineering", "cost_center_name": "Engineering", "employee_type": "Manager"}
}
6 changes: 4 additions & 2 deletions src/abbey/functions/in_group.rego
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package abbey.functions
import future.keywords.if
import future.keywords.in

# Function which checks whether a user is in a given group
# Groups are kept within an object called group_memberships in the
# system.abbey object
in_group(group_name) := true if {
some group in data.system.abbey.group_memberships
group == group_name
group_name in data.system.abbey.group_memberships
}
11 changes: 11 additions & 0 deletions src/abbey/functions/in_group_test.rego
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package abbey.functions

import future.keywords.if

test_in_group_engineering if {
in_group("Engineering") with data.system.abbey.group_memberships as ["Engineering", "R&D"]
}

test_not_in_group_marketing if {
not in_group("Marketing") with data.system.abbey.group_memberships as ["Engineering", "R&D"]
}

0 comments on commit fbbe036

Please sign in to comment.