Skip to content

Commit be37bed

Browse files
committed
Fix role issue for users in RCOS Discord
1 parent 0449f30 commit be37bed

File tree

5 files changed

+26
-8
lines changed

5 files changed

+26
-8
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ please submit a pull request fixing it.
88
- Fixed bug in rendering of registration form. ([#222])
99
- User profile OGP tags ([#228])
1010
- Added Spring 2022 RCOS proposal ([#240])
11+
- Updated minimum rust version to 1.58.1.
12+
- Fixed bug that missed verified role on users already in the RCOS Discord. ([#236], #PR)
1113

1214
## 0.8.5 - December 31st, 2021
1315
- Changes to the config file:
@@ -179,3 +181,4 @@ please submit a pull request fixing it.
179181
[#222]: https://github.com/rcos/Telescope/pull/222
180182
[#228]: https://github.com/rcos/Telescope/pull/228
181183
[#240]: https://github.com/rcos/Telescope/pull/240
184+
[#236]: https://github.com/rcos/Telescope/issues/236

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ version = "0.8.6-dev"
44
authors = ["Antonia \"Nia\" Calia-Bogan <[email protected]>"]
55
description = "The RCOS webapp"
66
edition = "2021"
7-
rust-version = "1.57"
7+
rust-version = "1.58.1"
88

99
[dependencies]
1010
# command line argument parser

Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Use latest rust (by explicit version to avoid getting a stale release)
2-
FROM rust:1.57
2+
FROM rust:1.58.1
33

44
# Set timezone
55
ENV TZ=America/New_York

src/web/services/auth/oauth2_providers/discord.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ impl DiscordIdentity {
190190
});
191191
}
192192

193-
/// Add this user to the RCOS Discord. Set their nickname and give them the "Verified" role.
193+
/// Add this user to the RCOS Discord. Set their nickname and give them the specified roles.
194194
pub async fn add_to_rcos_guild(
195195
&self,
196196
nickname: Option<String>,

src/web/services/user/join_discord.rs

+20-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
//! Page and service to let users into RCOS Discord and give them the verified role.
22
3-
use crate::api::discord::rcos_discord_verified_role_id;
3+
use crate::api::discord::{global_discord_client, rcos_discord_verified_role_id};
44
use crate::api::rcos::users::discord_whois::DiscordWhoIs;
55
use crate::error::TelescopeError;
66

77
use crate::web::services::auth::identity::AuthenticationCookie;
88
use actix_web::HttpResponse;
99
use reqwest::header::LOCATION;
10+
use serenity::model::prelude::RoleId;
11+
use crate::env::global_config;
1012

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

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

94-
// Add user to Discord.
95-
discord.add_to_rcos_guild(Some(nickname), roles).await?;
95+
// Add user to Discord with verified role and nickname.
96+
discord.add_to_rcos_guild(Some(nickname), vec![verified_role]).await?;
97+
98+
// If user was already in the discord, they may not have the verified role, and the
99+
// previous call will do nothing. Make an additional call here to add the verified role
100+
// to the user if they don't already have it.
101+
// See https://github.com/rcos/Telescope/issues/236.
102+
103+
// Get the rcos discord guild ID.
104+
let rcos_discord_guild = global_config().discord_config.rcos_guild_id();
105+
106+
// Make the call to add the verified role
107+
global_discord_client()
108+
.add_member_role(rcos_discord_guild, discord_user_id, verified_role.0)
109+
.await
110+
.map_err(TelescopeError::serenity_error)?;
96111

97112
// On success, redirect user back to their profile.
98113
Ok(HttpResponse::Found()

0 commit comments

Comments
 (0)