Address review feedback: remove backup file, initialize timestamps with current time, move attributes to Public schema

Co-authored-by: nitnelave <796633+nitnelave@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2025-08-26 22:51:27 +00:00
parent 1c92ae60d3
commit 8a8eb4157c
4 changed files with 37 additions and 2197 deletions
+27
View File
@@ -34,6 +34,24 @@ impl From<Schema> for PublicSchema {
is_hardcoded: true, is_hardcoded: true,
is_readonly: true, is_readonly: true,
}, },
AttributeSchema {
name: "modified_date".into(),
attribute_type: AttributeType::DateTime,
is_list: false,
is_visible: true,
is_editable: false,
is_hardcoded: true,
is_readonly: true,
},
AttributeSchema {
name: "password_modified_date".into(),
attribute_type: AttributeType::DateTime,
is_list: false,
is_visible: true,
is_editable: false,
is_hardcoded: true,
is_readonly: true,
},
AttributeSchema { AttributeSchema {
name: "mail".into(), name: "mail".into(),
attribute_type: AttributeType::String, attribute_type: AttributeType::String,
@@ -85,6 +103,15 @@ impl From<Schema> for PublicSchema {
is_hardcoded: true, is_hardcoded: true,
is_readonly: true, is_readonly: true,
}, },
AttributeSchema {
name: "modified_date".into(),
attribute_type: AttributeType::DateTime,
is_list: false,
is_visible: true,
is_editable: false,
is_hardcoded: true,
is_readonly: true,
},
AttributeSchema { AttributeSchema {
name: "uuid".into(), name: "uuid".into(),
attribute_type: AttributeType::String, attribute_type: AttributeType::String,
+4
View File
@@ -716,6 +716,8 @@ impl<Handler: BackendHandler> AttributeValue<Handler> {
let value: Option<DomainAttributeValue> = match attribute_schema.name.as_str() { let value: Option<DomainAttributeValue> = match attribute_schema.name.as_str() {
"user_id" => Some(user.user_id.clone().into_string().into()), "user_id" => Some(user.user_id.clone().into_string().into()),
"creation_date" => Some(user.creation_date.into()), "creation_date" => Some(user.creation_date.into()),
"modified_date" => Some(user.modified_date.into()),
"password_modified_date" => Some(user.password_modified_date.into()),
"mail" => Some(user.email.clone().into_string().into()), "mail" => Some(user.email.clone().into_string().into()),
"uuid" => Some(user.uuid.clone().into_string().into()), "uuid" => Some(user.uuid.clone().into_string().into()),
"display_name" => user.display_name.as_ref().map(|d| d.clone().into()), "display_name" => user.display_name.as_ref().map(|d| d.clone().into()),
@@ -760,6 +762,7 @@ impl<Handler: BackendHandler> AttributeValue<Handler> {
match attribute_schema.name.as_str() { match attribute_schema.name.as_str() {
"group_id" => (group.id.0 as i64).into(), "group_id" => (group.id.0 as i64).into(),
"creation_date" => group.creation_date.into(), "creation_date" => group.creation_date.into(),
"modified_date" => group.modified_date.into(),
"uuid" => group.uuid.clone().into_string().into(), "uuid" => group.uuid.clone().into_string().into(),
"display_name" => group.display_name.clone().into_string().into(), "display_name" => group.display_name.clone().into_string().into(),
_ => panic!("Unexpected hardcoded attribute: {}", attribute_schema.name), _ => panic!("Unexpected hardcoded attribute: {}", attribute_schema.name),
@@ -802,6 +805,7 @@ impl<Handler: BackendHandler> AttributeValue<Handler> {
match attribute_schema.name.as_str() { match attribute_schema.name.as_str() {
"group_id" => (group.group_id.0 as i64).into(), "group_id" => (group.group_id.0 as i64).into(),
"creation_date" => group.creation_date.into(), "creation_date" => group.creation_date.into(),
"modified_date" => group.modified_date.into(),
"uuid" => group.uuid.clone().into_string().into(), "uuid" => group.uuid.clone().into_string().into(),
"display_name" => group.display_name.clone().into_string().into(), "display_name" => group.display_name.clone().into_string().into(),
_ => panic!("Unexpected hardcoded attribute: {}", attribute_schema.name), _ => panic!("Unexpected hardcoded attribute: {}", attribute_schema.name),
File diff suppressed because it is too large Load Diff
@@ -1165,85 +1165,26 @@ async fn migrate_to_v11(transaction: DatabaseTransaction) -> Result<DatabaseTran
) )
.await?; .await?;
// Initialize existing users with modified_date = creation_date // Initialize existing users with modified_date and password_modified_date = now
let now = chrono::Utc::now().naive_utc();
transaction transaction
.execute( .execute(
builder.build( builder.build(
Query::update() Query::update()
.table(Users::Table) .table(Users::Table)
.value(Users::ModifiedDate, Expr::col(Users::CreationDate)) .value(Users::ModifiedDate, now)
.value(Users::PasswordModifiedDate, Expr::col(Users::CreationDate)), .value(Users::PasswordModifiedDate, now),
), ),
) )
.await?; .await?;
// Initialize existing groups with modified_date = creation_date // Initialize existing groups with modified_date = now
transaction transaction
.execute( .execute(
builder.build( builder.build(
Query::update() Query::update()
.table(Groups::Table) .table(Groups::Table)
.value(Groups::ModifiedDate, Expr::col(Groups::CreationDate)), .value(Groups::ModifiedDate, now),
),
)
.await?;
// Add the new timestamp attributes to the user attribute schema as hardcoded read-only attributes
transaction
.execute(
builder.build(
Query::insert()
.into_table(UserAttributeSchema::Table)
.columns([
UserAttributeSchema::UserAttributeSchemaName,
UserAttributeSchema::UserAttributeSchemaType,
UserAttributeSchema::UserAttributeSchemaIsList,
UserAttributeSchema::UserAttributeSchemaIsUserVisible,
UserAttributeSchema::UserAttributeSchemaIsUserEditable,
UserAttributeSchema::UserAttributeSchemaIsHardcoded,
])
.values_panic([
"modified_date".into(),
AttributeType::DateTime.into(),
false.into(),
true.into(),
false.into(),
true.into(),
])
.values_panic([
"password_modified_date".into(),
AttributeType::DateTime.into(),
false.into(),
true.into(),
false.into(),
true.into(),
]),
),
)
.await?;
// Add the new timestamp attribute to the group attribute schema as hardcoded read-only attribute
transaction
.execute(
builder.build(
Query::insert()
.into_table(GroupAttributeSchema::Table)
.columns([
GroupAttributeSchema::GroupAttributeSchemaName,
GroupAttributeSchema::GroupAttributeSchemaType,
GroupAttributeSchema::GroupAttributeSchemaIsList,
GroupAttributeSchema::GroupAttributeSchemaIsGroupVisible,
GroupAttributeSchema::GroupAttributeSchemaIsGroupEditable,
GroupAttributeSchema::GroupAttributeSchemaIsHardcoded,
])
.values_panic([
"modified_date".into(),
AttributeType::DateTime.into(),
false.into(),
true.into(),
false.into(),
true.into(),
]),
), ),
) )
.await?; .await?;