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