Skip to content

Commit

Permalink
Merge pull request #242 from rcos/fix-discord-join
Browse files Browse the repository at this point in the history
Fix verified role for users already in RCOS Discord. Update min rust version to 1.58.1.
  • Loading branch information
vcfxb authored Feb 3, 2022
2 parents 0449f30 + ec23629 commit dc673e7
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 21 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ please submit a pull request fixing it.
- Fixed bug in rendering of registration form. ([#222])
- User profile OGP tags ([#228])
- Added Spring 2022 RCOS proposal ([#240])
- Updated minimum rust version to 1.58.1.
- Fixed bug that missed verified role on users already in the RCOS Discord. ([#236], [#242])

## 0.8.5 - December 31st, 2021
- Changes to the config file:
Expand Down Expand Up @@ -178,4 +180,6 @@ please submit a pull request fixing it.
[#220]: https://github.com/rcos/Telescope/pull/220
[#222]: https://github.com/rcos/Telescope/pull/222
[#228]: https://github.com/rcos/Telescope/pull/228
[#236]: https://github.com/rcos/Telescope/issues/236
[#240]: https://github.com/rcos/Telescope/pull/240
[#242]: https://github.com/rcos/Telescope/pull/242
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.8.6-dev"
authors = ["Antonia \"Nia\" Calia-Bogan <[email protected]>"]
description = "The RCOS webapp"
edition = "2021"
rust-version = "1.57"
rust-version = "1.58.1"

[dependencies]
# command line argument parser
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Use latest rust (by explicit version to avoid getting a stale release)
FROM rust:1.57
FROM rust:1.58.1

# Set timezone
ENV TZ=America/New_York
Expand Down
6 changes: 1 addition & 5 deletions src/discord_bot/commands/whois.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,7 @@ async fn handle(ctx: &Context, interaction: &ApplicationCommandInteraction) -> S
// Title with the user's name
.title(format!("{} {}", u.first_name, u.last_name))
// Link to their profile
.url(format!(
"{}/user/{}",
global_config().telescope_url,
u.id
))
.url(format!("{}/user/{}", global_config().telescope_url, u.id))
// List their role inline
.field("User Role", u.role, true);

Expand Down
2 changes: 1 addition & 1 deletion src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ impl TelescopeConfig {
.expect("Could not resolve JWT secret."),
telescope_url: self
.reverse_lookup(profile_slice, |c| c.telescope_url.clone())
.expect("Could not resolve Telescope URl.")
.expect("Could not resolve Telescope URl."),
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/web/services/auth/oauth2_providers/discord.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ impl DiscordIdentity {
});
}

/// Add this user to the RCOS Discord. Set their nickname and give them the "Verified" role.
/// Add this user to the RCOS Discord. Set their nickname and give them the specified roles.
pub async fn add_to_rcos_guild(
&self,
nickname: Option<String>,
Expand Down
4 changes: 2 additions & 2 deletions src/web/services/meetings/edit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,13 @@ fn resolve_host_user_id(
) -> Option<Uuid> {
match set_host {
// If there is a specified nil UUID we want no host. Otherwise, we want the specified UUID.
Some(Query(HostQuery{ set_host })) => {
Some(Query(HostQuery { set_host })) => {
if set_host.is_nil() {
None
} else {
Some(set_host)
}
},
}

// If there is no host query then use the existing host parameter (which may be none).
None => meeting_data.host.as_ref().map(|h| h.id),
Expand Down
27 changes: 22 additions & 5 deletions src/web/services/user/join_discord.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
//! Page and service to let users into RCOS Discord and give them the verified role.
use crate::api::discord::rcos_discord_verified_role_id;
use crate::api::discord::{global_discord_client, rcos_discord_verified_role_id};
use crate::api::rcos::users::discord_whois::DiscordWhoIs;
use crate::error::TelescopeError;

use crate::env::global_config;
use crate::web::services::auth::identity::AuthenticationCookie;
use actix_web::HttpResponse;
use reqwest::header::LOCATION;
use serenity::model::prelude::RoleId;

/// Let users into the RCOS discord.
#[get("/join_discord")]
Expand Down Expand Up @@ -86,13 +88,28 @@ pub async fn handle(auth: AuthenticationCookie) -> Result<HttpResponse, Telescop
);

// Get RCOS Discord Verified role ID if possible. If not, user empty role list.
let roles = rcos_discord_verified_role_id()
let verified_role: RoleId = rcos_discord_verified_role_id()
.await?
.map(|role| vec![role])
.ok_or(TelescopeError::ise("Could not get Verified role ID."))?;

// Add user to Discord.
discord.add_to_rcos_guild(Some(nickname), roles).await?;
// Add user to Discord with verified role and nickname.
discord
.add_to_rcos_guild(Some(nickname), vec![verified_role])
.await?;

// If user was already in the discord, they may not have the verified role, and the
// previous call will do nothing. Make an additional call here to add the verified role
// to the user if they don't already have it.
// See https://github.com/rcos/Telescope/issues/236.

// Get the rcos discord guild ID.
let rcos_discord_guild = global_config().discord_config.rcos_guild_id();

// Make the call to add the verified role
global_discord_client()
.add_member_role(rcos_discord_guild, discord_user_id, verified_role.0)
.await
.map_err(TelescopeError::serenity_error)?;

// On success, redirect user back to their profile.
Ok(HttpResponse::Found()
Expand Down
8 changes: 3 additions & 5 deletions src/web/services/user/profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use crate::api::rcos::users::UserRole;
use crate::env::global_config;
use crate::error::TelescopeError;
use crate::templates::page::Page;
use crate::templates::tags::Tags;
use crate::templates::Template;
use crate::web::services::auth::identity::{AuthenticationCookie, Identity};
use actix_web::web::{Form, Path, ServiceConfig};
Expand All @@ -19,7 +20,6 @@ use serenity::model::guild::Member;
use serenity::model::user::User;
use std::collections::HashMap;
use uuid::Uuid;
use crate::templates::tags::Tags;

/// The path from the template directory to the profile template.
const TEMPLATE_NAME: &'static str = "user/profile";
Expand Down Expand Up @@ -179,7 +179,7 @@ async fn profile(

page.ogp_tags = tags;

return Ok(page)
return Ok(page);
}

/// Create a form template for the user settings page.
Expand Down Expand Up @@ -293,9 +293,7 @@ async fn save_changes(
let cohort_int = cohort.unwrap();
let year: i64 = Local::today().year() as i64;
if cohort_int < 1824 || cohort_int > year {
form["issues"]["cohort"] = json!(
format!("Year must be between 1824 and {}", year)
);
form["issues"]["cohort"] = json!(format!("Year must be between 1824 and {}", year));
}
}

Expand Down

0 comments on commit dc673e7

Please sign in to comment.