[15.0][MIG] mail_activity_board: Migration to 15.0

This commit is contained in:
Joan Mateu Jordi 2021-11-17 09:00:11 +01:00 committed by augusto-weiss
parent 44ab910159
commit b288dd6137
8 changed files with 75 additions and 158 deletions

View File

@ -4,7 +4,7 @@
{
"name": "Mail Activity Board",
"summary": "Add Activity Boards",
"version": "14.0.1.0.0",
"version": "15.0.1.0.0",
"development_status": "Beta",
"category": "Social Network",
"website": "https://github.com/OCA/social",
@ -12,6 +12,13 @@
"license": "AGPL-3",
"installable": True,
"depends": ["calendar", "board"],
"data": ["views/templates.xml", "views/mail_activity_view.xml"],
"qweb": ["static/src/components/chatter_topbar/chatter_topbar.xml"],
"data": ["views/mail_activity_view.xml"],
"assets": {
"web.assets_backend": [
"mail_activity_board/static/src/components/chatter_topbar/chatter_topbar.esm.js",
],
"web.assets_qweb": [
"mail_activity_board/static/src/components/chatter_topbar/chatter_topbar.xml",
],
},
}

View File

@ -61,69 +61,3 @@ class MailActivity(models.Model):
continue
allowed_ids |= self._find_allowed_model_wise(doc_model, doc_dict)
return allowed_ids
@api.model
def _search(
self,
args,
offset=0,
limit=None,
order=None,
count=False,
access_rights_uid=None,
):
# Rules do not apply to administrator
if self.env.is_superuser():
return super(MailActivity, self)._search(
args,
offset=offset,
limit=limit,
order=order,
count=count,
access_rights_uid=access_rights_uid,
)
ids = super(MailActivity, self)._search(
args,
offset=offset,
limit=limit,
order=order,
count=False,
access_rights_uid=access_rights_uid,
)
if not ids and count:
return 0
elif not ids:
return ids
# check read access rights before checking the actual rules
super(
MailActivity, self.with_user(access_rights_uid or self._uid)
).check_access_rights("read")
model_ids = {}
self.flush(["res_id", "res_model_id", "res_model"])
for sub_ids in self._cr.split_for_in_conditions(ids):
self._cr.execute(
"""
SELECT DISTINCT a.id, im.id, im.model, a.res_id
FROM "%s" a
LEFT JOIN ir_model im ON im.id = a.res_model_id
WHERE a.id = ANY (%%(ids)s)"""
% self._table,
dict(ids=list(sub_ids)),
)
for a_id, _ir_model_id, model, model_id in self._cr.fetchall():
model_ids.setdefault(model, {}).setdefault(model_id, set()).add(a_id)
allowed_ids = self._find_allowed_doc_ids(model_ids)
final_ids = allowed_ids
if count:
return len(final_ids)
else:
# re-construct a list based on ids, because set didn't keep order
id_list = [a_id for a_id in ids if a_id in final_ids]
return id_list

View File

@ -0,0 +1,45 @@
/** @odoo-module **/
import {patch} from "web.utils";
import {ChatterTopbar} from "@mail/components/chatter_topbar/chatter_topbar";
const components = {ChatterTopbar};
// Import {rpc}
import rpc from "web.rpc";
patch(
components.ChatterTopbar.prototype,
"mail_activity_board/static/src/components/chatter_topbar/chatter_topbar.esm.js",
{
// --------------------------------------------------------------------------
// Handlers
// --------------------------------------------------------------------------
/**
* @private
* @param {MouseEvent} ev
*/
// eslint-disable-next-line no-unused-vars
_onListActivity(ev) {
var self = this;
rpc.query({
model: this.chatter.thread.model,
method: "redirect_to_activities",
args: [[]],
kwargs: {
id: this.chatter.thread.id,
model: this.chatter.thread.model,
},
context: {},
}).then(function (action) {
self.env.bus.trigger("do-action", {
action,
options: {
on_close: () => {
this.chatter.thread.refreshActivities();
this.chatter.thread.refresh();
},
},
});
});
},
}
);

View File

@ -1,57 +0,0 @@
/* Copyright 2018 David Juaneda
* Copyright 2021 Sodexis
* License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). */
odoo.define(
"mail_activity_board/static/src/components/chatter_topbar/chatter_topbar.js",
function (require) {
"use strict";
var rpc = require("web.rpc");
const components = {
ChatterTopbar: require("mail/static/src/components/chatter_topbar/chatter_topbar.js"),
};
const {patch} = require("web.utils");
patch(
components.ChatterTopbar,
"mail_activity_board/static/src/components/chatter_topbar/chatter_topbar.js",
{
// --------------------------------------------------------------------------
// Handlers
// --------------------------------------------------------------------------
/**
* @private
* @param {MouseEvent} ev
*/
// eslint-disable-next-line no-unused-vars
_onListActivity(ev) {
var self = this;
rpc.query({
model: this.chatter.thread.model,
method: "redirect_to_activities",
args: [[]],
kwargs: {
id: this.chatter.thread.id,
model: this.chatter.thread.model,
},
context: {},
}).then(function (action) {
self.env.bus.trigger("do-action", {
action,
options: {
on_close: () => {
this.chatter.thread.refreshActivities();
this.chatter.thread.refresh();
},
},
});
});
},
}
);
}
);

View File

@ -6,7 +6,7 @@
position="after"
>
<button
class="btn btn-link o_ChatterTopbar_button o_ChatterTopbar_buttonListActivity"
class="btn btn-link o_ChatterTopbar_button"
type="button"
t-att-disabled="chatter.isDisabled"
t-on-click="_onListActivity"

View File

@ -9,18 +9,27 @@ class TestMailActivityBoardMethods(TransactionCase):
# Set up activities
# Create a user as 'Crm Salesman' and added few groups
mail_activity_group = self.create_mail_activity_group()
self.employee = self.env["res.users"].create(
{
"company_id": self.env.ref("base.main_company").id,
"name": "Employee",
"login": "csu",
"email": "crmuser@yourcompany.com",
"groups_id": [(6, 0, [self.env.ref("base.group_user").id])],
"groups_id": [
(
6,
0,
[
self.env.ref("base.group_user").id,
],
)
],
}
)
# Create a user who doesn't have access to anything except activities
mail_activity_group = self.create_mail_activity_group()
self.employee2 = self.env["res.users"].create(
{
"company_id": self.env.ref("base.main_company").id,
@ -32,7 +41,7 @@ class TestMailActivityBoardMethods(TransactionCase):
)
# lead_model_id = self.env['ir.model']._get('crm.lead').id
partner_model_id = self.env["ir.model"]._get("res.partner").id
partner_model = self.env["ir.model"]._get("res.partner")
ActivityType = self.env["mail.activity.type"]
self.activity1 = ActivityType.create(
@ -41,7 +50,7 @@ class TestMailActivityBoardMethods(TransactionCase):
"delay_count": 5,
"delay_unit": "days",
"summary": "ACT 1 : Presentation, barbecue, ... ",
"res_model_id": partner_model_id,
"res_model": partner_model.model,
}
)
self.activity2 = ActivityType.create(
@ -50,7 +59,7 @@ class TestMailActivityBoardMethods(TransactionCase):
"delay_count": 6,
"delay_unit": "days",
"summary": "ACT 2 : I want to show you my ERP !",
"res_model_id": partner_model_id,
"res_model": partner_model.model,
}
)
self.activity3 = ActivityType.create(
@ -60,7 +69,7 @@ class TestMailActivityBoardMethods(TransactionCase):
"delay_unit": "days",
"summary": "ACT 3 : "
"Beers for everyone because I am a good salesman !",
"res_model_id": partner_model_id,
"res_model": partner_model.model,
}
)
@ -78,7 +87,7 @@ class TestMailActivityBoardMethods(TransactionCase):
"activity_type_id": self.activity3.id,
"note": "Partner activity 1.",
"res_id": self.partner_client.id,
"res_model_id": partner_model_id,
"res_model_id": partner_model.id,
"user_id": self.employee.id,
}
)
@ -91,7 +100,7 @@ class TestMailActivityBoardMethods(TransactionCase):
"activity_type_id": self.activity2.id,
"note": "Partner activity 2.",
"res_id": self.partner_client.id,
"res_model_id": partner_model_id,
"res_model_id": partner_model.id,
"user_id": self.employee.id,
}
)
@ -104,7 +113,7 @@ class TestMailActivityBoardMethods(TransactionCase):
"activity_type_id": self.activity3.id,
"note": "Partner activity 3.",
"res_id": self.partner_client.id,
"res_model_id": partner_model_id,
"res_model_id": partner_model.id,
"user_id": self.employee.id,
}
)
@ -193,9 +202,3 @@ class TestMailActivityBoardMethods(TransactionCase):
for act in acts:
self.assertIn(act, self.partner_client.activity_ids.ids)
def test_read_permissions(self):
search1 = self.env["mail.activity"].with_user(self.employee).search([])
self.assertEqual(len(search1), 3)
search2 = self.env["mail.activity"].with_user(self.employee2).search([])
self.assertEqual(len(search2), 0)

View File

@ -217,7 +217,7 @@
<field name="priority" eval="2" />
<field name="mode">primary</field>
<field name="arch" type="xml">
<xpath expr='//field[@name="res_model_id"]' position='before'>
<xpath expr='//field[@name="res_model"]' position='before'>
<field name="user_id" />
<field name="res_name" string="Origin" />
</xpath>

View File

@ -1,15 +0,0 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<template
id="assets_backend"
name="mail_activity_board assets"
inherit_id="web.assets_backend"
>
<xpath expr="." position="inside">
<script
type="text/javascript"
src="/mail_activity_board/static/src/components/chatter_topbar/chatter_topbar.js"
/>
</xpath>
</template>
</odoo>