Skip to content

Commit

Permalink
Merge branch 'main' into CHAOS-204-new-question-types-framework
Browse files Browse the repository at this point in the history
  • Loading branch information
KavikaPalletenne authored Oct 2, 2023
2 parents c3d4053 + b5a0a53 commit 1b9b43f
Show file tree
Hide file tree
Showing 27 changed files with 10,602 additions and 1,651 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-latest
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
submodules: true
token: ${{ secrets.GH_TOKEN }}
Expand Down Expand Up @@ -62,7 +62,7 @@ jobs:
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
with:
Expand Down Expand Up @@ -100,7 +100,7 @@ jobs:
url: https://chaos.staging.csesoc.unsw.edu.au
steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
repository: csesoc/deployment
token: ${{ secrets.GH_TOKEN }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Mock an env file
run: |
echo "DATABASE_URL=test_url" >> backend/.env
Expand Down
4 changes: 4 additions & 0 deletions backend/migrations/2023-06-07-042751_user_gender/down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ALTER TABLE users
DROP COLUMN gender;

DROP TYPE user_gender;
4 changes: 4 additions & 0 deletions backend/migrations/2023-06-07-042751_user_gender/up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
CREATE TYPE user_gender AS ENUM ('Female', 'Male', 'Unspecified');

ALTER TABLE users
ADD COLUMN gender user_gender DEFAULT 'Unspecified' NOT NULL;
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;
47 changes: 40 additions & 7 deletions backend/seed_data/src/seed.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![allow(unused_variables)]

use backend::database::models::*;
use backend::database::schema::{AdminLevel, ApplicationStatus, QuestionType};
use backend::database::schema::{AdminLevel, ApplicationStatus, UserGender, QuestionType};
use backend::images::{save_image, try_decode_bytes};
use chrono::naive::NaiveDate;
use diesel::pg::PgConnection;
Expand All @@ -24,6 +24,8 @@ pub fn seed() {
display_name: "Shrey Somaiya".to_string(),
degree_name: "B. CompSci".to_string(),
degree_starting_year: 2019,
gender: UserGender::Unspecified,
pronouns: "they/them".to_string(),
superuser: true,
},
NewUser {
Expand All @@ -32,6 +34,8 @@ pub fn seed() {
display_name: "Fake User".to_string(),
degree_name: "B. CompSci".to_string(),
degree_starting_year: 2019,
gender: UserGender::Unspecified,
pronouns: "".to_string(),
superuser: false,
},
NewUser {
Expand All @@ -40,6 +44,8 @@ pub fn seed() {
display_name: "Michael Gribben".to_string(),
degree_name: "B. Eng (Software)".to_string(),
degree_starting_year: 2019,
gender: UserGender::Male,
pronouns: "he/him".to_string(),
superuser: false,
},
NewUser {
Expand All @@ -48,6 +54,8 @@ pub fn seed() {
display_name: "Giuliana Debellis".to_string(),
degree_name: "B. CompSci".to_string(),
degree_starting_year: 2020,
gender: UserGender::Female,
pronouns: "she/her".to_string(),
superuser: false,
},
NewUser {
Expand All @@ -56,6 +64,8 @@ pub fn seed() {
display_name: "Lachlan Ting".to_string(),
degree_name: "B. CompSci".to_string(),
degree_starting_year: 2019,
gender: UserGender::Male,
pronouns: "he/him".to_string(),
superuser: false,
},
NewUser {
Expand All @@ -64,6 +74,8 @@ pub fn seed() {
display_name: "Hayes Choi".to_string(),
degree_name: "B. CompSci".to_string(),
degree_starting_year: 2020,
gender: UserGender::Male,
pronouns: "he/him".to_string(),
superuser: false,
},
NewUser {
Expand All @@ -72,6 +84,8 @@ pub fn seed() {
display_name: "Clarence Feng".to_string(),
degree_name: "B. CompSci".to_string(),
degree_starting_year: 2020,
gender: UserGender::Male,
pronouns: "he/him".to_string(),
superuser: false,
},
];
Expand All @@ -86,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 Down Expand Up @@ -144,8 +170,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
5 changes: 5 additions & 0 deletions backend/server/src/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::error::JsonErr;
use crate::{
database::{
models::{NewUser, User},
schema::UserGender,
Database,
},
state::ApiState,
Expand Down Expand Up @@ -279,6 +280,8 @@ pub struct SignUpBody {
display_name: String,
degree_name: String,
degree_starting_year: u32,
gender: UserGender,
pronouns: String,
}

#[derive(Serialize)]
Expand Down Expand Up @@ -347,6 +350,8 @@ pub async fn signup(
display_name: body.display_name.to_string(),
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
7 changes: 5 additions & 2 deletions backend/server/src/database/models.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
use crate::question_types::QuestionData;
use crate::images::{get_http_image_path, ImageLocation};

use super::schema::AdminLevel;
use super::schema::ApplicationStatus;
use super::schema::{
answers, applications, campaigns, comments, organisation_users, organisations, questions,
ratings, roles, users, multi_select_answers, multi_select_options, short_answer_answers
};
use super::schema::{AdminLevel, ApplicationStatus, UserGender};
use chrono::NaiveDateTime;
use chrono::Utc;
use diesel::prelude::*;
Expand All @@ -26,6 +25,8 @@ pub struct User {
pub display_name: String,
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 All @@ -52,6 +53,8 @@ pub struct NewUser {
pub display_name: String,
pub degree_name: String,
pub degree_starting_year: i32,
pub gender: UserGender,
pub pronouns: String,
pub superuser: bool,
}

Expand Down
12 changes: 12 additions & 0 deletions backend/server/src/database/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ impl AdminLevel {
}
}

#[derive(Debug, DbEnum, PartialEq, Serialize, Deserialize, Clone, Copy)]
#[DbValueStyle = "PascalCase"]
pub enum UserGender {
Female,
Male,
Unspecified,
}

table! {
use diesel::sql_types::*;
use super::QuestionTypeMapping;
Expand Down Expand Up @@ -188,13 +196,17 @@ table! {
}

table! {
use super::UserGenderMapping;

users (id) {
id -> Int4,
email -> Text,
zid -> Text,
display_name -> Text,
degree_name -> Text,
degree_starting_year -> Int4,
gender -> UserGenderMapping,
pronouns -> Text,
superuser -> Bool,
created_at -> Timestamp,
updated_at -> Timestamp,
Expand Down
Loading

0 comments on commit 1b9b43f

Please sign in to comment.