@@ -3,10 +3,7 @@ use crate::{
3
3
config:: Config ,
4
4
network:: { DnsResolver , EmailTransport , TokioDnsResolver } ,
5
5
server:: { Status , StatusLevel } ,
6
- users:: User ,
7
6
} ;
8
- use actix_web:: { error:: ErrorForbidden , Error } ;
9
- use anyhow:: anyhow;
10
7
use lettre:: { AsyncSmtpTransport , Tokio1Executor } ;
11
8
use std:: sync:: { Arc , RwLock } ;
12
9
@@ -30,15 +27,6 @@ impl<DR: DnsResolver, ET: EmailTransport> AppState<DR, ET> {
30
27
api,
31
28
}
32
29
}
33
-
34
- /// Ensures that the user is an admin, otherwise returns an error (`403`).
35
- pub fn ensure_admin ( & self , user : & User ) -> Result < ( ) , Error > {
36
- if user. subscription . get_features ( & self . config ) . admin {
37
- Ok ( ( ) )
38
- } else {
39
- Err ( ErrorForbidden ( anyhow ! ( "Forbidden" ) ) )
40
- }
41
- }
42
30
}
43
31
44
32
#[ cfg( test) ]
@@ -49,14 +37,11 @@ pub mod tests {
49
37
network:: { Network , TokioDnsResolver } ,
50
38
server:: AppState ,
51
39
templates:: create_templates,
52
- tests:: { mock_config, mock_network, mock_search_index, mock_user, MockUserBuilder } ,
53
- users:: { SubscriptionTier , UserSubscription } ,
40
+ tests:: { mock_config, mock_search_index} ,
54
41
} ;
55
- use insta:: assert_debug_snapshot;
56
42
use lettre:: { AsyncSmtpTransport , Tokio1Executor } ;
57
43
use sqlx:: PgPool ;
58
44
use std:: sync:: Arc ;
59
- use time:: OffsetDateTime ;
60
45
61
46
pub async fn mock_app_state ( pool : PgPool ) -> anyhow:: Result < AppState > {
62
47
let config = mock_config ( ) ?;
@@ -75,43 +60,4 @@ pub mod tests {
75
60
76
61
Ok ( AppState :: new ( api. config . clone ( ) , api) )
77
62
}
78
-
79
- #[ sqlx:: test]
80
- async fn can_detect_admin ( pool : PgPool ) -> anyhow:: Result < ( ) > {
81
- let config = mock_config ( ) ?;
82
- let api = Arc :: new ( Api :: new (
83
- config,
84
- Database :: create ( pool) . await ?,
85
- mock_search_index ( ) ?,
86
- mock_network ( ) ,
87
- create_templates ( ) ?,
88
- ) ) ;
89
-
90
- let state = AppState :: new ( api. config . clone ( ) , api) ;
91
-
92
- let user = mock_user ( ) ?;
93
- assert ! ( state. ensure_admin( & user) . is_ok( ) ) ;
94
-
95
- let user = MockUserBuilder :: new (
96
- user. id ,
97
- & format ! ( "dev-{}@secutils.dev" , * user. id) ,
98
- & format ! ( "dev-handle-{}" , * user. id) ,
99
- OffsetDateTime :: now_utc ( ) ,
100
- )
101
- . set_subscription ( UserSubscription {
102
- tier : SubscriptionTier :: Professional ,
103
- started_at : OffsetDateTime :: now_utc ( ) ,
104
- ends_at : None ,
105
- trial_started_at : Some ( OffsetDateTime :: now_utc ( ) ) ,
106
- trial_ends_at : None ,
107
- } )
108
- . build ( ) ;
109
-
110
- assert_debug_snapshot ! (
111
- state. ensure_admin( & user) . unwrap_err( ) ,
112
- @"Forbidden"
113
- ) ;
114
-
115
- Ok ( ( ) )
116
- }
117
63
}
0 commit comments