Extract Instance::create_local_instance_user() from get_local_instance_user_uncached()
This commit is contained in:
		
							parent
							
								
									2f7a5cbf56
								
							
						
					
					
						commit
						af5b0b961b
					
				| @ -80,16 +80,7 @@ impl Instance { | ||||
|             .map_err(Error::from) | ||||
|     } | ||||
| 
 | ||||
|     pub fn get_local_instance_user() -> Option<&'static User> { | ||||
|         LOCAL_INSTANCE_USER.get() | ||||
|     } | ||||
| 
 | ||||
|     pub fn get_local_instance_user_uncached(conn: &Connection) -> Result<User> { | ||||
|         users::table | ||||
|             .filter(users::role.eq(3)) | ||||
|             .first(conn) | ||||
|             .or_else(|err| match err { | ||||
|                 NotFound => { | ||||
|     pub fn create_local_instance_user(conn: &Connection) -> Result<User> { | ||||
|         let instance = Instance::get_local().expect("Failed to get local instance"); | ||||
|         let email = format!("{}@{}", LOCAL_INSTANCE_USERNAME, &instance.public_domain); | ||||
|         NewUser::new_local( | ||||
| @ -102,6 +93,17 @@ impl Instance { | ||||
|             None, | ||||
|         ) | ||||
|     } | ||||
| 
 | ||||
|     pub fn get_local_instance_user() -> Option<&'static User> { | ||||
|         LOCAL_INSTANCE_USER.get() | ||||
|     } | ||||
| 
 | ||||
|     pub fn get_local_instance_user_uncached(conn: &Connection) -> Result<User> { | ||||
|         users::table | ||||
|             .filter(users::role.eq(3)) | ||||
|             .first(conn) | ||||
|             .or_else(|err| match err { | ||||
|                 NotFound => Self::create_local_instance_user(conn), | ||||
|                 _ => Err(Error::Db(err)), | ||||
|             }) | ||||
|     } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user