Checks if a user can deploy a station.
(&self, ctx: &CallContext)
| 163 | |
| 164 | /// Checks if a user can deploy a station. |
| 165 | pub fn can_deploy_station(&self, ctx: &CallContext) -> ServiceResult<CanDeployStation> { |
| 166 | let user = self.get_user_by_identity(&ctx.caller(), ctx)?; |
| 167 | let config = canister_config().ok_or(DeployError::Failed { |
| 168 | reason: "Canister config not initialized.".to_string(), |
| 169 | })?; |
| 170 | |
| 171 | let allowed_globally = match config.global_rate_limiter.can_deploy_station() { |
| 172 | CanDeployStation::Allowed(remaining) => remaining, |
| 173 | CanDeployStation::QuotaExceeded => return Ok(CanDeployStation::QuotaExceeded), |
| 174 | CanDeployStation::NotAllowed(subscription_status) => { |
| 175 | return Ok(CanDeployStation::NotAllowed(subscription_status)) |
| 176 | } |
| 177 | }; |
| 178 | |
| 179 | let allowed_per_user = match user.can_deploy_station() { |
| 180 | CanDeployStation::Allowed(remaining) => remaining, |
| 181 | CanDeployStation::QuotaExceeded => return Ok(CanDeployStation::QuotaExceeded), |
| 182 | CanDeployStation::NotAllowed(subscription_status) => { |
| 183 | return Ok(CanDeployStation::NotAllowed(subscription_status)) |
| 184 | } |
| 185 | }; |
| 186 | |
| 187 | Ok(CanDeployStation::Allowed(std::cmp::min( |
| 188 | allowed_globally, |
| 189 | allowed_per_user, |
| 190 | ))) |
| 191 | } |
| 192 | |
| 193 | /// Checks if the caller has access to the given user. |
| 194 | /// |
no test coverage detected