Skip to content

Commit 8358ddb

Browse files
authored
feat: add is_locked properties to view (#368)
1 parent c25bfc3 commit 8358ddb

File tree

5 files changed

+19
-0
lines changed

5 files changed

+19
-0
lines changed

collab-folder/src/folder.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -863,6 +863,7 @@ mod tests {
863863
created_by: None,
864864
last_edited_time: current_time,
865865
last_edited_by: None,
866+
is_locked: None,
866867
extra: Some(serde_json::to_string(&SpaceInfo::default()).unwrap()),
867868
};
868869
let space_view_id = space_view.id.clone();

collab-folder/src/hierarchy_builder.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ pub struct NestedChildViewBuilder {
116116
children: Vec<ParentChildViews>,
117117
is_favorite: bool,
118118
icon: Option<ViewIcon>,
119+
is_locked: Option<bool>,
119120
extra: Option<String>,
120121
}
121122

@@ -133,6 +134,7 @@ impl NestedChildViewBuilder {
133134
children: vec![],
134135
is_favorite: false,
135136
icon: None,
137+
is_locked: None,
136138
extra: None,
137139
}
138140
}
@@ -219,6 +221,7 @@ impl NestedChildViewBuilder {
219221
.collect(),
220222
),
221223
last_edited_by: Some(self.uid),
224+
is_locked: self.is_locked,
222225
extra: self.extra,
223226
};
224227
ParentChildViews {

collab-folder/src/view.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const VIEW_CREATED_BY: &str = "created_by";
2828
const VIEW_ICON: &str = "icon";
2929
const VIEW_LAST_EDITED_TIME: &str = "last_edited_time";
3030
const VIEW_LAST_EDITED_BY: &str = "last_edited_by";
31+
const VIEW_IS_LOCKED: &str = "is_locked";
3132
const VIEW_EXTRA: &str = "extra";
3233
// const VIEW_LAST_VIEWED_TIME: &str = "last_viewed_time";
3334

@@ -454,6 +455,7 @@ pub(crate) fn view_from_map_ref<T: ReadTxn>(
454455
.get_with_txn(txn, VIEW_LAST_EDITED_TIME)
455456
.unwrap_or(timestamp());
456457
let last_edited_by = map_ref.get_with_txn(txn, VIEW_LAST_EDITED_BY);
458+
let is_locked = map_ref.get_with_txn(txn, VIEW_IS_LOCKED);
457459
let extra = map_ref.get_with_txn(txn, VIEW_EXTRA);
458460

459461
Some(View {
@@ -468,6 +470,7 @@ pub(crate) fn view_from_map_ref<T: ReadTxn>(
468470
created_by,
469471
last_edited_time,
470472
last_edited_by,
473+
is_locked,
471474
extra,
472475
})
473476
}
@@ -586,6 +589,13 @@ impl<'a, 'b, 'c> ViewUpdate<'a, 'b, 'c> {
586589
self
587590
}
588591

592+
pub fn set_is_locked(self, is_locked: Option<bool>) -> Self {
593+
if let Some(is_locked) = is_locked {
594+
self.map_ref.insert(self.txn, VIEW_IS_LOCKED, is_locked);
595+
}
596+
self
597+
}
598+
589599
pub fn set_private(self, is_private: bool) -> Self {
590600
if let Some(private_section) = self.section_map.section_op(self.txn, Section::Private) {
591601
if is_private {
@@ -679,6 +689,7 @@ pub struct View {
679689
pub created_by: Option<i64>, // user id
680690
pub last_edited_time: i64,
681691
pub last_edited_by: Option<i64>, // user id
692+
pub is_locked: Option<bool>,
682693
/// this value used to store the extra data with JSON format
683694
/// for document:
684695
/// - cover: { type: "", value: "" }
@@ -713,6 +724,7 @@ impl View {
713724
created_by,
714725
last_edited_time: 0,
715726
last_edited_by: None,
727+
is_locked: None,
716728
extra: None,
717729
}
718730
}
@@ -730,6 +742,7 @@ impl View {
730742
created_by: uid,
731743
last_edited_time: 0,
732744
last_edited_by: None,
745+
is_locked: None,
733746
extra: None,
734747
}
735748
}

collab-folder/src/workspace.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ impl From<Workspace> for View {
5656
created_by: value.created_by,
5757
last_edited_time: value.last_edited_time,
5858
last_edited_by: value.last_edited_by,
59+
is_locked: None,
5960
extra: None,
6061
}
6162
}

collab-folder/tests/folder_test/util.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ pub fn make_test_view(view_id: &str, parent_view_id: &str, belongings: Vec<Strin
148148
created_by: None,
149149
last_edited_time: 0,
150150
last_edited_by: None,
151+
is_locked: None,
151152
extra: None,
152153
}
153154
}

0 commit comments

Comments
 (0)