Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

Commit

Permalink
revs
Browse files Browse the repository at this point in the history
  • Loading branch information
thesuzerain committed Oct 16, 2023
1 parent ee81e7a commit 466dfac
Show file tree
Hide file tree
Showing 14 changed files with 1,173 additions and 1,032 deletions.
23 changes: 9 additions & 14 deletions src/models/teams.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ bitflags::bitflags! {
const DELETE_PROJECT = 1 << 7;
const VIEW_ANALYTICS = 1 << 8;
const VIEW_PAYOUTS = 1 << 9;

const ALL = 0b1111111111;
}
}

Expand All @@ -55,14 +53,13 @@ impl ProjectPermissions {
organization_team_member: &Option<crate::database::models::TeamMember>, // team member of the user in the organization
) -> Option<Self> {
if role.is_admin() {
return Some(ProjectPermissions::ALL);
return Some(ProjectPermissions::all());
}

if let Some(member) = project_team_member {
if member.accepted {
return Some(member.permissions);
}
return Some(member.permissions);
}

if let Some(member) = organization_team_member {
Expand All @@ -87,15 +84,13 @@ bitflags::bitflags! {
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub struct OrganizationPermissions: u64 {
const EDIT_DETAILS = 1 << 0;
const UNUSED = 1 << 1; // a currently unused permission, formerly EDIT_BODY
const MANAGE_INVITES = 1 << 2;
const REMOVE_MEMBER = 1 << 3;
const EDIT_MEMBER = 1 << 4;
const ADD_PROJECT = 1 << 5;
const REMOVE_PROJECT = 1 << 6;
const DELETE_ORGANIZATION = 1 << 8;
const EDIT_MEMBER_DEFAULT_PERMISSIONS = 1 << 9; // Separate from EDIT_MEMBER
const ALL = 0b1111111111;
const MANAGE_INVITES = 1 << 1;
const REMOVE_MEMBER = 1 << 2;
const EDIT_MEMBER = 1 << 3;
const ADD_PROJECT = 1 << 4;
const REMOVE_PROJECT = 1 << 5;
const DELETE_ORGANIZATION = 1 << 6;
const EDIT_MEMBER_DEFAULT_PERMISSIONS = 1 << 7; // Separate from EDIT_MEMBER
const NONE = 0b0;
}
}
Expand All @@ -114,7 +109,7 @@ impl OrganizationPermissions {
team_member: &Option<crate::database::models::TeamMember>,
) -> Option<Self> {
if role.is_admin() {
return Some(OrganizationPermissions::ALL);
return Some(OrganizationPermissions::all());
}

if let Some(member) = team_member {
Expand Down
4 changes: 2 additions & 2 deletions src/routes/v2/organizations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ pub async fn organization_create(
members: vec![team_item::TeamMemberBuilder {
user_id: current_user.id.into(),
role: crate::models::teams::OWNER_ROLE.to_owned(),
permissions: ProjectPermissions::ALL,
organization_permissions: Some(OrganizationPermissions::ALL),
permissions: ProjectPermissions::all(),
organization_permissions: Some(OrganizationPermissions::all()),
accepted: true,
payouts_split: Decimal::ONE_HUNDRED,
ordering: 0,
Expand Down
133 changes: 75 additions & 58 deletions tests/common/dummy_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,32 +43,45 @@ pub enum DummyImage {

#[derive(Clone)]
pub struct DummyData {
pub project_alpha: DummyProjectAlpha,
pub project_beta: DummyProjectBeta,
pub organization_zeta: DummyOrganizationZeta,
}

#[derive(Clone)]
pub struct DummyProjectAlpha {
// Alpha project:
// This is a dummy project created by USER user.
// It's approved, listed, and visible to the public.
pub alpha_project_id: String,
pub alpha_project_slug: String,
pub alpha_version_id: String,
pub alpha_thread_id: String,
pub alpha_file_hash: String,
pub alpha_team_id: String,
pub project_id: String,
pub project_slug: String,
pub version_id: String,
pub thread_id: String,
pub file_hash: String,
pub team_id: String,
}

#[derive(Clone)]
pub struct DummyProjectBeta {
// Beta project:
// This is a dummy project created by USER user.
// It's not approved, unlisted, and not visible to the public.
pub beta_project_id: String,
pub beta_project_slug: String,
pub beta_version_id: String,
pub beta_thread_id: String,
pub beta_file_hash: String,
pub beta_team_id: String,
pub project_id: String,
pub project_slug: String,
pub version_id: String,
pub thread_id: String,
pub file_hash: String,
pub team_id: String,
}

#[derive(Clone)]
pub struct DummyOrganizationZeta {
// Zeta organization:
// This is a dummy organization created by USER user.
// There are no projects in it.
pub zeta_organization_id: String,
pub zeta_organization_title: String,
pub zeta_team_id: String,
pub organization_id: String,
pub organization_title: String,
pub team_id: String,
}

pub async fn add_dummy_data(test_env: &TestEnvironment) -> DummyData {
Expand All @@ -88,34 +101,36 @@ pub async fn add_dummy_data(test_env: &TestEnvironment) -> DummyData {

let zeta_organization = add_organization_zeta(test_env).await;

sqlx::query("INSERT INTO dummy_data (version) VALUES ($1)")
sqlx::query("INSERT INTO dummy_data (update_id) VALUES ($1)")
.bind(DUMMY_DATA_UPDATE)
.execute(pool)
.await
.unwrap();

DummyData {
alpha_team_id: alpha_project.team.to_string(),
beta_team_id: beta_project.team.to_string(),

alpha_project_id: alpha_project.id.to_string(),
beta_project_id: beta_project.id.to_string(),

alpha_project_slug: alpha_project.slug.unwrap(),
beta_project_slug: beta_project.slug.unwrap(),

alpha_version_id: alpha_version.id.to_string(),
beta_version_id: beta_version.id.to_string(),

alpha_thread_id: alpha_project.thread_id.to_string(),
beta_thread_id: beta_project.thread_id.to_string(),

alpha_file_hash: alpha_version.files[0].hashes["sha1"].clone(),
beta_file_hash: beta_version.files[0].hashes["sha1"].clone(),

zeta_organization_id: zeta_organization.id.to_string(),
zeta_team_id: zeta_organization.team_id.to_string(),
zeta_organization_title: zeta_organization.title,
project_alpha: DummyProjectAlpha {
team_id: alpha_project.team.to_string(),
project_id: alpha_project.id.to_string(),
project_slug: alpha_project.slug.unwrap(),
version_id: alpha_version.id.to_string(),
thread_id: alpha_project.thread_id.to_string(),
file_hash: alpha_version.files[0].hashes["sha1"].clone(),
},

project_beta: DummyProjectBeta {
team_id: beta_project.team.to_string(),
project_id: beta_project.id.to_string(),
project_slug: beta_project.slug.unwrap(),
version_id: beta_version.id.to_string(),
thread_id: beta_project.thread_id.to_string(),
file_hash: beta_version.files[0].hashes["sha1"].clone(),
},

organization_zeta: DummyOrganizationZeta {
organization_id: zeta_organization.id.to_string(),
team_id: zeta_organization.team_id.to_string(),
organization_title: zeta_organization.title,
},
}
}

Expand All @@ -125,27 +140,29 @@ pub async fn get_dummy_data(test_env: &TestEnvironment) -> DummyData {

let zeta_organization = get_organization_zeta(test_env).await;
DummyData {
alpha_team_id: alpha_project.team.to_string(),
beta_team_id: beta_project.team.to_string(),

alpha_project_id: alpha_project.id.to_string(),
beta_project_id: beta_project.id.to_string(),

alpha_project_slug: alpha_project.slug.unwrap(),
beta_project_slug: beta_project.slug.unwrap(),

alpha_version_id: alpha_version.id.to_string(),
beta_version_id: beta_version.id.to_string(),

alpha_thread_id: alpha_project.thread_id.to_string(),
beta_thread_id: beta_project.thread_id.to_string(),

alpha_file_hash: alpha_version.files[0].hashes["sha1"].clone(),
beta_file_hash: beta_version.files[0].hashes["sha1"].clone(),

zeta_organization_id: zeta_organization.id.to_string(),
zeta_team_id: zeta_organization.team_id.to_string(),
zeta_organization_title: zeta_organization.title,
project_alpha: DummyProjectAlpha {
team_id: alpha_project.team.to_string(),
project_id: alpha_project.id.to_string(),
project_slug: alpha_project.slug.unwrap(),
version_id: alpha_version.id.to_string(),
thread_id: alpha_project.thread_id.to_string(),
file_hash: alpha_version.files[0].hashes["sha1"].clone(),
},

project_beta: DummyProjectBeta {
team_id: beta_project.team.to_string(),
project_id: beta_project.id.to_string(),
project_slug: beta_project.slug.unwrap(),
version_id: beta_version.id.to_string(),
thread_id: beta_project.thread_id.to_string(),
file_hash: beta_version.files[0].hashes["sha1"].clone(),
},

organization_zeta: DummyOrganizationZeta {
organization_id: zeta_organization.id.to_string(),
team_id: zeta_organization.team_id.to_string(),
organization_title: zeta_organization.title,
},
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/common/environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ impl TestEnvironment {
let resp = self
.v2
.add_user_to_team(
&self.dummy.as_ref().unwrap().alpha_team_id,
&self.dummy.as_ref().unwrap().project_alpha.team_id,
FRIEND_USER_ID,
None,
None,
Expand Down
2 changes: 1 addition & 1 deletion tests/files/dummy_data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,5 @@ INSERT INTO categories (id, category, project_type) VALUES

-- Create dummy data table to mark that this file has been run
CREATE TABLE dummy_data (
update_id bigint PRIMARY KEY,
update_id bigint PRIMARY KEY
);
8 changes: 7 additions & 1 deletion tests/notifications.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@ mod common;
#[actix_rt::test]
pub async fn get_user_notifications_after_team_invitation_returns_notification() {
with_test_environment(|test_env| async move {
let alpha_team_id = test_env.dummy.as_ref().unwrap().alpha_team_id.clone();
let alpha_team_id = test_env
.dummy
.as_ref()
.unwrap()
.project_alpha
.team_id
.clone();
let api = test_env.v2;
api.get_user_notifications_deserialized(FRIEND_USER_ID, FRIEND_USER_PAT)
.await;
Expand Down
Loading

0 comments on commit 466dfac

Please sign in to comment.