Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 39 additions & 3 deletions crates/openplotva-app/src/permissions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ use std::{
use openplotva_core::{ChatSettings, ChatSettingsUpdate};
use openplotva_server::{
ACTION_EDIT_MESSAGE, ACTION_SEND_AUDIO, ACTION_SEND_IMAGE, ACTION_SEND_STICKER,
ACTION_SEND_TEXT, can_perform_action, permission_cache_key, permission_error_chat_type,
permission_error_settings_update,
ACTION_SEND_TEXT, ACTION_SEND_VIDEO, can_perform_action, permission_cache_key,
permission_error_chat_type, permission_error_settings_update,
};
use openplotva_telegram::{TelegramOutboundMethodKind, classify_telegram_send_error};
use time::OffsetDateTime;
Expand Down Expand Up @@ -135,6 +135,7 @@ impl<S> ChatPermissionPolicy<S> {
ACTION_SEND_IMAGE,
ACTION_SEND_STICKER,
ACTION_SEND_AUDIO,
ACTION_SEND_VIDEO,
] {
cache.remove(&permission_cache_key(chat_id, action));
}
Expand Down Expand Up @@ -348,7 +349,9 @@ mod tests {
};

use openplotva_core::{ChatSettings, ChatSettingsUpdate};
use openplotva_server::{ACTION_EDIT_MESSAGE, ACTION_SEND_STICKER, ACTION_SEND_TEXT};
use openplotva_server::{
ACTION_EDIT_MESSAGE, ACTION_SEND_STICKER, ACTION_SEND_TEXT, ACTION_SEND_VIDEO,
};
use openplotva_telegram::TelegramOutboundMethodKind;
use time::OffsetDateTime;

Expand Down Expand Up @@ -443,6 +446,39 @@ mod tests {
Ok(())
}

#[tokio::test]
async fn video_follows_the_group_draw_setting_and_invalidates_with_it()
-> Result<(), Box<dyn Error>> {
let now = OffsetDateTime::from_unix_timestamp(1_710_000_000)?;
let group = |enable_global_draw_reply| {
PermissionStoreStub::with_context(ChatPermissionContext {
chat_type: Some("supergroup".to_owned()),
settings: Some(ChatSettings {
enable_global_draw_reply,
..ChatSettings::defaults(42)
}),
})
};
let drawing = ChatPermissionPolicy::new(group(true));
let silent = ChatPermissionPolicy::new(group(false));

let allowed = drawing
.can_perform_action_at(42, None, ACTION_SEND_VIDEO, now)
.await;
drawing.invalidate_chat(42);
let reloaded = drawing
.can_perform_action_at(42, None, ACTION_SEND_VIDEO, now)
.await;
let refused = silent
.can_perform_action_at(42, None, ACTION_SEND_VIDEO, now)
.await;

assert!(allowed.allowed);
assert_eq!(reloaded.source, PermissionCheckSource::Store);
assert!(!refused.allowed);
Ok(())
}

#[tokio::test]
async fn policy_records_permission_error_update_and_invalidates_like_go()
-> Result<(), Box<dyn Error>> {
Expand Down
9 changes: 7 additions & 2 deletions crates/openplotva-server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@ pub fn can_perform_action(chat_type: &str, settings: Option<&ChatSettings>, acti
ACTION_SEND_TEXT | ACTION_EDIT_MESSAGE | ACTION_SEND_MESSAGE => {
settings.enable_global_text_reply
}
ACTION_SEND_IMAGE | ACTION_SEND_STICKER | ACTION_SEND_AUDIO => {
ACTION_SEND_IMAGE | ACTION_SEND_STICKER | ACTION_SEND_AUDIO | ACTION_SEND_VIDEO => {
settings.enable_global_draw_reply
}
_ => false,
Expand Down Expand Up @@ -3174,11 +3174,16 @@ mod tests {
Some(&draw_only),
ACTION_SEND_STICKER
));
assert!(!can_perform_action(
assert!(can_perform_action(
"supergroup",
Some(&draw_only),
ACTION_SEND_VIDEO
));
assert!(!can_perform_action(
"supergroup",
Some(&disabled),
ACTION_SEND_VIDEO
));
}

#[test]
Expand Down