[IMP] improved code to allow users to perform operations
bzr revid: tpa@tinyerp.com-20140326102654-chkaxf71i5n81x6l
This commit is contained in:
parent
18da293363
commit
1d69829083
|
@ -152,7 +152,7 @@ class website_forum(http.Controller):
|
|||
if request.session.uid:
|
||||
view_ids = Statistics.search(cr, uid, [('user_id', '=', request.session.uid), ('post_id', '=', question.id)], context=context)
|
||||
if not view_ids:
|
||||
Statistics.create(cr, uid, {'user_id': request.session.uid, 'post_id': question.id }, context=context)
|
||||
Statistics.create(cr, SUPERUSER_ID, {'user_id': request.session.uid, 'post_id': question.id }, context=context)
|
||||
else:
|
||||
request.session[request.session_id] = request.session.get(request.session_id, [])
|
||||
if not (question.id in request.session[request.session_id]):
|
||||
|
@ -186,9 +186,8 @@ class website_forum(http.Controller):
|
|||
group_id = request.registry["ir.model.data"].get_object_reference(cr, uid, 'website_mail', 'group_comment')[1]
|
||||
if group_id in [group.id for group in group_ids]:
|
||||
Post = request.registry['website.forum.post']
|
||||
Post.check_access_rights(cr, uid, 'read')
|
||||
Post.message_post(
|
||||
cr, SUPERUSER_ID, int(post_id),
|
||||
cr, uid, int(post_id),
|
||||
body=kwargs.get('comment'),
|
||||
type='comment',
|
||||
subtype='mt_comment',
|
||||
|
@ -289,7 +288,7 @@ class website_forum(http.Controller):
|
|||
return login_redirect()
|
||||
|
||||
cr, uid, context = request.cr, request.uid, request.context
|
||||
request.registry['res.users'].write(cr, uid, uid, {'forum': True}, context=context)
|
||||
request.registry['res.users'].write(cr, SUPERUSER_ID, uid, {'forum': True}, context=context)
|
||||
|
||||
create_context = dict(context)
|
||||
new_question_id = request.registry['website.forum.post'].create(
|
||||
|
@ -306,7 +305,7 @@ class website_forum(http.Controller):
|
|||
@http.route(['/forum/<model("website.forum"):forum>/question/<model("website.forum.post"):post>/editanswer'], type='http', auth="user", website=True, multilang=True)
|
||||
def edit_answer(self, forum, post, **kwargs):
|
||||
cr, uid, context = request.cr, request.uid, request.context
|
||||
request.registry['res.users'].write(cr, uid, uid, {'forum': True}, context=context)
|
||||
request.registry['res.users'].write(cr, SUPERUSER_ID, uid, {'forum': True}, context=context)
|
||||
for answer in post.child_ids:
|
||||
if answer.user_id.id == request.uid:
|
||||
post_answer = answer
|
||||
|
@ -322,7 +321,7 @@ class website_forum(http.Controller):
|
|||
@http.route('/forum/<model("website.forum"):forum>/question/saveanswer/', type='http', auth="user", multilang=True, methods=['POST'], website=True)
|
||||
def save_edited_answer(self, forum, **post):
|
||||
cr, uid, context = request.cr, request.uid, request.context
|
||||
request.registry['res.users'].write(cr, uid, uid, {'forum': True}, context=context)
|
||||
request.registry['res.users'].write(cr, SUPERUSER_ID, uid, {'forum': True}, context=context)
|
||||
answer_id = int(post.get('answer_id'))
|
||||
new_question_id = request.registry['website.forum.post'].write( cr, uid, [answer_id], {
|
||||
'content': post.get('answer_content'),
|
||||
|
@ -440,7 +439,7 @@ class website_forum(http.Controller):
|
|||
|
||||
@http.route('/forum/message_delete/', type='json', auth="user", multilang=True, methods=['POST'], website=True)
|
||||
def delete_comment(self, **kwarg):
|
||||
request.registry['mail.message'].unlink(request.cr, request.uid, [int(kwarg.get('message_id'))], context=request.context)
|
||||
request.registry['mail.message'].unlink(request.cr, SUPERUSER_ID, [int(kwarg.get('message_id'))], context=request.context)
|
||||
return True
|
||||
|
||||
@http.route('/forum/<model("website.forum"):forum>/edit/question/<model("website.forum.post"):post>', type='http', auth="user", multilang=True, website=True)
|
||||
|
@ -552,10 +551,11 @@ class website_forum(http.Controller):
|
|||
@http.route('/forum/<model("website.forum"):forum>/save/profile/', type='http', auth="user", multilang=True, website=True)
|
||||
def save_edited_profile(self, forum, **post):
|
||||
cr, uid, context = request.cr, request.uid, request.context
|
||||
request.registry['res.users'].write( cr, uid, [int(post.get('user_id'))], {
|
||||
User = request.registry['res.users']
|
||||
User.write(cr, SUPERUSER_ID, [int(post.get('user_id'))], {
|
||||
'name': post.get('name'),
|
||||
}, context=context)
|
||||
record_id = request.registry['res.users'].browse(cr, uid, int(post.get('user_id')),context=context).partner_id.id
|
||||
record_id = User.browse(cr, uid, int(post.get('user_id')),context=context).partner_id.id
|
||||
request.registry['res.partner'].write( cr, uid, [record_id], {
|
||||
'website': post.get('website'),
|
||||
'city': post.get('city'),
|
||||
|
@ -579,7 +579,7 @@ class website_forum(http.Controller):
|
|||
'comment': html2plaintext(post.content),
|
||||
}
|
||||
question = post.parent_id.id
|
||||
request.registry['website.forum.post'].unlink(request.cr, request.uid, [post.id], context=request.context)
|
||||
request.registry['website.forum.post'].unlink(request.cr, SUPERUSER_ID, [post.id], context=request.context)
|
||||
return self.post_comment(forum, question, **values)
|
||||
|
||||
@http.route('/forum/get_tags/', type='json', auth="public", multilang=True, methods=['POST'], website=True)
|
||||
|
|
|
@ -86,7 +86,7 @@ class Post(osv.Model):
|
|||
|
||||
def _get_vote(self, cr, uid, ids, context=None):
|
||||
result = {}
|
||||
for vote in self.pool.get('website.forum.post.vote').browse(cr, uid, ids, context=context):
|
||||
for vote in self.pool['website.forum.post.vote'].browse(cr, uid, ids, context=context):
|
||||
result[vote.post_id.id] = True
|
||||
return result.keys()
|
||||
|
||||
|
@ -116,7 +116,7 @@ class Post(osv.Model):
|
|||
|
||||
def _get_views(self, cr, uid, ids, context=None):
|
||||
result = {}
|
||||
for statistic in self.pool.get('website.forum.post.statistics').browse(cr, uid, ids, context=context):
|
||||
for statistic in self.pool['website.forum.post.statistics'].browse(cr, uid, ids, context=context):
|
||||
result[statistic.post_id.id] = True
|
||||
return result.keys()
|
||||
|
||||
|
@ -211,7 +211,7 @@ class Post(osv.Model):
|
|||
question = self.browse(cr, uid, vals.get("parent_id"), context=context)
|
||||
vals['name'] = question.name
|
||||
#add 2 karma to user when asks question.
|
||||
self.pool.get('res.users').write(cr, uid, [vals.get('user_id')], {'karma': 2}, context=context)
|
||||
self.pool['res.users'].write(cr, SUPERUSER_ID, [vals.get('user_id')], {'karma': 2}, context=context)
|
||||
post_id = super(Post, self).create(cr, uid, vals, context=create_context)
|
||||
self.message_post(cr, uid, [post_id], body=_(body), subtype=subtype, context=context)
|
||||
return post_id
|
||||
|
@ -232,7 +232,7 @@ class Post(osv.Model):
|
|||
value = 15
|
||||
elif vals.get('correct') == False:
|
||||
value = -15
|
||||
self.pool['res.users'].write(cr, uid, [post.user_id.id], {'karma': value}, context=context)
|
||||
self.pool['res.users'].write(cr, SUPERUSER_ID, [post.user_id.id], {'karma': value}, context=context)
|
||||
return super(Post, self).write(cr, uid, ids, vals, context=context)
|
||||
|
||||
class PostStatistics(osv.Model):
|
||||
|
@ -257,7 +257,7 @@ class Users(osv.Model):
|
|||
def _get_user_badge_level(self, cr, uid, ids, name, args, context=None):
|
||||
"""Return total badge per level of users"""
|
||||
result = dict.fromkeys(ids, False)
|
||||
badge_user_obj = self.pool.get('gamification.badge.user')
|
||||
badge_user_obj = self.pool['gamification.badge.user']
|
||||
for id in ids:
|
||||
result[id] = {
|
||||
'gold_badge': badge_user_obj.search(cr, uid, [('badge_id.level', '=', 'gold'), ('user_id', '=', id)], context=context, count=True),
|
||||
|
@ -328,7 +328,7 @@ class Vote(osv.Model):
|
|||
record = Post.browse(cr, uid, vals.get('post_id'), context=context)
|
||||
#Add 10 karma when user get up vote and subtract 10 karma when gets down vote.
|
||||
value = 10 if vals.get('vote') == '1' else -10
|
||||
self.pool['res.users'].write(cr, uid, [record.user_id.id], {'karma': value}, context=context)
|
||||
self.pool['res.users'].write(cr, SUPERUSER_ID, [record.user_id.id], {'karma': value}, context=context)
|
||||
body = "voted %s %s" % ('answer' if record.parent_id else 'question','up' if vals.get('vote')==1 else 'down')
|
||||
Post.message_post(cr, uid, [record.id], body=_(body), context=context)
|
||||
return vote_id
|
||||
|
@ -349,7 +349,7 @@ class Vote(osv.Model):
|
|||
value = -10
|
||||
elif record.vote == '-1' or new_vote == '1':
|
||||
value = 10
|
||||
self.pool['res.users'].write(cr, uid, [record.post_id.user_id.id], {'karma': value}, context=context)
|
||||
self.pool['res.users'].write(cr, SUPERUSER_ID, [record.post_id.user_id.id], {'karma': value}, context=context)
|
||||
self.write(cr, uid, vote_ids, {
|
||||
'vote': new_vote
|
||||
}, context=context)
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
|
||||
,,,,,,,
|
||||
|
||||
access_website_forum,website.forum,model_website_forum,,1,0,0,0
|
||||
access_website_forum_post,website.forum.post,model_website_forum_post,,1,0,0,0
|
||||
access_website_forum_post_history,website.forum.post.history,model_website_forum_post_history,,1,0,0,0
|
||||
access_website_forum_post_vote,website.forum.post.vote,model_website_forum_post_vote,,1,0,0,0
|
||||
access_website_forum_post,website.forum.post,model_website_forum_post,,1,1,1,0
|
||||
access_website_forum_post_history,website.forum.post.history,model_website_forum_post_history,,1,1,1,0
|
||||
access_website_forum_post_vote,website.forum.post.vote,model_website_forum_post_vote,,1,1,1,0
|
||||
access_website_forum_post_reason,website.forum.post.reason,model_website_forum_post_reason,,1,0,0,0
|
||||
access_website_forum_post_statistics,website.forum.post.statistics,model_website_forum_post_statistics,,1,0,0,0
|
||||
access_website_forum_tag,website.forum.tag,model_website_forum_tag,,1,0,0,0
|
||||
access_website_forum_tag,website.forum.tag,model_website_forum_tag,,1,0,1,0
|
||||
access_gamification_badge_user,gamification.badge.user,gamification.model_gamification_badge_user,,1,0,0,0
|
||||
access_gamification_badge,gamification_badge,gamification.model_gamification_badge,,1,0,0,0
|
||||
|
|
|
|
@ -9,8 +9,8 @@ $(document).ready(function () {
|
|||
'vote': value})
|
||||
.then(function (data) {
|
||||
if (data == false){
|
||||
vote_alert = $link.parents().find("#vote_alert");
|
||||
if (vote_alert.length <= 1) {
|
||||
vote_alert = $link.parent().find("#vote_alert");
|
||||
if (vote_alert.length == 0) {
|
||||
var $warning = $('<div class="alert alert-danger alert-dismissable" id="vote_alert" style="position:absolute; margin-top: -30px; margin-left: 90px;">'+
|
||||
'<button type="button" class="close notification_close" data-dismiss="alert" aria-hidden="true">×</button>'+
|
||||
'Sorry, you cannot vote for your own posts'+
|
||||
|
|
Loading…
Reference in New Issue