Skip to content

Commit ab2948f

Browse files
committed
Merge PR OCA#638 into 14.0
Signed-off-by simahawk
2 parents 6d0c3d8 + 393fb4b commit ab2948f

File tree

13 files changed

+134
-0
lines changed

13 files changed

+134
-0
lines changed

base_user_empty_password/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from . import models
2+
from . import wizard
+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Copyright 2024 Camptocamp SA
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)
3+
{
4+
"name": "Empty users password",
5+
"summary": "Allows to empty password of users",
6+
"version": "14.0.1.0.0",
7+
"development_status": "Beta",
8+
"category": "Uncategorized",
9+
"website": "https://github.com/OCA/server-auth",
10+
"author": "Camptocamp, Odoo Community Association (OCA)",
11+
"maintainers": ["grindtildeath"],
12+
"license": "AGPL-3",
13+
"depends": [
14+
"base",
15+
],
16+
"data": [
17+
# "data/ir_actions.xml",
18+
"security/ir.model.access.csv",
19+
"views/res_users.xml",
20+
"wizard/empty_password.xml",
21+
],
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import res_users
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Copyright 2024 Camptocamp SA
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)
3+
from odoo import fields, models
4+
5+
6+
class ResUsers(models.Model):
7+
_inherit = "res.users"
8+
9+
has_password = fields.Boolean(compute="_compute_has_password")
10+
11+
def _compute_has_password(self):
12+
# Bypass ORM as password is always empty in cache
13+
self.env.cr.execute(
14+
"""SELECT id, password FROM res_users WHERE id IN %s;""", (tuple(self.ids),)
15+
)
16+
res = {row[0]: row[1] for row in self.env.cr.fetchall()}
17+
for user in self:
18+
user.has_password = bool(res.get(user.id))
19+
20+
def _empty_password(self):
21+
# Update in DB to avoid using crypt context
22+
self.env.cr.execute(
23+
"""UPDATE res_users SET password = %s WHERE id IN %s""",
24+
("", (tuple(self.ids),)),
25+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Akim Juillerat <akim.juilllerat@camptocamp.com>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
This module provides a wizard to allow emptying users password field.
2+
3+
This could be useful to force the user to use another sign on method than Odoo.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
2+
access_empty_password_wizard,access_empty_password_wizard,model_empty_password_wizard,base.group_erp_manager,1,1,1,1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<odoo>
3+
<record id="view_users_form" model="ir.ui.view">
4+
<field name="name">res.users.form</field>
5+
<field name="model">res.users</field>
6+
<field name="inherit_id" ref="base.view_users_form" />
7+
<field name="arch" type="xml">
8+
<xpath expr="//notebook" position="before">
9+
<group name="password_defined" groups="base.group_no_one">
10+
<field name="has_password" />
11+
</group>
12+
</xpath>
13+
</field>
14+
</record>
15+
</odoo>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import empty_password
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Copyright 2024 Camptocamp SA
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)
3+
from odoo import fields, models
4+
5+
6+
class EmptyPasswordWizard(models.TransientModel):
7+
_name = "empty.password.wizard"
8+
_description = "Empty Password Wizard"
9+
10+
user_ids = fields.Many2many(
11+
"res.users", readonly=True, default=lambda w: w._default_user_ids()
12+
)
13+
14+
def _default_user_ids(self):
15+
return (
16+
self.env.context.get("active_model") == "res.users"
17+
and self.env.context.get("active_ids")
18+
or []
19+
)
20+
21+
def empty_password_button(self):
22+
self.ensure_one()
23+
self.user_ids._empty_password()
24+
return {"type": "ir.actions.client", "tag": "reload"}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<odoo>
3+
<record id="empty_password_wizard_view" model="ir.ui.view">
4+
<field name="name">Empty Password</field>
5+
<field name="model">empty.password.wizard</field>
6+
<field name="arch" type="xml">
7+
<form string="Empty Password">
8+
<field name="user_ids" invisible="1" />
9+
<div>
10+
<p>Are you sure you want to empty password of selected users?</p>
11+
</div>
12+
<footer>
13+
<button
14+
string="Empty Password"
15+
name="empty_password_button"
16+
type="object"
17+
class="btn-primary"
18+
/>
19+
<button string="Cancel" class="btn-secondary" special="cancel" />
20+
</footer>
21+
</form>
22+
</field>
23+
</record>
24+
<record id="empty_password_wizard_action" model="ir.actions.act_window">
25+
<field name="name">Empty Password</field>
26+
<field name="res_model">empty.password.wizard</field>
27+
<field name="view_mode">form</field>
28+
<field name="target">new</field>
29+
<field name="binding_model_id" ref="base.model_res_users" />
30+
</record>
31+
</odoo>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../../base_user_empty_password
+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import setuptools
2+
3+
setuptools.setup(
4+
setup_requires=['setuptools-odoo'],
5+
odoo_addon=True,
6+
)

0 commit comments

Comments
 (0)