[FIX] website_profile: allow to edit its profile
Move code from website_forum allowing to edit its own profile. Otherwise fields to update are not white listed. Also add an unpublished flag when seeing unpublished users in order to know it if you have access to depending on ACLs. Linked to task 1978530 Related to PR #33559
This commit is contained in:
committed by
Thibault Delavallée
parent
e87a74e3ca
commit
369143c986
@@ -1,27 +1,12 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
import hashlib
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
from werkzeug import urls
|
||||
|
||||
from odoo import api, fields, models
|
||||
|
||||
|
||||
class Users(models.Model):
|
||||
_inherit = 'res.users'
|
||||
|
||||
def __init__(self, pool, cr):
|
||||
init_res = super(Users, self).__init__(pool, cr)
|
||||
type(self).SELF_WRITEABLE_FIELDS = list(
|
||||
set(
|
||||
self.SELF_WRITEABLE_FIELDS +
|
||||
['country_id', 'city', 'website', 'website_description', 'website_published']))
|
||||
type(self).SELF_READABLE_FIELDS = type(self).SELF_READABLE_FIELDS + ['karma']
|
||||
return init_res
|
||||
|
||||
create_date = fields.Datetime('Create Date', readonly=True, index=True)
|
||||
forum_waiting_posts_count = fields.Integer('Waiting post', compute="_get_user_waiting_post")
|
||||
|
||||
|
||||
@@ -204,6 +204,7 @@ class WebsiteProfile(http.Controller):
|
||||
'rank': user.rank_id.name,
|
||||
'karma': user.karma,
|
||||
'badge_count': len(user.badge_ids),
|
||||
'website_published': user.website_published
|
||||
}
|
||||
|
||||
@http.route(['/profile/users',
|
||||
|
||||
@@ -14,6 +14,15 @@ VALIDATION_KARMA_GAIN = 3
|
||||
class Users(models.Model):
|
||||
_inherit = 'res.users'
|
||||
|
||||
def __init__(self, pool, cr):
|
||||
init_res = super(Users, self).__init__(pool, cr)
|
||||
type(self).SELF_WRITEABLE_FIELDS = list(
|
||||
set(
|
||||
self.SELF_WRITEABLE_FIELDS +
|
||||
['country_id', 'city', 'website', 'website_description', 'website_published']))
|
||||
type(self).SELF_READABLE_FIELDS = type(self).SELF_READABLE_FIELDS + ['karma']
|
||||
return init_res
|
||||
|
||||
@api.model
|
||||
def _generate_profile_token(self, user_id, email):
|
||||
"""Return a token for email validation. This token is valid for the day
|
||||
|
||||
@@ -497,6 +497,7 @@
|
||||
<img class="position-absolute" t-attf-src="/website_profile/static/src/img/rank_#{user['position']}.svg" alt="User rank" style="bottom: 0; right: -10px"/>
|
||||
</div>
|
||||
<h3 class="mt-2 mb-0" t-esc="user['name']"></h3>
|
||||
<span class="badge badge-danger font-weight-normal px-2" t-if="not user['website_published']">Unpublished</span>
|
||||
<strong class="text-muted" t-esc="user['rank']"/>
|
||||
</div>
|
||||
<div class="row mx-0 o_wprofile_top3_card_footer text-nowrap">
|
||||
@@ -516,6 +517,9 @@
|
||||
<td class="align-middle w-md-75">
|
||||
<span class="font-weight-bold" t-esc="user['name']"/><br/>
|
||||
<span class="text-muted font-weight-bold" t-esc="user['rank']"></span>
|
||||
</td>
|
||||
<td t-if="not user['website_published']" class="align-middle font-weight-bold text-right text-nowrap">
|
||||
<span class="badge badge-danger font-weight-normal px-2 py-1 m-1">Unpublished</span>
|
||||
</td>
|
||||
<td class="align-middle font-weight-bold text-right text-nowrap">
|
||||
<b t-esc="user['karma']"/> <span class="text-muted small font-weight-bold">XP</span>
|
||||
|
||||
Reference in New Issue
Block a user