Skip to content

Commit

Permalink
Merge branch 'dev' into admin-group-permission
Browse files Browse the repository at this point in the history
  • Loading branch information
t-aleksander committed Dec 12, 2024
2 parents 8b4671d + b64ce0c commit 95cf27c
Show file tree
Hide file tree
Showing 26 changed files with 1,120 additions and 532 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions migrations/20241211115639_directory_sync_target.down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE openidprovider DROP COLUMN directory_sync_target;
7 changes: 7 additions & 0 deletions migrations/20241211115639_directory_sync_target.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
CREATE TYPE dirsync_target AS ENUM (
'all',
'users',
'groups'
);

ALTER TABLE openidprovider ADD COLUMN directory_sync_target dirsync_target DEFAULT 'all'::dirsync_target NOT NULL;
56 changes: 52 additions & 4 deletions src/enterprise/db/models/openid_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,46 @@ impl From<String> for DirectorySyncUserBehavior {
}
}

// What to sync from the directory
// All: Sync both users and groups
// Users: Sync only users and their state
// Groups: Sync only groups (members without their state)
#[derive(Clone, Deserialize, Serialize, PartialEq, Type, Debug)]
#[sqlx(type_name = "dirsync_target", rename_all = "snake_case")]
pub enum DirectorySyncTarget {
All,
Users,
Groups,
}

impl fmt::Display for DirectorySyncTarget {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"{}",
match self {
DirectorySyncTarget::All => "all",
DirectorySyncTarget::Users => "users",
DirectorySyncTarget::Groups => "groups",
}
)
}
}

impl From<String> for DirectorySyncTarget {
fn from(s: String) -> Self {
match s.to_lowercase().as_str() {
"all" => DirectorySyncTarget::All,
"users" => DirectorySyncTarget::Users,
"groups" => DirectorySyncTarget::Groups,
_ => {
warn!("Unknown directory sync target passed: {}", s);
DirectorySyncTarget::All
}
}
}
}

#[derive(Deserialize, Model, Serialize)]
pub struct OpenIdProvider<I = NoId> {
pub id: I,
Expand All @@ -64,6 +104,8 @@ pub struct OpenIdProvider<I = NoId> {
pub directory_sync_user_behavior: DirectorySyncUserBehavior,
#[model(enum)]
pub directory_sync_admin_behavior: DirectorySyncUserBehavior,
#[model(enum)]
pub directory_sync_target: DirectorySyncTarget,
}

impl OpenIdProvider {
Expand All @@ -81,6 +123,7 @@ impl OpenIdProvider {
directory_sync_interval: i32,
directory_sync_user_behavior: DirectorySyncUserBehavior,
directory_sync_admin_behavior: DirectorySyncUserBehavior,
directory_sync_target: DirectorySyncTarget,
) -> Self {
Self {
id: NoId,
Expand All @@ -96,6 +139,7 @@ impl OpenIdProvider {
directory_sync_interval,
directory_sync_user_behavior,
directory_sync_admin_behavior,
directory_sync_target,
}
}

Expand All @@ -105,8 +149,9 @@ impl OpenIdProvider {
"UPDATE openidprovider SET name = $1, \
base_url = $2, client_id = $3, client_secret = $4, \
display_name = $5, google_service_account_key = $6, google_service_account_email = $7, admin_email = $8, \
directory_sync_enabled = $9, directory_sync_interval = $10, directory_sync_user_behavior = $11, directory_sync_admin_behavior = $12 \
WHERE id = $13",
directory_sync_enabled = $9, directory_sync_interval = $10, directory_sync_user_behavior = $11, directory_sync_admin_behavior = $12, \
directory_sync_target = $13 \
WHERE id = $14",
self.name,
self.base_url,
self.client_id,
Expand All @@ -119,6 +164,7 @@ impl OpenIdProvider {
self.directory_sync_interval,
self.directory_sync_user_behavior as DirectorySyncUserBehavior,
self.directory_sync_admin_behavior as DirectorySyncUserBehavior,
self.directory_sync_target as DirectorySyncTarget,
provider.id,
)
.execute(pool)
Expand All @@ -138,7 +184,8 @@ impl OpenIdProvider<Id> {
"SELECT id, name, base_url, client_id, client_secret, display_name, \
google_service_account_key, google_service_account_email, admin_email, directory_sync_enabled,
directory_sync_interval, directory_sync_user_behavior \"directory_sync_user_behavior: DirectorySyncUserBehavior\", \
directory_sync_admin_behavior \"directory_sync_admin_behavior: DirectorySyncUserBehavior\" \
directory_sync_admin_behavior \"directory_sync_admin_behavior: DirectorySyncUserBehavior\", \
directory_sync_target \"directory_sync_target: DirectorySyncTarget\" \
FROM openidprovider WHERE name = $1",
name
)
Expand All @@ -152,7 +199,8 @@ impl OpenIdProvider<Id> {
"SELECT id, name, base_url, client_id, client_secret, display_name, \
google_service_account_key, google_service_account_email, admin_email, directory_sync_enabled, \
directory_sync_interval, directory_sync_user_behavior \"directory_sync_user_behavior: DirectorySyncUserBehavior\", \
directory_sync_admin_behavior \"directory_sync_admin_behavior: DirectorySyncUserBehavior\" \
directory_sync_admin_behavior \"directory_sync_admin_behavior: DirectorySyncUserBehavior\", \
directory_sync_target \"directory_sync_target: DirectorySyncTarget\" \
FROM openidprovider LIMIT 1"
)
.fetch_optional(pool)
Expand Down
Loading

0 comments on commit 95cf27c

Please sign in to comment.