[FIX][IMP] channel: improve can_upload / can_see computation on channel

Purpose of this commit is to clean a bit interface of slides

 * separate can_see from can_upload;
 * correctly set can_see on partial visibility channels;
 * remove upload button for portal users as they have no rights to upload a
   document and this is not supported in any way;

This commit is linked to task ID 1933820 and PR #30553.
This commit is contained in:
Thibault Delavallée
2019-01-28 15:37:14 +00:00
parent f766653780
commit 088041f79d
3 changed files with 8 additions and 8 deletions
+3 -3
View File
@@ -65,7 +65,7 @@ class WebsiteSlides(http.Controller):
'most_viewed_slides': most_viewed_slides,
'related_slides': related_slides,
'user': request.env.user,
'is_public_user': request.env.user == request.website.user_id,
'is_public_user': request.website.is_public_user(),
'comments': slide.channel_id.can_see_full and slide.website_message_ids or [],
'private': not slide.channel_id.can_see_full,
}
@@ -88,7 +88,7 @@ class WebsiteSlides(http.Controller):
return request.render('website_slides.channels', {
'channels': channels,
'user': request.env.user,
'is_public_user': request.env.user == request.website.user_id
'is_public_user': request.website.is_public_user(),
})
def sitemap_slide(env, rule, qs):
@@ -164,7 +164,7 @@ class WebsiteSlides(http.Controller):
'sorting': sorting,
'user': user,
'pager': pager,
'is_public_user': user == request.website.user_id,
'is_public_user': request.website.is_public_user(),
'display_channel_settings': not request.httprequest.cookies.get('slides_channel_%s' % (channel.id), False) and channel.can_see_full,
}
if search:
@@ -127,9 +127,9 @@ class Channel(models.Model):
@api.one
@api.depends('visibility', 'group_ids', 'upload_group_ids')
def _compute_access(self):
self.can_see = self.visibility in ['public', 'private'] or bool(self.group_ids & self.env.user.groups_id)
self.can_see = self.visibility in ['public', 'partial'] or bool(self.group_ids & self.env.user.groups_id)
self.can_see_full = self.visibility == 'public' or bool(self.group_ids & self.env.user.groups_id)
self.can_upload = self.can_see and (not self.upload_group_ids or bool(self.upload_group_ids & self.env.user.groups_id))
self.can_upload = not self.env.user.share and (not self.upload_group_ids or bool(self.upload_group_ids & self.env.user.groups_id))
@api.multi
@api.depends('name')
@@ -88,7 +88,7 @@
/ <a t-attf-href="/slides/#{slug(channel)}/category/#{slug(category)}" t-esc="category.name"/>
</t>
<!-- Public user has not right to create/write on slide -->
<t t-if="channel.can_upload and not is_public_user">
<t t-if="channel.can_see and channel.can_upload and not is_public_user">
<a role="button" class="btn btn-primary oe_slide_js_upload" title="Upload Presentation" t-attf-channel_id="#{channel.id}" aria-label="Upload Presentation" href="#">
<i class="fa fa-cloud-upload"></i> Upload
</a>
@@ -233,13 +233,13 @@
<h1>No presentation published yet.</h1>
<p>
The <i><t t-esc="channel.name"/></i> is empty.
<span t-if="can_upload">
<span t-if="channel.can_see and channel.can_upload">
Upload PDF presentations, documents, videos or infographic using the button below.
</span>
</p>
<p>
<!-- Public user has not right to create/write on slide-->
<a role="button" t-if="can_upload and not is_public_user" class="btn btn-primary oe_slide_js_upload" t-attf-channel_id="#{channel.id}" aria-label="Upload Presentation" title="Upload Presentation" href="#">
<a role="button" t-if="channel.can_see and channel.can_upload and not is_public_user" class="btn btn-primary oe_slide_js_upload" t-attf-channel_id="#{channel.id}" aria-label="Upload Presentation" title="Upload Presentation" href="#">
<i class="fa fa-cloud-upload"></i> Upload
</a>
</p>