Skip to content

Commit

Permalink
tombstone: removed user check and formatted ui
Browse files Browse the repository at this point in the history
  • Loading branch information
Fatimah authored and kpsherva committed Oct 11, 2023
1 parent 87df7ac commit 66d4a88
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 57 deletions.
2 changes: 1 addition & 1 deletion invenio_communities/communities/resources/ui_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def mask_removed_by(obj):
if user == "system":
return_value = _("System (automatic)")
elif user is not None:
return_value = _("User")
return_value = _("Admin")

return return_value

Expand Down
17 changes: 2 additions & 15 deletions invenio_communities/communities/services/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
OpenRequestsForCommunityDeletionError,
)
from invenio_communities.generators import CommunityMembers
from invenio_communities.members.records.api import Member

from ...errors import CommunityDeletedError, DeletionStatusError
from ..records.systemfields.deletion_status import CommunityDeletionStatusEnum
Expand Down Expand Up @@ -664,26 +663,16 @@ def read(self, identity, id_, expand=False, include_deleted=False):
"""Retrieve a record."""
record = self.record_cls.pid.resolve(id_)
result = super().read(identity, id_, expand=expand)
is_user = False

if record.tombstone is not None:
owners = [
m.dumps() for m in Member.get_members(record.id) if m.role == "owner"
]
is_user = any(
owner.get("user_id") == int(record.tombstone.removed_by.get("user"))
for owner in owners
)
if not include_deleted and record.deletion_status.is_deleted:
raise CommunityDeletedError(record, is_user, result_item=result)
raise CommunityDeletedError(record, result_item=result)
if include_deleted and record.deletion_status.is_deleted:
can_read_deleted = self.check_permission(
identity, "read_deleted", record=record
)

if not can_read_deleted:
# displays tombstone
raise CommunityDeletedError(record, is_user, result_item=result)
raise CommunityDeletedError(record, result_item=result)

return result

Expand All @@ -692,11 +681,9 @@ def update(self, identity, id_, data, revision_id=None, uow=None, expand=False):
"""Replace a record."""
record = self.record_cls.pid.resolve(id_)

is_user = True
if record.deletion_status.is_deleted:
raise CommunityDeletedError(
record,
is_user,
result_item=self.result_item(
self,
identity,
Expand Down
3 changes: 1 addition & 2 deletions invenio_communities/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,9 @@ def __init__(self, requests):
class CommunityDeletedError(CommunityError):
"""Error denoting that the community was deleted."""

def __init__(self, community, is_user, result_item=None):
def __init__(self, community, result_item=None):
"""Constructor."""
self.community = community
self.is_user = is_user
self.result_item = result_item


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,50 +8,51 @@
{% extends config.THEME_ERROR_TEMPLATE %}

{%- set title = _("Tombstone") + " | " + config.THEME_SITENAME -%}
{%- set removal_reason = _("Reason unknown") %}
{%- if record.ui.tombstone.removal_reason %}
{%- set removal_reason = record.ui.tombstone.removal_reason.title_l10n %}
{%- endif %}

{%- block message %}
<div class="container centered rel-pt-2">
<h1 class="ui header inline-block">
<i class="icon lightning" aria-hidden="true"></i>
<div class="content pl-0 rel-pr-1">
{{ _('Gone') }}
</div>
</h1>
{%- block message %}
<div class="container centered rel-pt-2">
<h1 class="ui header inline-block">
<i class="icon lightning" aria-hidden="true"></i>
<div class="content pl-0 rel-pr-1">
{{ _('Gone') }}
</div>
</h1>

<p>
{%- trans sitename=config.THEME_SITENAME %}
The record you are trying to access was removed from {{ sitename }}. The
metadata of the record is kept for archival purposes.
{%- endtrans %}
</p>
<p>
{%- trans sitename=config.THEME_SITENAME %}
The community you are trying to access was removed from {{ sitename }}. The
metadata of the community is kept for archival purposes.
{%- endtrans %}
</p>
{%- if record.ui.tombstone.removal_reason %}
<div class="ui message compact text-align-left">
<div class="content">
<p>
<strong>{{ _("Reason for removal:") }}</strong> {{ removal_reason }}
</p>
<p>
<strong>{{ _("Removed by:") }}</strong>
{% if is_user %}
User
{% else %}
Admin
{% endif %}
</p>
{%- if record.ui.tombstone.note %}
<p>
<strong>{{ _("Removal note:") }}</strong> {{ record.ui.tombstone.note }}
</p>
{%- endif %}
<p>
<strong>{{ _("Date of removal:") }}</strong> {{ record.ui.tombstone.removal_date_l10n_long }}
</p>
</div>

<div class="ui message compact text-align-left">
<div class="content">
<p>
<strong>{{ _("Reason for removal:") }}</strong> {{ removal_reason }}
</p>
<p>
<strong>{{ _("Removed by:") }}</strong>
{% if is_user %}
User
{% else %}
Admin
{% endif %}
</p>
{%- if record.ui.tombstone.note %}
<p>
<strong>{{ _("Removal note:") }}</strong> {{ record.ui.tombstone.note }}
</p>
{%- endif %}
<p>
<strong>{{ _("Date of removal:") }}</strong> {{ record.ui.tombstone.removal_date_l10n_long }}
</p>
</div>

{%- endif %}
</div>
</div>
{% endblock message %}
{% endblock message %}

0 comments on commit 66d4a88

Please sign in to comment.