Design pending blogs in organizations (#123)

This commit is contained in:
Phuoc Anh Kha Le 2024-07-23 01:24:43 -05:00 committed by GitHub
parent 66f6212947
commit 44554d7de6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 423 additions and 306 deletions

View file

@ -208,14 +208,9 @@ class PostView(TitleMixin, CommentedDetailView, PageVoteDetailView, BookMarkDeta
orgs = list(self.object.organizations.all())
if self.request.profile:
if self.request.profile.id in self.object.get_authors():
for org in orgs:
if org.is_member(self.request.profile):
context["editable_orgs"].append(org)
else:
for org in orgs:
if org.is_admin(self.request.profile):
context["editable_orgs"].append(org)
for org in orgs:
if self.request.profile.can_edit_organization(org):
context["editable_orgs"].append(org)
return context

View file

@ -1118,7 +1118,7 @@ class EditOrganizationBlog(
LoginRequiredMixin,
TitleMixin,
OrganizationHomeView,
MemberOrganizationMixin,
AdminOrganizationMixin,
UpdateView,
):
template_name = "organization/blog/edit.html"
@ -1134,19 +1134,20 @@ class EditOrganizationBlog(
self.blog_id = kwargs["blog_pk"]
self.blog = BlogPost.objects.get(id=self.blog_id)
if self.organization not in self.blog.organizations.all():
raise Exception("This blog does not belong to this organization")
if (
self.request.profile.id not in self.blog.get_authors()
and not self.can_edit_organization(self.organization)
):
raise Exception("Not allowed to edit this blog")
except:
raise Exception(_("This blog does not belong to this organization"))
if not self.request.profile.can_edit_organization(self.organization):
raise Exception(_("Not allowed to edit this blog"))
except Exception as e:
return generic_message(
request,
_("Permission denied"),
_("Not allowed to edit this blog"),
e,
)
def publish_blog(self, request, *args, **kwargs):
self.blog_id = kwargs["blog_pk"]
BlogPost.objects.filter(pk=self.blog_id).update(visible=True)
def delete_blog(self, request, *args, **kwargs):
self.blog_id = kwargs["blog_pk"]
BlogPost.objects.get(pk=self.blog_id).delete()
@ -1164,6 +1165,22 @@ class EditOrganizationBlog(
if request.POST["action"] == "Delete":
self.create_notification("Delete blog")
self.delete_blog(request, *args, **kwargs)
cur_url = reverse(
"organization_home",
args=(self.organization_id, self.organization.slug),
)
return HttpResponseRedirect(cur_url)
elif request.POST["action"] == "Reject":
self.create_notification("Reject blog")
self.delete_blog(request, *args, **kwargs)
cur_url = reverse(
"organization_pending_blogs",
args=(self.organization_id, self.organization.slug),
)
return HttpResponseRedirect(cur_url)
elif request.POST["action"] == "Approve":
self.create_notification("Approve blog")
self.publish_blog(request, *args, **kwargs)
cur_url = reverse(
"organization_pending_blogs",
args=(self.organization_id, self.organization.slug),
@ -1185,9 +1202,8 @@ class EditOrganizationBlog(
args=[self.organization.id, self.organization.slug, self.blog_id],
)
html = f'<a href="{link}">{blog.title} - {self.organization.name}</a>'
post_authors = blog.authors.all()
posible_users = self.organization.admins.all() | post_authors
make_notification(posible_users, action, html, self.request.profile)
to_users = (self.organization.admins.all() | blog.get_authors()).distinct()
make_notification(to_users, action, html, self.request.profile)
def form_valid(self, form):
with revisions.create_revision():
@ -1224,3 +1240,8 @@ class PendingBlogs(
def get_title(self):
return _("Pending blogs in %s") % self.organization.name
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["org"] = self.organization
return context