Ignore old admin column

This commit is contained in:
Conrad Irwin 2023-10-13 14:08:40 -06:00
parent e050d168a7
commit bb408936e9
3 changed files with 14 additions and 55 deletions

View file

@ -82,12 +82,13 @@ id_type!(UserId);
id_type!(ChannelBufferCollaboratorId); id_type!(ChannelBufferCollaboratorId);
id_type!(FlagId); id_type!(FlagId);
#[derive(Eq, PartialEq, Copy, Clone, Debug, EnumIter, DeriveActiveEnum)] #[derive(Eq, PartialEq, Copy, Clone, Debug, EnumIter, DeriveActiveEnum, Default)]
#[sea_orm(rs_type = "String", db_type = "String(None)")] #[sea_orm(rs_type = "String", db_type = "String(None)")]
pub enum ChannelRole { pub enum ChannelRole {
#[sea_orm(string_value = "admin")] #[sea_orm(string_value = "admin")]
Admin, Admin,
#[sea_orm(string_value = "member")] #[sea_orm(string_value = "member")]
#[default]
Member, Member,
#[sea_orm(string_value = "guest")] #[sea_orm(string_value = "guest")]
Guest, Guest,

View file

@ -78,8 +78,7 @@ impl Database {
channel_id: ActiveValue::Set(channel.id), channel_id: ActiveValue::Set(channel.id),
user_id: ActiveValue::Set(creator_id), user_id: ActiveValue::Set(creator_id),
accepted: ActiveValue::Set(true), accepted: ActiveValue::Set(true),
admin: ActiveValue::Set(true), role: ActiveValue::Set(ChannelRole::Admin),
role: ActiveValue::Set(Some(ChannelRole::Admin)),
} }
.insert(&*tx) .insert(&*tx)
.await?; .await?;
@ -197,8 +196,7 @@ impl Database {
channel_id: ActiveValue::Set(channel_id), channel_id: ActiveValue::Set(channel_id),
user_id: ActiveValue::Set(invitee_id), user_id: ActiveValue::Set(invitee_id),
accepted: ActiveValue::Set(false), accepted: ActiveValue::Set(false),
admin: ActiveValue::Set(role == ChannelRole::Admin), role: ActiveValue::Set(role),
role: ActiveValue::Set(Some(role)),
} }
.insert(&*tx) .insert(&*tx)
.await?; .await?;
@ -402,14 +400,7 @@ impl Database {
let mut role_for_channel: HashMap<ChannelId, ChannelRole> = HashMap::default(); let mut role_for_channel: HashMap<ChannelId, ChannelRole> = HashMap::default();
for membership in channel_memberships.iter() { for membership in channel_memberships.iter() {
role_for_channel.insert( role_for_channel.insert(membership.channel_id, membership.role);
membership.channel_id,
membership.role.unwrap_or(if membership.admin {
ChannelRole::Admin
} else {
ChannelRole::Member
}),
);
} }
for ChannelEdge { for ChannelEdge {
@ -561,8 +552,7 @@ impl Database {
.and(channel_member::Column::UserId.eq(for_user)), .and(channel_member::Column::UserId.eq(for_user)),
) )
.set(channel_member::ActiveModel { .set(channel_member::ActiveModel {
admin: ActiveValue::set(role == ChannelRole::Admin), role: ActiveValue::set(role),
role: ActiveValue::set(Some(role)),
..Default::default() ..Default::default()
}) })
.exec(&*tx) .exec(&*tx)
@ -596,7 +586,6 @@ impl Database {
#[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)] #[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)]
enum QueryMemberDetails { enum QueryMemberDetails {
UserId, UserId,
Admin,
Role, Role,
IsDirectMember, IsDirectMember,
Accepted, Accepted,
@ -610,7 +599,6 @@ impl Database {
.filter(channel_member::Column::ChannelId.is_in(ancestor_ids.iter().copied())) .filter(channel_member::Column::ChannelId.is_in(ancestor_ids.iter().copied()))
.select_only() .select_only()
.column(channel_member::Column::UserId) .column(channel_member::Column::UserId)
.column(channel_member::Column::Admin)
.column(channel_member::Column::Role) .column(channel_member::Column::Role)
.column_as( .column_as(
channel_member::Column::ChannelId.eq(channel_id), channel_member::Column::ChannelId.eq(channel_id),
@ -629,17 +617,9 @@ impl Database {
let mut user_details: HashMap<UserId, UserDetail> = HashMap::default(); let mut user_details: HashMap<UserId, UserDetail> = HashMap::default();
while let Some(row) = stream.next().await { while let Some(row) = stream.next().await {
let ( let (user_id, channel_role, is_direct_member, is_invite_accepted, visibility): (
user_id,
is_admin,
channel_role,
is_direct_member,
is_invite_accepted,
visibility,
): (
UserId, UserId,
bool, ChannelRole,
Option<ChannelRole>,
bool, bool,
bool, bool,
ChannelVisibility, ChannelVisibility,
@ -650,11 +630,6 @@ impl Database {
(false, true) => proto::channel_member::Kind::AncestorMember, (false, true) => proto::channel_member::Kind::AncestorMember,
(false, false) => continue, (false, false) => continue,
}; };
let channel_role = channel_role.unwrap_or(if is_admin {
ChannelRole::Admin
} else {
ChannelRole::Member
});
if channel_role == ChannelRole::Guest if channel_role == ChannelRole::Guest
&& visibility != ChannelVisibility::Public && visibility != ChannelVisibility::Public
@ -797,7 +772,6 @@ impl Database {
enum QueryChannelMembership { enum QueryChannelMembership {
ChannelId, ChannelId,
Role, Role,
Admin,
Visibility, Visibility,
} }
@ -811,7 +785,6 @@ impl Database {
.select_only() .select_only()
.column(channel_member::Column::ChannelId) .column(channel_member::Column::ChannelId)
.column(channel_member::Column::Role) .column(channel_member::Column::Role)
.column(channel_member::Column::Admin)
.column(channel::Column::Visibility) .column(channel::Column::Visibility)
.into_values::<_, QueryChannelMembership>() .into_values::<_, QueryChannelMembership>()
.stream(&*tx) .stream(&*tx)
@ -826,29 +799,16 @@ impl Database {
// note these channels are not iterated in any particular order, // note these channels are not iterated in any particular order,
// our current logic takes the highest permission available. // our current logic takes the highest permission available.
while let Some(row) = rows.next().await { while let Some(row) = rows.next().await {
let (ch_id, role, admin, visibility): ( let (ch_id, role, visibility): (ChannelId, ChannelRole, ChannelVisibility) = row?;
ChannelId,
Option<ChannelRole>,
bool,
ChannelVisibility,
) = row?;
match role { match role {
Some(ChannelRole::Admin) => is_admin = true, ChannelRole::Admin => is_admin = true,
Some(ChannelRole::Member) => is_member = true, ChannelRole::Member => is_member = true,
Some(ChannelRole::Guest) => { ChannelRole::Guest => {
if visibility == ChannelVisibility::Public { if visibility == ChannelVisibility::Public {
is_participant = true is_participant = true
} }
} }
Some(ChannelRole::Banned) => is_banned = true, ChannelRole::Banned => is_banned = true,
None => {
// rows created from pre-role collab server.
if admin {
is_admin = true
} else {
is_member = true
}
}
} }
if channel_id == ch_id { if channel_id == ch_id {
current_channel_visibility = Some(visibility); current_channel_visibility = Some(visibility);

View file

@ -9,9 +9,7 @@ pub struct Model {
pub channel_id: ChannelId, pub channel_id: ChannelId,
pub user_id: UserId, pub user_id: UserId,
pub accepted: bool, pub accepted: bool,
pub admin: bool, pub role: ChannelRole,
// only optional while migrating
pub role: Option<ChannelRole>,
} }
impl ActiveModelBehavior for ActiveModel {} impl ActiveModelBehavior for ActiveModel {}