Skip to content
Snippets Groups Projects
Commit 206fed61 authored by Benjami's avatar Benjami
Browse files

WIP: Added methods into community and user to get admins

parent c7b610f8
No related branches found
No related tags found
2 merge requests!253[REL] Release 06/11/23,!191V1 imrpvements to CompanyEasyCreation wizard (CRM Lead execution)🙋‍
......@@ -155,6 +155,17 @@ class ResCompany(models.Model):
admins_user_ids.append(role_line.user_id.id)
return any([user in admins_user_ids for user in company_user_ids])
def get_ce_admins(self):
admins = []
role_lines = self.env["res.users.role.line"].sudo().search([
("allowed_company_ids.id", "=", self.id), # It's M2M, = is okey?
("active", "=", True),
("role_id.code", "=", "role_ce_admin")
])
for role_line in role_lines:
admins.append(role_line.user_id)
return admins
def add_ce_admin(self, user):
if self.hierarchy_level != COMMUNITY_HIERARCHY:
raise UserError(_("Only a CE can have CE admins"))
......@@ -191,7 +202,7 @@ class ResCompany(models.Model):
def get_ce_members(self, domain_key="in_kc_and_active"):
domains_dict = {
"in_kc_and_active": [
("company_id", "=", self.id),
("company_id", "=", self.id), # TODO: company_ids ??
("oauth_uid", "!=", None),
("active", "=", True),
]
......
......@@ -195,3 +195,15 @@ class ResUsers(models.Model):
def get_role_codes(self):
# TODO Map all code to company and enable (We should update the API schema too)
return self.role_line_ids[0].role_id.code
def get_administrared_ce(self):
communities = []
role_lines = self.env["res.users.role.line"].sudo().search([
("user_id.id", "=", self.id),
("active", "=", True),
("role_id.code", "=", "role_ce_admin")
])
for role_line in role_lines:
for company in role_line.allowed_company_ids:
communities.append(company.id)
return communities
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment