Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add is_locked properties to view #368

Merged
merged 1 commit into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions collab-folder/src/folder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -863,6 +863,7 @@ mod tests {
created_by: None,
last_edited_time: current_time,
last_edited_by: None,
is_locked: None,
extra: Some(serde_json::to_string(&SpaceInfo::default()).unwrap()),
};
let space_view_id = space_view.id.clone();
Expand Down
3 changes: 3 additions & 0 deletions collab-folder/src/hierarchy_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ pub struct NestedChildViewBuilder {
children: Vec<ParentChildViews>,
is_favorite: bool,
icon: Option<ViewIcon>,
is_locked: Option<bool>,
extra: Option<String>,
}

Expand All @@ -133,6 +134,7 @@ impl NestedChildViewBuilder {
children: vec![],
is_favorite: false,
icon: None,
is_locked: None,
extra: None,
}
}
Expand Down Expand Up @@ -219,6 +221,7 @@ impl NestedChildViewBuilder {
.collect(),
),
last_edited_by: Some(self.uid),
is_locked: self.is_locked,
extra: self.extra,
};
ParentChildViews {
Expand Down
13 changes: 13 additions & 0 deletions collab-folder/src/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const VIEW_CREATED_BY: &str = "created_by";
const VIEW_ICON: &str = "icon";
const VIEW_LAST_EDITED_TIME: &str = "last_edited_time";
const VIEW_LAST_EDITED_BY: &str = "last_edited_by";
const VIEW_IS_LOCKED: &str = "is_locked";
const VIEW_EXTRA: &str = "extra";
// const VIEW_LAST_VIEWED_TIME: &str = "last_viewed_time";

Expand Down Expand Up @@ -454,6 +455,7 @@ pub(crate) fn view_from_map_ref<T: ReadTxn>(
.get_with_txn(txn, VIEW_LAST_EDITED_TIME)
.unwrap_or(timestamp());
let last_edited_by = map_ref.get_with_txn(txn, VIEW_LAST_EDITED_BY);
let is_locked = map_ref.get_with_txn(txn, VIEW_IS_LOCKED);
let extra = map_ref.get_with_txn(txn, VIEW_EXTRA);

Some(View {
Expand All @@ -468,6 +470,7 @@ pub(crate) fn view_from_map_ref<T: ReadTxn>(
created_by,
last_edited_time,
last_edited_by,
is_locked,
extra,
})
}
Expand Down Expand Up @@ -586,6 +589,13 @@ impl<'a, 'b, 'c> ViewUpdate<'a, 'b, 'c> {
self
}

pub fn set_is_locked(self, is_locked: Option<bool>) -> Self {
if let Some(is_locked) = is_locked {
self.map_ref.insert(self.txn, VIEW_IS_LOCKED, is_locked);
}
self
}

pub fn set_private(self, is_private: bool) -> Self {
if let Some(private_section) = self.section_map.section_op(self.txn, Section::Private) {
if is_private {
Expand Down Expand Up @@ -679,6 +689,7 @@ pub struct View {
pub created_by: Option<i64>, // user id
pub last_edited_time: i64,
pub last_edited_by: Option<i64>, // user id
pub is_locked: Option<bool>,
/// this value used to store the extra data with JSON format
/// for document:
/// - cover: { type: "", value: "" }
Expand Down Expand Up @@ -713,6 +724,7 @@ impl View {
created_by,
last_edited_time: 0,
last_edited_by: None,
is_locked: None,
extra: None,
}
}
Expand All @@ -730,6 +742,7 @@ impl View {
created_by: uid,
last_edited_time: 0,
last_edited_by: None,
is_locked: None,
extra: None,
}
}
Expand Down
1 change: 1 addition & 0 deletions collab-folder/src/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ impl From<Workspace> for View {
created_by: value.created_by,
last_edited_time: value.last_edited_time,
last_edited_by: value.last_edited_by,
is_locked: None,
extra: None,
}
}
Expand Down
1 change: 1 addition & 0 deletions collab-folder/tests/folder_test/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ pub fn make_test_view(view_id: &str, parent_view_id: &str, belongings: Vec<Strin
created_by: None,
last_edited_time: 0,
last_edited_by: None,
is_locked: None,
extra: None,
}
}
Expand Down
Loading