fix: community joining
This commit is contained in:
parent
8c43f62545
commit
6141910059
2 changed files with 30 additions and 3 deletions
|
@ -23,7 +23,9 @@
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
<div class="card secondary flex flex-col gap-2">
|
<div class="card secondary flex flex-col gap-2">
|
||||||
<span>{{ item.content|markdown|safe }}</span>
|
<span class="no_p_margin"
|
||||||
|
>{{ item.content|markdown|safe }}</span
|
||||||
|
>
|
||||||
|
|
||||||
<div class="card w-full flex flex-wrap gap-2">
|
<div class="card w-full flex flex-wrap gap-2">
|
||||||
<button
|
<button
|
||||||
|
|
|
@ -86,6 +86,31 @@ impl DataManager {
|
||||||
Ok(res.unwrap())
|
Ok(res.unwrap())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get a community membership by `owner` and `community`.
|
||||||
|
pub async fn get_membership_by_owner_community_no_void(
|
||||||
|
&self,
|
||||||
|
owner: usize,
|
||||||
|
community: usize,
|
||||||
|
) -> Result<CommunityMembership> {
|
||||||
|
let conn = match self.connect().await {
|
||||||
|
Ok(c) => c,
|
||||||
|
Err(e) => return Err(Error::DatabaseConnection(e.to_string())),
|
||||||
|
};
|
||||||
|
|
||||||
|
let res = query_row!(
|
||||||
|
&conn,
|
||||||
|
"SELECT * FROM memberships WHERE owner = $1 AND community = $2",
|
||||||
|
&[&(owner as i64), &(community as i64)],
|
||||||
|
|x| { Ok(Self::get_membership_from_row(x)) }
|
||||||
|
);
|
||||||
|
|
||||||
|
if res.is_err() {
|
||||||
|
return Err(Error::GeneralNotFound("community membership".to_string()));
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(res.unwrap())
|
||||||
|
}
|
||||||
|
|
||||||
/// Get all community memberships by `owner`.
|
/// Get all community memberships by `owner`.
|
||||||
pub async fn get_memberships_by_owner(&self, owner: usize) -> Result<Vec<CommunityMembership>> {
|
pub async fn get_memberships_by_owner(&self, owner: usize) -> Result<Vec<CommunityMembership>> {
|
||||||
let conn = match self.connect().await {
|
let conn = match self.connect().await {
|
||||||
|
@ -149,7 +174,7 @@ impl DataManager {
|
||||||
pub async fn create_membership(&self, data: CommunityMembership) -> Result<String> {
|
pub async fn create_membership(&self, data: CommunityMembership) -> Result<String> {
|
||||||
// make sure membership doesn't already exist
|
// make sure membership doesn't already exist
|
||||||
if self
|
if self
|
||||||
.get_membership_by_owner_community(data.owner, data.community)
|
.get_membership_by_owner_community_no_void(data.owner, data.community)
|
||||||
.await
|
.await
|
||||||
.is_ok()
|
.is_ok()
|
||||||
{
|
{
|
||||||
|
@ -227,7 +252,7 @@ impl DataManager {
|
||||||
if user.id != y.owner {
|
if user.id != y.owner {
|
||||||
// pull other user's membership status
|
// pull other user's membership status
|
||||||
if let Ok(z) = self
|
if let Ok(z) = self
|
||||||
.get_membership_by_owner_community(user.id, y.community)
|
.get_membership_by_owner_community_no_void(user.id, y.community)
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
// somebody with MANAGE_ROLES _and_ a higher role number can remove us
|
// somebody with MANAGE_ROLES _and_ a higher role number can remove us
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue