mirror of
https://github.com/mediacms-io/mediacms.git
synced 2026-05-05 20:23:26 -04:00
all
This commit is contained in:
+1
-12
@@ -305,21 +305,10 @@ class MediaPublishForm(forms.ModelForm):
|
||||
|
||||
def clean(self):
|
||||
cleaned_data = super().clean()
|
||||
state = cleaned_data.get("state")
|
||||
shared = cleaned_data.get("shared")
|
||||
|
||||
if self.was_shared and not shared and not cleaned_data.get('confirm_state'):
|
||||
if state == 'private':
|
||||
error_parts = []
|
||||
rbac_cat_titles = list(self.instance.category.filter(is_rbac_category=True).values_list('title', flat=True))
|
||||
if rbac_cat_titles:
|
||||
error_parts.append(f"shared with users that have access to categories: {', '.join(rbac_cat_titles)}")
|
||||
if self.instance.permissions.exists():
|
||||
error_parts.append("shared by me with other users (visible in 'Shared by me' page)")
|
||||
detail = f" Currently this media is {' and '.join(error_parts)}." if error_parts else ""
|
||||
self.add_error('confirm_state', f"I understand that this will remove all sharing.{detail}")
|
||||
else:
|
||||
self.add_error('confirm_state', "I understand that unchecking Shared will affect existing sharing settings.")
|
||||
self.add_error('confirm_state', "I understand that unchecking Shared will remove all existing sharing for this media.")
|
||||
|
||||
return cleaned_data
|
||||
|
||||
|
||||
+10
-1
@@ -506,7 +506,16 @@ class MediaBulkUserActions(APIView):
|
||||
|
||||
m.save(update_fields=["state", "listable"])
|
||||
|
||||
if state == "private":
|
||||
shared = request.data.get('shared', None)
|
||||
|
||||
if shared is True:
|
||||
for m in media:
|
||||
MediaPermission.objects.get_or_create(
|
||||
media=m,
|
||||
user=request.user,
|
||||
defaults={'owner_user': request.user, 'permission': 'owner'},
|
||||
)
|
||||
elif shared is False or (shared is None and state == 'private'):
|
||||
MediaPermission.objects.filter(media__in=media).delete()
|
||||
for m in media:
|
||||
rbac_cats = m.category.filter(is_rbac_category=True)
|
||||
|
||||
Reference in New Issue
Block a user