Skip to content

Commit

Permalink
[15.0][MIG] mail_activity_board: Migration to 15.0
Browse files Browse the repository at this point in the history
  • Loading branch information
JoanMForgeFlow committed Nov 18, 2021
1 parent cf0791d commit 770076d
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 97 deletions.
13 changes: 10 additions & 3 deletions mail_activity_board/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,21 @@
{
"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",
"author": "SDi, David Juaneda, Sodexis, Odoo Community Association (OCA)",
"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.js',
],
'web.assets_qweb': [
'mail_activity_board/static/src/components/chatter_topbar/chatter_topbar.xml',
],
},
}
64 changes: 0 additions & 64 deletions mail_activity_board/models/mail_activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,68 +62,4 @@ def _find_allowed_doc_ids(self, model_ids):
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
25 changes: 11 additions & 14 deletions mail_activity_board/tests/test_mail_activity_board.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,19 @@ def setUp(self):
# 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,
Expand All @@ -32,7 +33,7 @@ def setUp(self):
)

# 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(
Expand All @@ -41,7 +42,7 @@ def setUp(self):
"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(
Expand All @@ -50,7 +51,7 @@ def setUp(self):
"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(
Expand All @@ -60,7 +61,7 @@ def setUp(self):
"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,
}
)

Expand All @@ -78,7 +79,7 @@ def setUp(self):
"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,
}
)
Expand All @@ -91,7 +92,7 @@ def setUp(self):
"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,
}
)
Expand All @@ -104,7 +105,7 @@ def setUp(self):
"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,
}
)
Expand Down Expand Up @@ -194,8 +195,4 @@ def test_redirect_to_activities(self):
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)

2 changes: 1 addition & 1 deletion mail_activity_board/views/mail_activity_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
15 changes: 0 additions & 15 deletions mail_activity_board/views/templates.xml

This file was deleted.

0 comments on commit 770076d

Please sign in to comment.