add: only people with post manage permission to view post likes
This commit is contained in:
parent
5d5849cdef
commit
12adcd5fd3
5 changed files with 55 additions and 45 deletions
|
@ -33,11 +33,6 @@
|
||||||
{{ icon "quote" }}
|
{{ icon "quote" }}
|
||||||
<span>{{ text "communities:label.quotes" }}</span>
|
<span>{{ text "communities:label.quotes" }}</span>
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
<a href="/post/{{ post.id }}/likes" class="active">
|
|
||||||
{{ icon "heart" }}
|
|
||||||
<span>{{ text "communities:label.likes" }}</span>
|
|
||||||
</a>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{% if (user and user.id == post.owner) or can_manage_posts %}
|
{% if (user and user.id == post.owner) or can_manage_posts %}
|
||||||
|
@ -48,6 +43,11 @@
|
||||||
<span>{{ text "communities:label.edit_content" }}</span>
|
<span>{{ text "communities:label.edit_content" }}</span>
|
||||||
</a>
|
</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
<a href="/post/{{ post.id }}/likes" class="active">
|
||||||
|
{{ icon "heart" }}
|
||||||
|
<span>{{ text "communities:label.likes" }}</span>
|
||||||
|
</a>
|
||||||
|
|
||||||
<a href="/post/{{ post.id }}#/configure">
|
<a href="/post/{{ post.id }}#/configure">
|
||||||
{{ icon "settings" }}
|
{{ icon "settings" }}
|
||||||
<span>{{ text "communities:action.configure" }}</span>
|
<span>{{ text "communities:action.configure" }}</span>
|
||||||
|
|
|
@ -73,11 +73,6 @@
|
||||||
{{ icon "quote" }}
|
{{ icon "quote" }}
|
||||||
<span>{{ text "communities:label.quotes" }}</span>
|
<span>{{ text "communities:label.quotes" }}</span>
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
<a href="/post/{{ post.id }}/likes">
|
|
||||||
{{ icon "heart" }}
|
|
||||||
<span>{{ text "communities:label.likes" }}</span>
|
|
||||||
</a>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{% if (user and user.id == post.owner) or can_manage_posts %}
|
{% if (user and user.id == post.owner) or can_manage_posts %}
|
||||||
|
@ -88,6 +83,12 @@
|
||||||
<span>{{ text "communities:label.edit_content" }}</span>
|
<span>{{ text "communities:label.edit_content" }}</span>
|
||||||
</a>
|
</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
<a href="/post/{{ post.id }}/likes">
|
||||||
|
{{ icon "heart" }}
|
||||||
|
<span>{{ text "communities:label.likes" }}</span>
|
||||||
|
</a>
|
||||||
|
|
||||||
<a href="#/configure" data-tab-button="configure">
|
<a href="#/configure" data-tab-button="configure">
|
||||||
{{ icon "settings" }}
|
{{ icon "settings" }}
|
||||||
<span>{{ text "communities:action.configure" }}</span>
|
<span>{{ text "communities:action.configure" }}</span>
|
||||||
|
|
|
@ -33,11 +33,6 @@
|
||||||
{{ icon "quote" }}
|
{{ icon "quote" }}
|
||||||
<span>{{ text "communities:label.quotes" }}</span>
|
<span>{{ text "communities:label.quotes" }}</span>
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
<a href="/post/{{ post.id }}/likes">
|
|
||||||
{{ icon "heart" }}
|
|
||||||
<span>{{ text "communities:label.likes" }}</span>
|
|
||||||
</a>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{% if (user and user.id == post.owner) or can_manage_posts %}
|
{% if (user and user.id == post.owner) or can_manage_posts %}
|
||||||
|
@ -48,6 +43,11 @@
|
||||||
<span>{{ text "communities:label.edit_content" }}</span>
|
<span>{{ text "communities:label.edit_content" }}</span>
|
||||||
</a>
|
</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
<a href="/post/{{ post.id }}/likes">
|
||||||
|
{{ icon "heart" }}
|
||||||
|
<span>{{ text "communities:label.likes" }}</span>
|
||||||
|
</a>
|
||||||
|
|
||||||
<a href="/post/{{ post.id }}#/configure">
|
<a href="/post/{{ post.id }}#/configure">
|
||||||
{{ icon "settings" }}
|
{{ icon "settings" }}
|
||||||
<span>{{ text "communities:action.configure" }}</span>
|
<span>{{ text "communities:action.configure" }}</span>
|
||||||
|
|
|
@ -33,11 +33,6 @@
|
||||||
{{ icon "quote" }}
|
{{ icon "quote" }}
|
||||||
<span>{{ text "communities:label.quotes" }}</span>
|
<span>{{ text "communities:label.quotes" }}</span>
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
<a href="/post/{{ post.id }}/likes">
|
|
||||||
{{ icon "heart" }}
|
|
||||||
<span>{{ text "communities:label.likes" }}</span>
|
|
||||||
</a>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{% if (user and user.id == post.owner) or can_manage_posts %}
|
{% if (user and user.id == post.owner) or can_manage_posts %}
|
||||||
|
@ -48,6 +43,11 @@
|
||||||
<span>{{ text "communities:label.edit_content" }}</span>
|
<span>{{ text "communities:label.edit_content" }}</span>
|
||||||
</a>
|
</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
<a href="/post/{{ post.id }}/likes">
|
||||||
|
{{ icon "heart" }}
|
||||||
|
<span>{{ text "communities:label.likes" }}</span>
|
||||||
|
</a>
|
||||||
|
|
||||||
<a href="/post/{{ post.id }}#/configure">
|
<a href="/post/{{ post.id }}#/configure">
|
||||||
{{ icon "settings" }}
|
{{ icon "settings" }}
|
||||||
<span>{{ text "communities:action.configure" }}</span>
|
<span>{{ text "communities:action.configure" }}</span>
|
||||||
|
|
|
@ -842,31 +842,44 @@ pub async fn likes_request(
|
||||||
Extension(data): Extension<State>,
|
Extension(data): Extension<State>,
|
||||||
) -> impl IntoResponse {
|
) -> impl IntoResponse {
|
||||||
let data = data.read().await;
|
let data = data.read().await;
|
||||||
let user = get_user_from_token!(jar, data.0);
|
let user = match get_user_from_token!(jar, data.0) {
|
||||||
|
Some(ua) => ua,
|
||||||
|
None => {
|
||||||
|
return Err(Html(
|
||||||
|
render_error(Error::NotAllowed, &jar, &data, &None).await,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
let post = match data.0.get_post_by_id(id).await {
|
let post = match data.0.get_post_by_id(id).await {
|
||||||
Ok(p) => p,
|
Ok(p) => p,
|
||||||
Err(e) => return Err(Html(render_error(e, &jar, &data, &user).await)),
|
Err(e) => return Err(Html(render_error(e, &jar, &data, &Some(user)).await)),
|
||||||
};
|
};
|
||||||
|
|
||||||
let community = match data.0.get_community_by_id(post.community).await {
|
let community = match data.0.get_community_by_id(post.community).await {
|
||||||
Ok(c) => c,
|
Ok(c) => c,
|
||||||
Err(e) => return Err(Html(render_error(e, &jar, &data, &user).await)),
|
Err(e) => return Err(Html(render_error(e, &jar, &data, &Some(user)).await)),
|
||||||
};
|
};
|
||||||
|
|
||||||
let ignore_users = if let Some(ref ua) = user {
|
let ignore_users = data.0.get_userblocks_receivers(user.id).await;
|
||||||
data.0.get_userblocks_receivers(ua.id).await
|
|
||||||
} else {
|
|
||||||
Vec::new()
|
|
||||||
};
|
|
||||||
|
|
||||||
// ...
|
// ...
|
||||||
let owner = match data.0.get_user_by_id(post.owner).await {
|
let ua = Some(user.clone());
|
||||||
Ok(ua) => ua,
|
let membership = data
|
||||||
Err(e) => return Err(Html(render_error(e, &jar, &data, &user).await)),
|
.0
|
||||||
};
|
.get_membership_by_owner_community(user.id, community.id)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
check_user_blocked_or_private!(user, owner, data, jar);
|
if user.id != post.owner
|
||||||
|
&& user.id != community.owner
|
||||||
|
&& !membership.role.check(CommunityPermission::MANAGE_POSTS)
|
||||||
|
&& !user.permissions.check(FinePermission::MANAGE_POSTS)
|
||||||
|
{
|
||||||
|
return Err(Html(
|
||||||
|
render_error(Error::NotAllowed, &jar, &data, &None).await,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
// check repost
|
// check repost
|
||||||
let reposting = data.0.get_post_reposting(&post, &ignore_users).await;
|
let reposting = data.0.get_post_reposting(&post, &ignore_users).await;
|
||||||
|
@ -874,36 +887,32 @@ pub async fn likes_request(
|
||||||
// check question
|
// check question
|
||||||
let question = match data.0.get_post_question(&post, &ignore_users).await {
|
let question = match data.0.get_post_question(&post, &ignore_users).await {
|
||||||
Ok(q) => q,
|
Ok(q) => q,
|
||||||
Err(e) => return Err(Html(render_error(e, &jar, &data, &user).await)),
|
Err(e) => return Err(Html(render_error(e, &jar, &data, &Some(user)).await)),
|
||||||
};
|
};
|
||||||
|
|
||||||
// check permissions
|
// check permissions
|
||||||
let (can_read, _) = check_permissions!(community, jar, data, user);
|
let (can_read, _) = check_permissions!(community, jar, data, ua);
|
||||||
|
|
||||||
if !can_read {
|
if !can_read {
|
||||||
return Err(Html(
|
return Err(Html(
|
||||||
render_error(Error::NotAllowed, &jar, &data, &user).await,
|
render_error(Error::NotAllowed, &jar, &data, &Some(user)).await,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
// ...
|
// ...
|
||||||
let ignore_users = if let Some(ref ua) = user {
|
let ignore_users = data.0.get_userblocks_receivers(user.id).await;
|
||||||
data.0.get_userblocks_receivers(ua.id).await
|
|
||||||
} else {
|
|
||||||
Vec::new()
|
|
||||||
};
|
|
||||||
|
|
||||||
let list = match data.0.get_reactions_by_asset(post.id, 12, props.page).await {
|
let list = match data.0.get_reactions_by_asset(post.id, 12, props.page).await {
|
||||||
Ok(p) => match data.0.fill_reactions(&p, ignore_users).await {
|
Ok(p) => match data.0.fill_reactions(&p, ignore_users).await {
|
||||||
Ok(p) => p,
|
Ok(p) => p,
|
||||||
Err(e) => return Err(Html(render_error(e, &jar, &data, &user).await)),
|
Err(e) => return Err(Html(render_error(e, &jar, &data, &Some(user)).await)),
|
||||||
},
|
},
|
||||||
Err(e) => return Err(Html(render_error(e, &jar, &data, &user).await)),
|
Err(e) => return Err(Html(render_error(e, &jar, &data, &Some(user)).await)),
|
||||||
};
|
};
|
||||||
|
|
||||||
// init context
|
// init context
|
||||||
let lang = get_lang!(jar, data.0);
|
let lang = get_lang!(jar, data.0);
|
||||||
let mut context = initial_context(&data.0.0, lang, &user).await;
|
let mut context = initial_context(&data.0.0, lang, &Some(user)).await;
|
||||||
|
|
||||||
let (
|
let (
|
||||||
is_owner,
|
is_owner,
|
||||||
|
@ -914,7 +923,7 @@ pub async fn likes_request(
|
||||||
can_manage_community,
|
can_manage_community,
|
||||||
can_manage_roles,
|
can_manage_roles,
|
||||||
can_manage_questions,
|
can_manage_questions,
|
||||||
) = community_context_bools!(data, user, community);
|
) = community_context_bools!(data, ua, community);
|
||||||
|
|
||||||
context.insert("post", &post);
|
context.insert("post", &post);
|
||||||
context.insert("question", &question);
|
context.insert("question", &question);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue