@@ -12,7 +12,7 @@ use crate::Session;
12
12
pub enum Error {
13
13
OnlyCreatorCanCloseChannel ,
14
14
ChannelIsExpired ,
15
- ChannelIsPastWithdrawPeriod ,
15
+ ChannelIsInWithdrawPeriod ,
16
16
RulesError ( String ) ,
17
17
}
18
18
@@ -28,21 +28,28 @@ pub async fn check_access(
28
28
Event :: Close => true ,
29
29
_ => false ,
30
30
} ;
31
-
32
- // Check basic access rules
33
- // only the creator can send a CLOSE
34
- if session. uid != channel. creator && events. iter ( ) . any ( is_close_event) {
35
- return Err ( Error :: OnlyCreatorCanCloseChannel ) ;
36
- }
37
-
38
31
let current_time = Utc :: now ( ) ;
32
+ let is_in_withdraw_period = current_time > channel. spec . withdraw_period_start ;
39
33
40
34
if current_time > channel. valid_until {
41
35
return Err ( Error :: ChannelIsExpired ) ;
42
36
}
43
37
44
- if current_time > channel. spec . withdraw_period_start && !events. iter ( ) . all ( is_close_event) {
45
- return Err ( Error :: ChannelIsPastWithdrawPeriod ) ;
38
+ // We're only sending a CLOSE
39
+ // That's allowed for the creator normally, and for everyone during the withdraw period
40
+ if events. iter ( ) . all ( is_close_event)
41
+ && ( session. uid == channel. creator || is_in_withdraw_period)
42
+ {
43
+ return Ok ( ( ) ) ;
44
+ }
45
+
46
+ // Only the creator can send a CLOSE
47
+ if session. uid != channel. creator && events. iter ( ) . any ( is_close_event) {
48
+ return Err ( Error :: OnlyCreatorCanCloseChannel ) ;
49
+ }
50
+
51
+ if is_in_withdraw_period {
52
+ return Err ( Error :: ChannelIsInWithdrawPeriod ) ;
46
53
}
47
54
48
55
let default_rules = [
0 commit comments