Skip to content

Commit

Permalink
dev(feat): User gender and pronouns (#452)
Browse files Browse the repository at this point in the history
* feat: wrote DB migration for user gender

* fix: removed 'Other' gender

* feat: fully implemented user gender in backend

* fix: set user gender to non-nullable

* dev(frontend): added pronouns and gender field on signup

* fix: re-arranged gender options

* fix: user signup works with gender

* feat: implemented pronouns in backend

* feat: implemented user pronouns in frontend

* fix: installed nodejs packages

---------

Co-authored-by: m4ch374 <[email protected]>
  • Loading branch information
dhj03 and m4ch374 authored Sep 20, 2023
1 parent 3ebf36e commit ca22d34
Show file tree
Hide file tree
Showing 11 changed files with 10,292 additions and 1,675 deletions.
2 changes: 2 additions & 0 deletions backend/migrations/2023-09-20-052638_user_pronouns/down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE users
DROP COLUMN pronouns;
2 changes: 2 additions & 0 deletions backend/migrations/2023-09-20-052638_user_pronouns/up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE users
ADD COLUMN pronouns TEXT DEFAULT '' NOT NULL;
42 changes: 35 additions & 7 deletions backend/seed_data/src/seed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pub fn seed() {
degree_name: "B. CompSci".to_string(),
degree_starting_year: 2019,
gender: UserGender::Unspecified,
pronouns: "they/them".to_string(),
superuser: true,
},
NewUser {
Expand All @@ -34,6 +35,7 @@ pub fn seed() {
degree_name: "B. CompSci".to_string(),
degree_starting_year: 2019,
gender: UserGender::Unspecified,
pronouns: "".to_string(),
superuser: false,
},
NewUser {
Expand All @@ -43,6 +45,7 @@ pub fn seed() {
degree_name: "B. Eng (Software)".to_string(),
degree_starting_year: 2019,
gender: UserGender::Male,
pronouns: "he/him".to_string(),
superuser: false,
},
NewUser {
Expand All @@ -52,6 +55,7 @@ pub fn seed() {
degree_name: "B. CompSci".to_string(),
degree_starting_year: 2020,
gender: UserGender::Female,
pronouns: "she/her".to_string(),
superuser: false,
},
NewUser {
Expand All @@ -61,6 +65,7 @@ pub fn seed() {
degree_name: "B. CompSci".to_string(),
degree_starting_year: 2019,
gender: UserGender::Male,
pronouns: "he/him".to_string(),
superuser: false,
},
NewUser {
Expand All @@ -70,6 +75,7 @@ pub fn seed() {
degree_name: "B. CompSci".to_string(),
degree_starting_year: 2020,
gender: UserGender::Male,
pronouns: "he/him".to_string(),
superuser: false,
},
NewUser {
Expand All @@ -79,6 +85,7 @@ pub fn seed() {
degree_name: "B. CompSci".to_string(),
degree_starting_year: 2020,
gender: UserGender::Male,
pronouns: "he/him".to_string(),
superuser: false,
},
];
Expand All @@ -93,10 +100,22 @@ pub fn seed() {
// create two organisations
let csesoc_org_logo_id = "d6b7b23d-064b-40f2-9b73-9a4cd32ee9c6";
let degrees_org_logo_id = "adebf7f3-aa1e-4712-b5ca-051430bfaf8e";
let csesoc_org_logo = try_decode_bytes(std::fs::read("./assets/csesoc_logo.png").unwrap()).expect("./assets/csesoc_logo.png missing!");
let degrees_org_logo = try_decode_bytes(std::fs::read("./assets/180DC.png").unwrap()).expect("./assets/180DC.png missing!");
save_image(csesoc_org_logo, backend::images::ImageLocation::ORGANISATIONS, csesoc_org_logo_id).expect("Failed saving CSESoc Logo");
save_image(degrees_org_logo, backend::images::ImageLocation::ORGANISATIONS, degrees_org_logo_id).expect("Failed saving 180DC Logo");
let csesoc_org_logo = try_decode_bytes(std::fs::read("./assets/csesoc_logo.png").unwrap())
.expect("./assets/csesoc_logo.png missing!");
let degrees_org_logo = try_decode_bytes(std::fs::read("./assets/180DC.png").unwrap())
.expect("./assets/180DC.png missing!");
save_image(
csesoc_org_logo,
backend::images::ImageLocation::ORGANISATIONS,
csesoc_org_logo_id,
)
.expect("Failed saving CSESoc Logo");
save_image(
degrees_org_logo,
backend::images::ImageLocation::ORGANISATIONS,
degrees_org_logo_id,
)
.expect("Failed saving 180DC Logo");

let orgs = vec![
NewOrganisation {
Expand All @@ -114,7 +133,9 @@ pub fn seed() {
.expect(&format!("Failed to insert org {}.", org.name));
}

assert!(Organisation::get_all(&connection).len() == 2);
let x = Organisation::get_all(&connection);
println!("{:?}", x);
assert!(x.len() == 2);

println!("... Added {} organizations\n", orgs.len());
// make giuliana the admin of csesoc
Expand Down Expand Up @@ -151,8 +172,15 @@ pub fn seed() {
// create peer mentoring campaign for csesoc

let peer_mentoring_logo_id = "523fde49-027a-4fc8-b296-aaefe9e215d6";
let peer_mentoring_logo = try_decode_bytes(std::fs::read("./assets/csesoc_peer_mentoring.jpg").unwrap()).expect("./assets/csesoc_peer_mentoring.jpg missing!");
save_image(peer_mentoring_logo, backend::images::ImageLocation::CAMPAIGNS, peer_mentoring_logo_id).expect("Failed saving Peer Mentoring Logo");
let peer_mentoring_logo =
try_decode_bytes(std::fs::read("./assets/csesoc_peer_mentoring.jpg").unwrap())
.expect("./assets/csesoc_peer_mentoring.jpg missing!");
save_image(
peer_mentoring_logo,
backend::images::ImageLocation::CAMPAIGNS,
peer_mentoring_logo_id,
)
.expect("Failed saving Peer Mentoring Logo");

let new_campaign = NewCampaign {
name: "2022 Peer Mentor Recruitment".to_string(),
Expand Down
4 changes: 3 additions & 1 deletion backend/server/src/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::error::JsonErr;
use crate::{
database::{
models::{NewUser, User},
schema::{UserGender},
schema::UserGender,
Database,
},
state::ApiState,
Expand Down Expand Up @@ -281,6 +281,7 @@ pub struct SignUpBody {
degree_name: String,
degree_starting_year: u32,
gender: UserGender,
pronouns: String,
}

#[derive(Serialize)]
Expand Down Expand Up @@ -350,6 +351,7 @@ pub async fn signup(
degree_name: body.degree_name.to_string(),
degree_starting_year: body.degree_starting_year as i32,
gender: body.gender,
pronouns: body.pronouns.to_string(),
superuser: User::get_number(conn) == 0,
};

Expand Down
4 changes: 3 additions & 1 deletion backend/server/src/database/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ pub struct User {
pub degree_name: String,
pub degree_starting_year: i32,
pub gender: UserGender,
pub pronouns: String,
pub superuser: bool,
pub created_at: NaiveDateTime,
pub updated_at: NaiveDateTime,
Expand Down Expand Up @@ -51,6 +52,7 @@ pub struct NewUser {
pub degree_name: String,
pub degree_starting_year: i32,
pub gender: UserGender,
pub pronouns: String,
pub superuser: bool,
}

Expand Down Expand Up @@ -150,7 +152,7 @@ impl NewUser {
}
}

#[derive(Queryable, Serialize, Deserialize)]
#[derive(Queryable, Serialize, Deserialize, Debug)]
pub struct Organisation {
pub id: i32,
pub name: String,
Expand Down
1 change: 1 addition & 0 deletions backend/server/src/database/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ table! {
degree_name -> Text,
degree_starting_year -> Int4,
gender -> UserGenderMapping,
pronouns -> Text,
superuser -> Bool,
created_at -> Timestamp,
updated_at -> Timestamp,
Expand Down
174 changes: 174 additions & 0 deletions backend/server/src/src/database/schema.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
// @generated automatically by Diesel CLI.

pub mod sql_types {
#[derive(diesel::sql_types::SqlType)]
#[diesel(postgres_type(name = "admin_level"))]
pub struct AdminLevel;

#[derive(diesel::sql_types::SqlType)]
#[diesel(postgres_type(name = "application_status"))]
pub struct ApplicationStatus;

#[derive(diesel::sql_types::SqlType)]
#[diesel(postgres_type(name = "user_gender"))]
pub struct UserGender;
}

diesel::table! {
answers (id) {
id -> Int4,
application_id -> Int4,
question_id -> Int4,
description -> Text,
created_at -> Timestamp,
updated_at -> Timestamp,
}
}

diesel::table! {
use diesel::sql_types::*;
use super::sql_types::ApplicationStatus;

applications (id) {
id -> Int4,
user_id -> Int4,
role_id -> Int4,
status -> ApplicationStatus,
created_at -> Timestamp,
updated_at -> Timestamp,
private_status -> Nullable<ApplicationStatus>,
}
}

diesel::table! {
campaigns (id) {
id -> Int4,
organisation_id -> Int4,
name -> Text,
cover_image -> Nullable<Text>,
description -> Text,
starts_at -> Timestamp,
ends_at -> Timestamp,
published -> Bool,
created_at -> Timestamp,
updated_at -> Timestamp,
}
}

diesel::table! {
comments (id) {
id -> Int4,
application_id -> Int4,
commenter_user_id -> Int4,
description -> Text,
created_at -> Timestamp,
updated_at -> Timestamp,
}
}

diesel::table! {
use diesel::sql_types::*;
use super::sql_types::AdminLevel;

organisation_users (id) {
id -> Int4,
user_id -> Int4,
organisation_id -> Int4,
admin_level -> AdminLevel,
created_at -> Timestamp,
updated_at -> Timestamp,
}
}

diesel::table! {
organisations (id) {
id -> Int4,
name -> Text,
logo -> Nullable<Text>,
created_at -> Timestamp,
updated_at -> Timestamp,
}
}

diesel::table! {
questions (id) {
id -> Int4,
role_ids -> Array<Nullable<Int4>>,
title -> Text,
description -> Nullable<Text>,
max_bytes -> Int4,
required -> Bool,
created_at -> Timestamp,
updated_at -> Timestamp,
}
}

diesel::table! {
ratings (id) {
id -> Int4,
application_id -> Int4,
rater_user_id -> Int4,
rating -> Int4,
created_at -> Timestamp,
updated_at -> Timestamp,
}
}

diesel::table! {
roles (id) {
id -> Int4,
campaign_id -> Int4,
name -> Text,
description -> Nullable<Text>,
min_available -> Int4,
max_available -> Int4,
finalised -> Bool,
created_at -> Timestamp,
updated_at -> Timestamp,
}
}

diesel::table! {
use diesel::sql_types::*;
use super::sql_types::UserGender;

users (id) {
id -> Int4,
email -> Text,
zid -> Text,
display_name -> Text,
degree_name -> Text,
degree_starting_year -> Int4,
superuser -> Bool,
created_at -> Timestamp,
updated_at -> Timestamp,
gender -> UserGender,
pronouns -> Text,
}
}

diesel::joinable!(answers -> applications (application_id));
diesel::joinable!(answers -> questions (question_id));
diesel::joinable!(applications -> roles (role_id));
diesel::joinable!(applications -> users (user_id));
diesel::joinable!(campaigns -> organisations (organisation_id));
diesel::joinable!(comments -> applications (application_id));
diesel::joinable!(comments -> users (commenter_user_id));
diesel::joinable!(organisation_users -> organisations (organisation_id));
diesel::joinable!(organisation_users -> users (user_id));
diesel::joinable!(ratings -> applications (application_id));
diesel::joinable!(ratings -> users (rater_user_id));
diesel::joinable!(roles -> campaigns (campaign_id));

diesel::allow_tables_to_appear_in_same_query!(
answers,
applications,
campaigns,
comments,
organisation_users,
organisations,
questions,
ratings,
roles,
users,
);
Loading

0 comments on commit ca22d34

Please sign in to comment.