Push role refactoring through RPC/client
This commit is contained in:
parent
690d9fb971
commit
540436a1f9
12 changed files with 178 additions and 89 deletions
|
@ -1,4 +1,5 @@
|
|||
use crate::Result;
|
||||
use rpc::proto;
|
||||
use sea_orm::{entity::prelude::*, DbErr};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
|
@ -91,3 +92,30 @@ pub enum ChannelRole {
|
|||
#[sea_orm(string_value = "guest")]
|
||||
Guest,
|
||||
}
|
||||
|
||||
impl From<proto::ChannelRole> for ChannelRole {
|
||||
fn from(value: proto::ChannelRole) -> Self {
|
||||
match value {
|
||||
proto::ChannelRole::Admin => ChannelRole::Admin,
|
||||
proto::ChannelRole::Member => ChannelRole::Member,
|
||||
proto::ChannelRole::Guest => ChannelRole::Guest,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<proto::ChannelRole> for ChannelRole {
|
||||
fn into(self) -> proto::ChannelRole {
|
||||
match self {
|
||||
ChannelRole::Admin => proto::ChannelRole::Admin,
|
||||
ChannelRole::Member => proto::ChannelRole::Member,
|
||||
ChannelRole::Guest => proto::ChannelRole::Guest,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<i32> for ChannelRole {
|
||||
fn into(self) -> i32 {
|
||||
let proto: proto::ChannelRole = self.into();
|
||||
proto.into()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -564,13 +564,18 @@ impl Database {
|
|||
(false, true) => proto::channel_member::Kind::AncestorMember,
|
||||
(false, false) => continue,
|
||||
};
|
||||
let channel_role = channel_role.unwrap_or(if is_admin {
|
||||
ChannelRole::Admin
|
||||
} else {
|
||||
ChannelRole::Member
|
||||
});
|
||||
let user_id = user_id.to_proto();
|
||||
let kind = kind.into();
|
||||
if let Some(last_row) = rows.last_mut() {
|
||||
if last_row.user_id == user_id {
|
||||
if is_direct_member {
|
||||
last_row.kind = kind;
|
||||
last_row.admin = channel_role == Some(ChannelRole::Admin) || is_admin;
|
||||
last_row.role = channel_role.into()
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
@ -578,7 +583,7 @@ impl Database {
|
|||
rows.push(proto::ChannelMember {
|
||||
user_id,
|
||||
kind,
|
||||
admin: channel_role == Some(ChannelRole::Admin) || is_admin,
|
||||
role: channel_role.into(),
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -851,10 +856,11 @@ impl Database {
|
|||
&self,
|
||||
user: UserId,
|
||||
channel: ChannelId,
|
||||
to: ChannelId,
|
||||
new_parent: ChannelId,
|
||||
tx: &DatabaseTransaction,
|
||||
) -> Result<ChannelGraph> {
|
||||
self.check_user_is_channel_admin(to, user, &*tx).await?;
|
||||
self.check_user_is_channel_admin(new_parent, user, &*tx)
|
||||
.await?;
|
||||
|
||||
let paths = channel_path::Entity::find()
|
||||
.filter(channel_path::Column::IdPath.like(&format!("%/{}/%", channel)))
|
||||
|
@ -872,7 +878,7 @@ impl Database {
|
|||
}
|
||||
|
||||
let paths_to_new_parent = channel_path::Entity::find()
|
||||
.filter(channel_path::Column::ChannelId.eq(to))
|
||||
.filter(channel_path::Column::ChannelId.eq(new_parent))
|
||||
.all(tx)
|
||||
.await?;
|
||||
|
||||
|
@ -906,7 +912,7 @@ impl Database {
|
|||
if let Some(channel) = channel_descendants.get_mut(&channel) {
|
||||
// Remove the other parents
|
||||
channel.clear();
|
||||
channel.insert(to);
|
||||
channel.insert(new_parent);
|
||||
}
|
||||
|
||||
let channels = self
|
||||
|
|
|
@ -328,17 +328,17 @@ async fn test_channel_invites(db: &Arc<Database>) {
|
|||
proto::ChannelMember {
|
||||
user_id: user_1.to_proto(),
|
||||
kind: proto::channel_member::Kind::Member.into(),
|
||||
admin: true,
|
||||
role: proto::ChannelRole::Admin.into(),
|
||||
},
|
||||
proto::ChannelMember {
|
||||
user_id: user_2.to_proto(),
|
||||
kind: proto::channel_member::Kind::Invitee.into(),
|
||||
admin: false,
|
||||
role: proto::ChannelRole::Member.into(),
|
||||
},
|
||||
proto::ChannelMember {
|
||||
user_id: user_3.to_proto(),
|
||||
kind: proto::channel_member::Kind::Invitee.into(),
|
||||
admin: true,
|
||||
role: proto::ChannelRole::Admin.into(),
|
||||
},
|
||||
]
|
||||
);
|
||||
|
@ -362,12 +362,12 @@ async fn test_channel_invites(db: &Arc<Database>) {
|
|||
proto::ChannelMember {
|
||||
user_id: user_1.to_proto(),
|
||||
kind: proto::channel_member::Kind::Member.into(),
|
||||
admin: true,
|
||||
role: proto::ChannelRole::Admin.into(),
|
||||
},
|
||||
proto::ChannelMember {
|
||||
user_id: user_2.to_proto(),
|
||||
kind: proto::channel_member::Kind::AncestorMember.into(),
|
||||
admin: false,
|
||||
role: proto::ChannelRole::Member.into(),
|
||||
},
|
||||
]
|
||||
);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue