This PR adds a setting to prevent projects from being shared in public
channels.
This can be enabled by adding the following to the project settings
(`.zed/settings.json`):
```json
{
"prevent_sharing_in_public_channels": true
}
```
This will then disable the "Share" button when not in a private channel:
<img width="380" height="115" alt="Screenshot 2025-10-28 at 2 28 10 PM"
src="https://github.com/user-attachments/assets/6761ac34-c0d5-4451-a443-adf7a1c42bcd"
/>
Release Notes:
- collaboration: Added a `prevent_sharing_in_public_channels` project
setting for preventing projects from being shared in public channels.
77 lines
2.6 KiB
Rust
77 lines
2.6 KiB
Rust
use std::path::Path;
|
|
|
|
use anyhow::Context as _;
|
|
use settings::Settings;
|
|
use util::{
|
|
ResultExt,
|
|
paths::{PathMatcher, PathStyle},
|
|
rel_path::RelPath,
|
|
};
|
|
|
|
#[derive(Clone, PartialEq, Eq)]
|
|
pub struct WorktreeSettings {
|
|
pub project_name: Option<String>,
|
|
/// Whether to prevent this project from being shared in public channels.
|
|
pub prevent_sharing_in_public_channels: bool,
|
|
pub file_scan_inclusions: PathMatcher,
|
|
pub file_scan_exclusions: PathMatcher,
|
|
pub private_files: PathMatcher,
|
|
}
|
|
|
|
impl WorktreeSettings {
|
|
pub fn is_path_private(&self, path: &RelPath) -> bool {
|
|
path.ancestors()
|
|
.any(|ancestor| self.private_files.is_match(ancestor.as_std_path()))
|
|
}
|
|
|
|
pub fn is_path_excluded(&self, path: &RelPath) -> bool {
|
|
path.ancestors()
|
|
.any(|ancestor| self.file_scan_exclusions.is_match(ancestor.as_std_path()))
|
|
}
|
|
|
|
pub fn is_path_always_included(&self, path: &RelPath) -> bool {
|
|
path.ancestors()
|
|
.any(|ancestor| self.file_scan_inclusions.is_match(ancestor.as_std_path()))
|
|
}
|
|
}
|
|
|
|
impl Settings for WorktreeSettings {
|
|
fn from_settings(content: &settings::SettingsContent) -> Self {
|
|
let worktree = content.project.worktree.clone();
|
|
let file_scan_exclusions = worktree.file_scan_exclusions.unwrap();
|
|
let file_scan_inclusions = worktree.file_scan_inclusions.unwrap();
|
|
let private_files = worktree.private_files.unwrap().0;
|
|
let parsed_file_scan_inclusions: Vec<String> = file_scan_inclusions
|
|
.iter()
|
|
.flat_map(|glob| {
|
|
Path::new(glob)
|
|
.ancestors()
|
|
.map(|a| a.to_string_lossy().into())
|
|
})
|
|
.filter(|p: &String| !p.is_empty())
|
|
.collect();
|
|
|
|
Self {
|
|
project_name: worktree.project_name.into_inner(),
|
|
prevent_sharing_in_public_channels: worktree.prevent_sharing_in_public_channels,
|
|
file_scan_exclusions: path_matchers(file_scan_exclusions, "file_scan_exclusions")
|
|
.log_err()
|
|
.unwrap_or_default(),
|
|
file_scan_inclusions: path_matchers(
|
|
parsed_file_scan_inclusions,
|
|
"file_scan_inclusions",
|
|
)
|
|
.unwrap(),
|
|
private_files: path_matchers(private_files, "private_files")
|
|
.log_err()
|
|
.unwrap_or_default(),
|
|
}
|
|
}
|
|
}
|
|
|
|
fn path_matchers(mut values: Vec<String>, context: &'static str) -> anyhow::Result<PathMatcher> {
|
|
values.sort();
|
|
PathMatcher::new(values, PathStyle::local())
|
|
.with_context(|| format!("Failed to parse globs from {}", context))
|
|
}
|