aboutsummaryrefslogtreecommitdiff
path: root/actions/src/remote_actions/mapping_manage/edit_mapping.rs
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-02-05 22:35:05 +0800
committer魏曹先生 <1992414357@qq.com>2026-02-05 22:35:05 +0800
commit27f6414ad1ff451feb0044af62f37dc2a6255ffa (patch)
treecb5693bc014cc8579dcf02a730fd4d2a5dfcf1a5 /actions/src/remote_actions/mapping_manage/edit_mapping.rs
parentade2fcb9302a4ab759795820dbde3b2b269490ee (diff)
Remove examples and legacy code, update .gitignore
- Delete examples directory and its example action system - Rename actions/ to legacy_actions/ and data/ to legacy_data/ - Update Cargo.toml license file reference - Move setup scripts to scripts/dev/ directory - Add todo.txt patterns to .gitignore
Diffstat (limited to 'actions/src/remote_actions/mapping_manage/edit_mapping.rs')
-rw-r--r--actions/src/remote_actions/mapping_manage/edit_mapping.rs157
1 files changed, 0 insertions, 157 deletions
diff --git a/actions/src/remote_actions/mapping_manage/edit_mapping.rs b/actions/src/remote_actions/mapping_manage/edit_mapping.rs
deleted file mode 100644
index 3c39c5d..0000000
--- a/actions/src/remote_actions/mapping_manage/edit_mapping.rs
+++ /dev/null
@@ -1,157 +0,0 @@
-use std::collections::HashMap;
-
-use action_system::{action::ActionContext, macros::action_gen};
-use serde::{Deserialize, Serialize};
-use tcp_connection::error::TcpTargetError;
-use vcs_data::data::local::{
- modified_status::sign_vault_modified,
- workspace_analyzer::{FromRelativePathBuf, ToRelativePathBuf},
-};
-
-use crate::{
- remote_actions::{
- auth_member, check_connection_instance, get_current_sheet_name, try_get_vault,
- },
- write_and_return,
-};
-
-pub type OperationArgument = (EditMappingOperations, Option<ToRelativePathBuf>);
-
-#[derive(Serialize, Deserialize, PartialEq, Eq, Clone)]
-pub enum EditMappingOperations {
- Move,
- Erase,
-}
-
-#[derive(Serialize, Deserialize, Default)]
-pub enum EditMappingActionResult {
- Success,
-
- // Fail
- AuthorizeFailed(String),
- EditNotAllowed,
- MappingNotFound(FromRelativePathBuf),
- InvalidMove(InvalidMoveReason),
-
- #[default]
- Unknown,
-}
-
-#[derive(Serialize, Deserialize)]
-pub enum InvalidMoveReason {
- MoveOperationButNoTarget(FromRelativePathBuf),
- ContainsDuplicateMapping(ToRelativePathBuf),
-}
-
-#[derive(Serialize, Deserialize, Clone)]
-pub struct EditMappingActionArguments {
- pub operations: HashMap<FromRelativePathBuf, OperationArgument>,
-}
-
-/// This Action only modifies Sheet Mapping and
-/// does not interfere with the actual location of local files or Local Mapping
-#[action_gen]
-pub async fn edit_mapping_action(
- ctx: ActionContext,
- args: EditMappingActionArguments,
-) -> Result<EditMappingActionResult, TcpTargetError> {
- let instance = check_connection_instance(&ctx)?;
-
- // Auth Member
- let (member_id, is_host_mode) = match auth_member(&ctx, instance).await {
- Ok(id) => id,
- Err(e) => {
- return Ok(EditMappingActionResult::AuthorizeFailed(e.to_string()));
- }
- };
-
- // Check sheet
- let (sheet_name, is_ref_sheet) =
- get_current_sheet_name(&ctx, instance, &member_id, true).await?;
-
- // Can modify Sheet when not in reference sheet or in Host mode
- let can_modify_sheet = !is_ref_sheet || is_host_mode;
-
- if !can_modify_sheet {
- return Ok(EditMappingActionResult::EditNotAllowed);
- }
-
- if ctx.is_proc_on_remote() {
- let vault = try_get_vault(&ctx)?;
- let mut sheet = vault.sheet(&sheet_name).await?;
-
- // Precheck
- for (from_path, (operation, to_path)) in args.operations.iter() {
- // Check mapping exists
- if !sheet.mapping().contains_key(from_path) {
- write_and_return!(
- instance,
- EditMappingActionResult::MappingNotFound(from_path.clone())
- );
- }
-
- // Move check
- if operation == &EditMappingOperations::Move {
- // Check if target exists
- if let Some(to_path) = to_path {
- // Check if target is duplicate
- if sheet.mapping().contains_key(to_path) {
- write_and_return!(
- instance,
- EditMappingActionResult::InvalidMove(
- InvalidMoveReason::ContainsDuplicateMapping(to_path.clone())
- )
- );
- }
- } else {
- write_and_return!(
- instance,
- EditMappingActionResult::InvalidMove(
- InvalidMoveReason::MoveOperationButNoTarget(from_path.clone())
- )
- );
- }
- }
- }
-
- // Process
- for (from_path, (operation, to_path)) in args.operations {
- match operation {
- // During the Precheck phase, it has been ensured that:
- // 1. The mapping to be edited for the From path indeed exists
- // 2. The location of the To path is indeed empty
- // 3. In Move mode, To path can be safely unwrapped
- // Therefore, the following unwrap() calls are safe to execute
- EditMappingOperations::Move => {
- let mapping = sheet.mapping_mut().remove(&from_path).unwrap();
- let to_path = to_path.unwrap();
- sheet
- .add_mapping(to_path, mapping.id, mapping.version)
- .await?;
- }
- EditMappingOperations::Erase => {
- sheet.mapping_mut().remove(&from_path).unwrap();
- }
- }
- }
-
- // Write
- sheet.persist().await?;
-
- write_and_return!(instance, EditMappingActionResult::Success);
- }
-
- if ctx.is_proc_on_local() {
- let result = instance
- .lock()
- .await
- .read::<EditMappingActionResult>()
- .await?;
- if matches!(result, EditMappingActionResult::Success) {
- sign_vault_modified(true).await;
- }
- return Ok(result);
- }
-
- Ok(EditMappingActionResult::Success)
-}