From ea230b85c0f4e09b61187b22f98f6d719951acb9 Mon Sep 17 00:00:00 2001 From: Kendall Strautman Swarthout <36613477+kendallstrautman@users.noreply.github.com> Date: Mon, 21 Oct 2024 12:25:58 -0700 Subject: [PATCH] Add role to directory user (#254) --- .../com/workos/directorysync/models/DirectoryUserRole.kt | 5 +++++ src/main/kotlin/com/workos/directorysync/models/User.kt | 5 +++++ src/main/kotlin/com/workos/webhooks/models/UserUpdated.kt | 5 +++++ .../com/workos/test/directorysync/DirectorySyncApiTest.kt | 7 +++++++ src/test/kotlin/com/workos/test/directorysync/UserTest.kt | 1 + .../com/workos/test/webhooks/DirectoryGroupWebhookTests.kt | 1 + .../com/workos/test/webhooks/DirectoryUserWebhookTests.kt | 3 +++ .../kotlin/com/workos/test/webhooks/WebhooksApiTest.kt | 2 ++ 8 files changed, 29 insertions(+) create mode 100644 src/main/kotlin/com/workos/directorysync/models/DirectoryUserRole.kt diff --git a/src/main/kotlin/com/workos/directorysync/models/DirectoryUserRole.kt b/src/main/kotlin/com/workos/directorysync/models/DirectoryUserRole.kt new file mode 100644 index 00000000..68dc6527 --- /dev/null +++ b/src/main/kotlin/com/workos/directorysync/models/DirectoryUserRole.kt @@ -0,0 +1,5 @@ +package com.workos.directorysync.models + +import com.workos.common.models.Role + +typealias DirectoryUserRole = Role diff --git a/src/main/kotlin/com/workos/directorysync/models/User.kt b/src/main/kotlin/com/workos/directorysync/models/User.kt index 62085b5a..c0d586b7 100644 --- a/src/main/kotlin/com/workos/directorysync/models/User.kt +++ b/src/main/kotlin/com/workos/directorysync/models/User.kt @@ -19,6 +19,7 @@ import com.fasterxml.jackson.annotation.JsonProperty * @param emails The emails of the user. * @param groups The groups that the user is a member of. * @param state The state of the user. + * @param role The user's role based on group memberships. * @param customAttributes An object containing the custom attribute mapping for the Directory Provider. * @param rawAttributes An object containing the data returned from the Directory Provider. */ @@ -76,6 +77,10 @@ open class User @JvmField open val state: UserState, + @JvmField + @JsonProperty("role") + val role: DirectoryUserRole, + @JvmField @JsonProperty("custom_attributes") open val customAttributes: Map, diff --git a/src/main/kotlin/com/workos/webhooks/models/UserUpdated.kt b/src/main/kotlin/com/workos/webhooks/models/UserUpdated.kt index 5585cedb..187c3888 100644 --- a/src/main/kotlin/com/workos/webhooks/models/UserUpdated.kt +++ b/src/main/kotlin/com/workos/webhooks/models/UserUpdated.kt @@ -2,6 +2,7 @@ package com.workos.webhooks.models import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import com.workos.directorysync.models.DirectoryUserRole import com.workos.directorysync.models.Email import com.workos.directorysync.models.UserState @@ -67,6 +68,10 @@ open class UserUpdated @JsonProperty("raw_attributes") val rawAttributes: Map, + @JvmField + @JsonProperty("role") + val role: DirectoryUserRole, + /** * Object containing the names and values of attributes and their previous values. * New attributes that do not appear in the previous snapshot are indicated with a diff --git a/src/test/kotlin/com/workos/test/directorysync/DirectorySyncApiTest.kt b/src/test/kotlin/com/workos/test/directorysync/DirectorySyncApiTest.kt index a5ec0a33..b97879f4 100644 --- a/src/test/kotlin/com/workos/test/directorysync/DirectorySyncApiTest.kt +++ b/src/test/kotlin/com/workos/test/directorysync/DirectorySyncApiTest.kt @@ -312,6 +312,7 @@ class DirectorySyncApiTest : TestBase() { "raw_attributes": {} }], "state": "active", + "role":{"slug":"admin"}, "created_at": "2021-06-25T19:07:33.155Z", "updated_at": "2021-06-25T19:08:33.155Z", "custom_attributes": { @@ -528,6 +529,7 @@ class DirectorySyncApiTest : TestBase() { "raw_attributes": {} }], "state": "active", + "role":{"slug":"admin"}, "created_at": "2021-06-25T19:07:33.155Z", "updated_at": "2021-06-25T19:08:33.155Z", "custom_attributes": { @@ -559,6 +561,7 @@ class DirectorySyncApiTest : TestBase() { "raw_attributes": {} }], "state": "active", + "role":{"slug":"member"}, "created_at": "2021-06-25T19:07:33.155Z", "updated_at": "2021-06-25T19:08:33.155Z", "custom_attributes": { @@ -629,6 +632,7 @@ class DirectorySyncApiTest : TestBase() { "raw_attributes": {} }], "state": "active", + "role":{"slug":"admin"}, "created_at": "2021-06-25T19:07:33.155Z", "updated_at": "2021-06-25T19:08:33.155Z", "custom_attributes": { @@ -659,6 +663,7 @@ class DirectorySyncApiTest : TestBase() { "raw_attributes": {} }], "state": "active", + "role":{"slug":"member"}, "created_at": "2021-06-25T19:07:33.155Z", "updated_at": "2021-06-25T19:08:33.155Z", "custom_attributes": { @@ -734,6 +739,7 @@ class DirectorySyncApiTest : TestBase() { "state": "active", "created_at": "2021-06-25T19:07:33.155Z", "updated_at": "2021-06-25T19:08:33.155Z", + "role":{"slug":"admin"}, "custom_attributes": { "department": "Engineering" }, @@ -765,6 +771,7 @@ class DirectorySyncApiTest : TestBase() { "state": "active", "created_at": "2021-06-25T19:07:33.155Z", "updated_at": "2021-06-25T19:08:33.155Z", + "role":{"slug":"member"}, "custom_attributes": { "department": "Engineering" }, diff --git a/src/test/kotlin/com/workos/test/directorysync/UserTest.kt b/src/test/kotlin/com/workos/test/directorysync/UserTest.kt index c04dd591..a6871880 100644 --- a/src/test/kotlin/com/workos/test/directorysync/UserTest.kt +++ b/src/test/kotlin/com/workos/test/directorysync/UserTest.kt @@ -41,6 +41,7 @@ class UserTest : TestBase() { "raw_attributes": {} }], "state": "active", + "role":{"slug":"admin"}, "created_at": "2021-06-25T19:07:33.155Z", "updated_at": "2021-06-25T19:08:33.155Z", "custom_attributes": { diff --git a/src/test/kotlin/com/workos/test/webhooks/DirectoryGroupWebhookTests.kt b/src/test/kotlin/com/workos/test/webhooks/DirectoryGroupWebhookTests.kt index ca80cd7c..eaa868d9 100644 --- a/src/test/kotlin/com/workos/test/webhooks/DirectoryGroupWebhookTests.kt +++ b/src/test/kotlin/com/workos/test/webhooks/DirectoryGroupWebhookTests.kt @@ -66,6 +66,7 @@ class DirectoryGroupWebhookTests : TestBase() { "first_name": "Michael", "job_title": "Software Engineer", "directory_id": "$directoryId", + "role": { "slug": "member" }, "created_at": "2021-06-25T19:07:33.155Z", "updated_at": "2021-06-25T19:08:33.155Z", "raw_attributes": { diff --git a/src/test/kotlin/com/workos/test/webhooks/DirectoryUserWebhookTests.kt b/src/test/kotlin/com/workos/test/webhooks/DirectoryUserWebhookTests.kt index ddef9e08..b9aac496 100644 --- a/src/test/kotlin/com/workos/test/webhooks/DirectoryUserWebhookTests.kt +++ b/src/test/kotlin/com/workos/test/webhooks/DirectoryUserWebhookTests.kt @@ -37,6 +37,7 @@ class DirectoryUserWebhookTests : TestBase() { "created_at": "2021-06-25T19:07:33.155Z", "updated_at": "2021-06-25T19:08:33.155Z", "directory_id": "$directoryId", + "role": { "slug": "member" }, "raw_attributes": { "id": "105777651754615852813", "etag": "\"nqbsbhvoIENh0WbZEZYWTG7mnk2phHz4rrCEo-rHT2k/E5jQHrdS88NS4ACUhZ4m9CYVR30\"", @@ -102,6 +103,7 @@ class DirectoryUserWebhookTests : TestBase() { "created_at": "2021-06-25T19:07:33.155Z", "updated_at": "2021-06-25T19:08:33.155Z", "directory_id": "$directoryId", + "role": { "slug": "admin" }, "raw_attributes": { "id": "105777651754615852813", "etag": "\"nqbsbhvoIENh0WbZEZYWTG7mnk2phHz4rrCEo-rHT2k/E5jQHrdS88NS4ACUhZ4m9CYVR30\"", @@ -140,6 +142,7 @@ class DirectoryUserWebhookTests : TestBase() { }, "custom_attributes": {}, "previous_attributes": { + "role": { "slug": "member" }, "raw_attributes": { "emails": [ { diff --git a/src/test/kotlin/com/workos/test/webhooks/WebhooksApiTest.kt b/src/test/kotlin/com/workos/test/webhooks/WebhooksApiTest.kt index 357ecf94..f2ad4bbc 100644 --- a/src/test/kotlin/com/workos/test/webhooks/WebhooksApiTest.kt +++ b/src/test/kotlin/com/workos/test/webhooks/WebhooksApiTest.kt @@ -38,6 +38,7 @@ class WebhooksApiTest : TestBase() { "created_at": "2021-06-25T19:07:33.155Z", "updated_at": "2021-06-25T19:08:33.155Z", "directory_id": "directory_01F9M7F68PZP8QXP8G7X5QRHS7", + "role": { "slug": "member" }, "custom_attributes": {}, "raw_attributes": { "name": { @@ -95,6 +96,7 @@ class WebhooksApiTest : TestBase() { "created_at": "2021-06-25T19:07:33.155Z", "updated_at": "2021-06-25T19:08:33.155Z", "directory_id": "directory_01F9M7F68PZP8QXP8G7X5QRHS7", + "role": { "slug": "member" }, "custom_attributes": {}, "raw_attributes": {}, "new_unknown_property": {},