summaryrefslogtreecommitdiff
path: root/crates/vcs/src/data/vault/config.rs
blob: 11917ded87333a19e41b869c29e20502f1635fb4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
use cfg_file::ConfigFile;
use serde::{Deserialize, Serialize};

use crate::constants::SERVER_FILE_VAULT;
use crate::data::member::Member;
use crate::data::vault::MemberId;

#[derive(Serialize, Deserialize, ConfigFile)]
#[cfg_file(path = SERVER_FILE_VAULT)]
pub struct VaultConfig {
    /// Vault name, which can be used as the project name and generally serves as a hint
    vault_name: String,

    /// Vault admin id, a list of member id representing administrator identities
    vault_admin_list: Vec<MemberId>,
}

impl Default for VaultConfig {
    fn default() -> Self {
        Self {
            vault_name: "JustEnoughVault".to_string(),
            vault_admin_list: Vec::new(),
        }
    }
}

impl VaultConfig {
    // Change name of the vault.
    pub fn change_name(&mut self, name: impl Into<String>) {
        self.vault_name = name.into()
    }

    // Add admin
    pub fn add_admin(&mut self, member: &Member) {
        let uuid = member.id();
        if !self.vault_admin_list.contains(&uuid) {
            self.vault_admin_list.push(uuid);
        }
    }

    // Remove admin
    pub fn remove_admin(&mut self, member: &Member) {
        let id = member.id();
        self.vault_admin_list.retain(|x| x != &id);
    }
}