Skip to content
Permalink
Browse files

temp get access computation

  • Loading branch information...
dbeguin committed Mar 14, 2019
1 parent e5baa51 commit 477f94b4a8a5b5a6878d770c9db12b8f10351449
@@ -370,7 +370,6 @@ def channel(self, channel, category=None, tag=None, page=1, slide_type=None, unc
'user': request.env.user,
'pager': pager,
'is_public_user': request.website.is_public_user(),
'is_slides_publisher': request.env.user.has_group('website.group_website_publisher'),
}
if not request.env.user._is_public():
last_message_values = request.env['mail.message'].search([
@@ -399,6 +398,9 @@ def channel(self, channel, category=None, tag=None, page=1, slide_type=None, unc
force_void=True,
limit=self._slides_per_category if channel.channel_type == 'documentation' else False,
offset=pager['offset'])

promoted_slide_sudo_user = values['slide_promoted'].sudo(request.env.user)
values['slide_promoted_can_access'] = promoted_slide_sudo_user._check_get_access() and promoted_slide_sudo_user.can_access
values['channel_progress'] = self._get_channel_progress(channel, include_quiz=True)

values = self._prepare_additional_channel_values(values, **kw)
@@ -460,11 +460,14 @@ def _get_categorized_slides(self, base_domain, order, force_void=True, limit=Fal
category_slides = all_slides.filtered(lambda slide: slide.category_id == category)
if not category_slides and not force_void:
continue
slides = category_slides[(offset or 0):(limit or len(category_slides))]
category_data.append({
'category': category, 'id': category.id,
'name': category.name, 'slug_name': slug(category),
'total_slides': len(category_slides),
'slides': category_slides[(offset or 0):(limit or len(category_slides))],
'slides': slides,
'slides_access': {slide.id: {'can_vote': slide._check_get_access() and slide.can_vote,
'can_access': slide._check_get_access() and slide.can_access} for slide in slides.sudo(self.env.user)}
})

return category_data
@@ -14,7 +14,7 @@
from odoo import api, fields, models, _
from odoo.addons.http_routing.models.ir_http import slug
from odoo.addons.gamification.models.gamification_karma_rank import KarmaError
from odoo.exceptions import Warning, UserError
from odoo.exceptions import Warning, UserError, AccessError
from odoo.http import request
from odoo.addons.http_routing.models.ir_http import url_for

@@ -151,6 +151,7 @@ def _default_access_token(self):
dislikes = fields.Integer('Dislikes', compute='_compute_user_info', store=True)
user_vote = fields.Integer('User vote', compute='_compute_user_info')
embed_code = fields.Text('Embed Code', readonly=True, compute='_compute_embed_code')
can_access = fields.Boolean('Can Access', compute='_compute_can_access')
# views
embedcount_ids = fields.One2many('slide.embed', 'slide_id', string="Embed Count")
slide_views = fields.Integer('# of Website Views', store=True, compute="_compute_slide_views")
@@ -271,11 +272,25 @@ def _compute_can_publish(self):
def _get_can_publish_error_message(self):
return _("Publishing is restricted to the responsible of training courses or members of the publisher group for documentation courses")

@api.multi
def _compute_can_access(self):
for slide in self:
slide.can_access = slide.is_preview or slide.channel_id.is_member or self.env.user.has_group('website.group_website_publisher')

@api.multi
def _compute_karma_rights(self):
for slide in self:
slide.can_comment = self.env.user.karma >= slide.channel_id.karma_slide_comment
slide.can_vote = self.env.user.karma >= slide.channel_id.karma_slide_vote
enough_karma = self.env.user.karma >= slide.channel_id.karma_slide_vote
slide.can_comment = enough_karma
slide.can_vote = enough_karma and (slide.is_preview or slide.channel_id.is_member)

def _check_get_access(self):
try:
self.check_access_rights('read')
self.check_access_rule('read')
except AccessError:
return False
return True

# ---------------------------------------------------------
# ORM Overrides
@@ -10,8 +10,8 @@ var _t = core._t;

var SlideLikeWidget = Widget.extend({
events: {
'click .o_wslides_js_slide_like_up': '_onClickUp',
'click .o_wslides_js_slide_like_down': '_onClickDown',
'click .o_wslides_js_slide_like_up :not([disabled])': '_onClickUp',
'click .o_wslides_js_slide_like_down :not([disabled])': '_onClickDown',
},

//--------------------------------------------------------------------------
@@ -32,8 +32,10 @@ $o-enterprise-radient-color: #62495B !default;

.o_wslides_js_slide_like_up,
.o_wslides_js_slide_like_down {
cursor: pointer;
color: $link-color;
&:not(.disabled) {
cursor: pointer;
color: $link-color;
}
}

.o_wslides_js_lesson_quiz_question {
@@ -387,7 +387,7 @@
</div>
<div class="col-8">
<h3 class="w-100" t-att-title="slide_promoted.name">
<t t-if="slide_promoted.is_preview or channel.is_member or is_slides_publisher">
<t t-if="slide_promoted_can_access">
<a t-attf-href="/slides/slide/#{slug(slide_promoted)}" class="font-weight-bold text-muted" t-field="slide_promoted.name"/>
</t>
<t t-else="">
@@ -420,7 +420,9 @@
</div>
<div class="row mx-n2 mt8">
<t t-foreach="category['slides']" t-as="slide">
<div class="col-md-3 col-sm-6 px-2 col-xs-12 d-flex flex-grow-1" t-call="website_slides.lesson_card"/>
<div class="col-md-3 col-sm-6 px-2 col-xs-12 d-flex flex-grow-1" t-call="website_slides.lesson_card">
<t t-set="slide_access" t-value="category['slides_access'][slide.id]"/>
</div>
</t>
</div>
</div>
@@ -438,15 +440,14 @@
<template id='lesson_card' name="Lesson Card">
<div class="card w-100 o_wslides_lesson_card mb-4">
<t t-set="lesson_image" t-value="'/slides/slide/%s/get_image?field=image_large' % slide.id"/>
<t t-set="can_access" t-value="slide.is_preview or channel.is_member or is_slides_publisher"/>
<a t-if="can_access" t-attf-href="/slides/slide/#{slug(slide)}" t-title="slide.name">
<a t-if="slide_access['can_access']" t-attf-href="/slides/slide/#{slug(slide)}" t-title="slide.name">
<div class="card-img-top" t-attf-style="padding-top: 50%; background-image: url(#{lesson_image}); background-size: cover; background-position:center"/>
</a>
<t t-else="">
<div class="card-img-top" t-attf-style="padding-top: 50%; background-image: url(#{lesson_image}); background-size: cover; background-position:center"/>
</t>
<div class="card-body">
<a t-if="can_access" class="card-title h5" t-attf-href="/slides/slide/#{slug(slide)}" t-esc="slide.name"/>
<a t-if="slide_access['can_access']" class="card-title h5" t-attf-href="/slides/slide/#{slug(slide)}" t-esc="slide.name"/>
<span t-else="" class="card-title h5 text-muted" t-esc="slide.name"/>
<div class="card-subtitle mb-2 text-muted">
<t t-if="slide.is_preview">
@@ -469,11 +470,11 @@
<div class="d-flex align-items-center small">
<span class="font-weight-bold mr-auto" t-field="slide.completion_time" t-options='{"widget": "float_time"}'/>
<div class="o_wslides_js_slide_like mr-2">
<span class="o_wslides_js_slide_like_up" tabindex="0" data-toggle="popover" t-att-data-slide-id="slide.id">
<span t-att-class="('o_wslides_js_slide_like_up %s') % ('disabled' if not slide_access['can_vote'] else '')" tabindex="0" data-toggle="popover" t-att-data-slide-id="slide.id">
<i class="fa fa-thumbs-up fa-1x" role="img" aria-label="Likes" title="Likes"></i>
<span t-esc="slide.likes"/>
</span>
<span class="o_wslides_js_slide_like_down" tabindex="0" data-toggle="popover" t-att-data-slide-id="slide.id">
<span t-att-class="('o_wslides_js_slide_like_down %s') % ('disabled' if not slide_access['can_vote'] else '')" tabindex="0" data-toggle="popover" t-att-data-slide-id="slide.id">
<i class="fa fa-thumbs-down fa-1x" role="img" aria-label="Dislikes" title="Dislikes"></i>
<span t-esc="slide.dislikes"/>
</span>

0 comments on commit 477f94b

Please sign in to comment.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.