Change a view's scope between Draft and Shared. This is useful after `git import` which creates Draft views by default.
(&self, name: &str, scope: ViewScope)
| 159 | /// This is useful after `git import` which creates Draft views by |
| 160 | /// default. |
| 161 | pub fn set_view_scope(&self, name: &str, scope: ViewScope) -> Result<(), RepositoryError> { |
| 162 | let mut txn = self |
| 163 | .pristine |
| 164 | .write_txn() |
| 165 | .map_err(|e| RepositoryError::Database(e.to_string()))?; |
| 166 | |
| 167 | let mut view = txn |
| 168 | .get_view(name) |
| 169 | .map_err(|e| RepositoryError::Database(e.to_string()))? |
| 170 | .ok_or_else(|| RepositoryError::ViewNotFound { |
| 171 | name: name.to_string(), |
| 172 | })?; |
| 173 | |
| 174 | view.kind = scope; |
| 175 | // Clear parent when promoting to Shared root view |
| 176 | if scope.is_shared() { |
| 177 | view.parent = None; |
| 178 | } |
| 179 | |
| 180 | txn.update_view(&view) |
| 181 | .map_err(|e| RepositoryError::Database(e.to_string()))?; |
| 182 | |
| 183 | txn.commit() |
| 184 | .map_err(|e| RepositoryError::Database(e.to_string()))?; |
| 185 | |
| 186 | Ok(()) |
| 187 | } |
| 188 | |
| 189 | /// Walk the parent chain from `view_name` and return the name of the |
| 190 | /// first Shared view encountered. If `view_name` is itself Shared, |