Enhancement: shared icon

This commit is contained in:
shamoon 2023-12-06 08:49:42 -08:00
parent 088bad9030
commit 491f0b9c87
5 changed files with 55 additions and 10 deletions

View File

@ -1721,7 +1721,7 @@
</context-group> </context-group>
<context-group purpose="location"> <context-group purpose="location">
<context context-type="sourcefile">src/app/components/document-list/document-card-small/document-card-small.component.html</context> <context context-type="sourcefile">src/app/components/document-list/document-card-small/document-card-small.component.html</context>
<context context-type="linenumber">83</context> <context context-type="linenumber">89</context>
</context-group> </context-group>
<context-group purpose="location"> <context-group purpose="location">
<context context-type="sourcefile">src/app/components/manage/consumption-templates/consumption-templates.component.html</context> <context context-type="sourcefile">src/app/components/manage/consumption-templates/consumption-templates.component.html</context>
@ -4073,7 +4073,7 @@
</context-group> </context-group>
<context-group purpose="location"> <context-group purpose="location">
<context context-type="sourcefile">src/app/components/document-list/document-card-small/document-card-small.component.html</context> <context context-type="sourcefile">src/app/components/document-list/document-card-small/document-card-small.component.html</context>
<context context-type="linenumber">99</context> <context context-type="linenumber">105</context>
</context-group> </context-group>
</trans-unit> </trans-unit>
<trans-unit id="872092479747931526" datatype="html"> <trans-unit id="872092479747931526" datatype="html">
@ -5007,11 +5007,26 @@
<context context-type="linenumber">58,59</context> <context context-type="linenumber">58,59</context>
</context-group> </context-group>
</trans-unit> </trans-unit>
<trans-unit id="5739581984228459958" datatype="html">
<source>Shared</source>
<context-group purpose="location">
<context context-type="sourcefile">src/app/components/document-list/document-card-large/document-card-large.component.html</context>
<context context-type="linenumber">119</context>
</context-group>
<context-group purpose="location">
<context context-type="sourcefile">src/app/components/document-list/document-card-small/document-card-small.component.html</context>
<context context-type="linenumber">84</context>
</context-group>
<context-group purpose="location">
<context context-type="sourcefile">src/app/pipes/username.pipe.ts</context>
<context context-type="linenumber">33</context>
</context-group>
</trans-unit>
<trans-unit id="2332107018974972998" datatype="html"> <trans-unit id="2332107018974972998" datatype="html">
<source>Score:</source> <source>Score:</source>
<context-group purpose="location"> <context-group purpose="location">
<context context-type="sourcefile">src/app/components/document-list/document-card-large/document-card-large.component.html</context> <context context-type="sourcefile">src/app/components/document-list/document-card-large/document-card-large.component.html</context>
<context context-type="linenumber">116</context> <context context-type="linenumber">122</context>
</context-group> </context-group>
</trans-unit> </trans-unit>
<trans-unit id="3661756380991326939" datatype="html"> <trans-unit id="3661756380991326939" datatype="html">
@ -6297,13 +6312,6 @@
<context context-type="linenumber">11</context> <context context-type="linenumber">11</context>
</context-group> </context-group>
</trans-unit> </trans-unit>
<trans-unit id="5739581984228459958" datatype="html">
<source>Shared</source>
<context-group purpose="location">
<context context-type="sourcefile">src/app/pipes/username.pipe.ts</context>
<context context-type="linenumber">33</context>
</context-group>
</trans-unit>
<trans-unit id="2807800733729323332" datatype="html"> <trans-unit id="2807800733729323332" datatype="html">
<source>Yes</source> <source>Yes</source>
<context-group purpose="location"> <context-group purpose="location">

View File

@ -112,6 +112,12 @@
</svg> </svg>
<small>{{document.owner | username}}</small> <small>{{document.owner | username}}</small>
</div> </div>
<div *ngIf="document.is_shared" class="list-group-item bg-light text-dark p-1 border-0">
<svg class="metadata-icon me-2 text-muted" fill="currentColor">
<use xlink:href="assets/bootstrap-icons.svg#people-fill"/>
</svg>
<small i18n>Shared</small>
</div>
<div *ngIf="document.__search_hit__?.score" class="list-group-item bg-light text-dark border-0 d-flex p-0 ps-4 search-score"> <div *ngIf="document.__search_hit__?.score" class="list-group-item bg-light text-dark border-0 d-flex p-0 ps-4 search-score">
<small class="text-muted" i18n>Score:</small> <small class="text-muted" i18n>Score:</small>
<ngb-progressbar [type]="searchScoreClass" [value]="document.__search_hit__.score" class="search-score-bar mx-2 mt-1" [max]="1"></ngb-progressbar> <ngb-progressbar [type]="searchScoreClass" [value]="document.__search_hit__.score" class="search-score-bar mx-2 mt-1" [max]="1"></ngb-progressbar>

View File

@ -77,6 +77,12 @@
</svg> </svg>
<small>{{document.owner | username}}</small> <small>{{document.owner | username}}</small>
</div> </div>
<div *ngIf="document.is_shared" class="ps-0 p-1">
<svg class="metadata-icon me-2 text-muted" fill="currentColor">
<use xlink:href="assets/bootstrap-icons.svg#people-fill"/>
</svg>
<small i18n>Shared</small>
</div>
</div> </div>
<div class="d-flex justify-content-between align-items-center"> <div class="d-flex justify-content-between align-items-center">
<div class="btn-group w-100"> <div class="btn-group w-100">

View File

@ -17,4 +17,6 @@ export interface ObjectWithPermissions extends ObjectWithId {
permissions?: PermissionsObject permissions?: PermissionsObject
user_can_change?: boolean user_can_change?: boolean
is_shared?: boolean
} }

View File

@ -8,6 +8,7 @@ from celery import states
from django.conf import settings from django.conf import settings
from django.contrib.auth.models import Group from django.contrib.auth.models import Group
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.contrib.contenttypes.models import ContentType
from django.core.validators import URLValidator from django.core.validators import URLValidator
from django.utils.crypto import get_random_string from django.utils.crypto import get_random_string
from django.utils.text import slugify from django.utils.text import slugify
@ -15,6 +16,8 @@ from django.utils.translation import gettext as _
from drf_writable_nested.serializers import NestedUpdateMixin from drf_writable_nested.serializers import NestedUpdateMixin
from guardian.core import ObjectPermissionChecker from guardian.core import ObjectPermissionChecker
from guardian.shortcuts import get_users_with_perms from guardian.shortcuts import get_users_with_perms
from guardian.utils import get_group_obj_perms_model
from guardian.utils import get_user_obj_perms_model
from rest_framework import fields from rest_framework import fields
from rest_framework import serializers from rest_framework import serializers
from rest_framework.fields import SerializerMethodField from rest_framework.fields import SerializerMethodField
@ -160,6 +163,7 @@ class OwnedObjectSerializer(serializers.ModelSerializer, SetPermissionsMixin):
try: try:
if full_perms: if full_perms:
self.fields.pop("user_can_change") self.fields.pop("user_can_change")
self.fields.pop("is_shared")
else: else:
self.fields.pop("permissions") self.fields.pop("permissions")
except KeyError: except KeyError:
@ -205,8 +209,26 @@ class OwnedObjectSerializer(serializers.ModelSerializer, SetPermissionsMixin):
) )
) )
def get_is_shared(self, obj: Document):
ctype = ContentType.objects.get_for_model(obj)
UserObjectPermission = get_user_obj_perms_model()
GroupObjectPermission = get_group_obj_perms_model()
return obj.owner == self.user and (
UserObjectPermission.objects.filter(
content_type=ctype,
object_pk=obj.pk,
).count()
> 0
or GroupObjectPermission.objects.filter(
content_type=ctype,
object_pk=obj.pk,
).count()
> 0
)
permissions = SerializerMethodField(read_only=True) permissions = SerializerMethodField(read_only=True)
user_can_change = SerializerMethodField(read_only=True) user_can_change = SerializerMethodField(read_only=True)
is_shared = SerializerMethodField(read_only=True)
set_permissions = serializers.DictField( set_permissions = serializers.DictField(
label="Set permissions", label="Set permissions",
@ -556,6 +578,7 @@ class DocumentSerializer(
"owner", "owner",
"permissions", "permissions",
"user_can_change", "user_can_change",
"is_shared",
"set_permissions", "set_permissions",
"notes", "notes",
"custom_fields", "custom_fields",