Browse Source

Aug 22: [FIX] Bug Fixed 'model_access_rights'

pull/195/merge
Risvana Cybro 1 month ago
parent
commit
4c3f002672
  1. 2
      model_access_rights/__manifest__.py
  2. 7
      model_access_rights/doc/RELEASE_NOTES.md
  3. 65
      model_access_rights/models/access_right.py
  4. BIN
      model_access_rights/static/description/assets/screenshots/s3.png
  5. 4
      model_access_rights/static/description/index.html
  6. 44
      model_access_rights/static/src/js/form_controller.js
  7. 45
      model_access_rights/static/src/js/kanban_controller.js
  8. 44
      model_access_rights/static/src/js/list_controller.js

2
model_access_rights/__manifest__.py

@ -21,7 +21,7 @@
##############################################################################
{
'name': 'Hide Create|Delete|Archive|Export Options - Model Wise',
'version': '15.0.1.0.1',
'version': '15.0.2.0.0',
'category': 'Extra Tools',
'summary': """Hide module features for user groups.""",
'description': """

7
model_access_rights/doc/RELEASE_NOTES.md

@ -9,3 +9,10 @@
#### Version 15.0.1.0.1
#### BUG FIX
- Fixed issue of export action not appearing in res.groups list view after module installation
#### 14.07.2025
#### Version 15.0.2.0.0
#### UPDT
- Added a new option to restrict model access rights for certain user.

65
model_access_rights/models/access_right.py

@ -33,7 +33,7 @@ class AccessRight(models.Model):
model_id = fields.Many2one('ir.model', ondelete='cascade',
required=True, string="Model",
help="Select the model")
groups_id = fields.Many2one('res.groups', required=True,
groups_id = fields.Many2one('res.groups',
string="Groups", help="Select the group")
is_delete = fields.Boolean(string="Delete", help="Hide the delete option")
is_export = fields.Boolean(string="Export",
@ -43,30 +43,45 @@ class AccessRight(models.Model):
help="Hide the create option "
"from list as well as form view")
is_archive = fields.Boolean(string="Archive/UnArchive",
help="Hide the archive option")
help="hide the archive option")
restriction_type = fields.Selection([
('user', 'User Wise'),
('group', 'Group Wise')
], 'Restriction Type', required=True, default="group")
user_id = fields.Many2one('res.users',
help="select the user")
@api.model
def hide_buttons(self, args):
"""Returns the visibility settings for buttons per model and group."""
user = self.env['res.users'].browse(args[0])
model_name = args[1]
access_right_rec = self.sudo().search_read([
('model_id.model', '=', model_name),
('groups_id', 'in', user.groups_id.ids)
], ['is_delete', 'is_export', 'is_create_or_update', 'is_archive'])
if access_right_rec:
rec = access_right_rec[0] # If multiple, first match wins
return {
'is_delete': rec['is_delete'],
'is_export': rec['is_export'],
'is_create_or_update': rec['is_create_or_update'],
'is_archive': rec['is_archive']
}
return {
'is_delete': False,
'is_export': False,
'is_create_or_update': False,
'is_archive': False
}
def hide_buttons(self):
"""This function contains a query that detects which all options want
to hide, in which model,and to which user groups"""
access_right_rec = self.sudo().search_read([], ['model_id', 'is_delete',
'is_export',
'is_create_or_update',
'is_archive',
'restriction_type',
'user_id',
'groups_id'])
for dic in access_right_rec:
model = self.env['ir.model'].sudo().browse(dic['model_id'][0]).model
if dic['restriction_type'] == "group":
group_name = self.env['ir.model.data'].sudo().search([
('model', '=', 'res.groups'),
('res_id', '=', dic['groups_id'][0])
]).name
module_name = self.env['ir.model.data'].sudo().search([
('model', '=', 'res.groups'),
('res_id', '=', dic['groups_id'][0])
]).module
else:
group_name=False
module_name=False
dic.update({
'model': model,
'group_name': group_name,
'module': module_name,
'restriction_type': dic['restriction_type'],
'user': dic['user_id']
})
return access_right_rec

BIN
model_access_rights/static/description/assets/screenshots/s3.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 107 KiB

After

Width:  |  Height:  |  Size: 99 KiB

4
model_access_rights/static/description/index.html

@ -156,7 +156,7 @@
<div class="d-flex align-items-center"
style="margin-top: 30px; margin-bottom: 30px">
<img src="assets/misc/check-box.png" class="mr-2"/>
<span style="font-family: 'Montserrat', sans-serif; font-size: 18px; font-weight: bold;">Can hide the options for specific user group</span>
<span style="font-family: 'Montserrat', sans-serif; font-size: 18px; font-weight: bold;">Can hide the options for specific user group or user</span>
</div>
<div class="d-flex align-items-center"
style="margin-top: 30px; margin-bottom: 30px">
@ -201,7 +201,7 @@
<h3 style="font-family: 'Montserrat', sans-serif; font-size: 18px; font-weight: bold;">
Select the group of any user, model in which it is applied.
Here 'User:Own Documents Only' in 'Sales' is selected.<br/>
Imp: Features will be hidden for all the users with this group.
Imp: Features will be hidden for all the users with this group or user.
</h3>
<img src="assets/screenshots/s3.png" class="img-thumbnail">
</div>

44
model_access_rights/static/src/js/form_controller.js

@ -5,6 +5,7 @@
import FormController from 'web.FormController';
import { patch } from "@web/core/utils/patch";
import rpc from 'web.rpc';
import session from 'web.session';
patch(FormController.prototype, 'model_access_rights/static/src/js/form_controller.js.FormController', {
/**
* This function will used to hide the selected options from the form view
@ -14,18 +15,37 @@ patch(FormController.prototype, 'model_access_rights/static/src/js/form_controll
var user_id = self.initialState.context.uid;
var model = self.modelName;
await rpc.query({model: 'access.right', method: 'hide_buttons',
args: [[user_id, model]],
}).then(function(data) {
if(data){
if(data['is_create_or_update']){
self.activeActions.create = false;
self.activeActions.edit = false;
}
if(data['is_delete']){
self.activeActions.delete = false;
}
if(data['is_archive']){
self.archiveEnabled = false;
args: [],
}).then(function(result) {
for (var i = 0; i < result.length; i++) {
var group = result[i].module + "." + result[i].group_name
if (self.modelName == result[i].model) {
if (result[i].restriction_type == "group") {
if (session.user_has_group(group)) {
if (!session.is_admin) {
if (result[i].is_create_or_update) {
self.activeActions.create = false
self.activeActions.edit = false
}
if (result[i].is_delete) {
self.activeActions.delete = false
}
}
}
} else {
if (user_id == result[i].user[0]) {
if (!this.user.isAdmin) {
if (result[i].is_create_or_update) {
self.activeActions.create = false
self.activeActions.edit = false
}
if (result[i].is_delete) {
self.activeActions.delete = false
}
}
}
}
}
}
});

45
model_access_rights/static/src/js/kanban_controller.js

@ -5,30 +5,49 @@
import KanbanController from 'web.KanbanController';
import { patch } from "@web/core/utils/patch";
import rpc from 'web.rpc';
import session from 'web.session';
patch(KanbanController.prototype, 'model_access_rights/static/src/js/kanban_controller.js.KanbanController', {
/**
* This function will used to hide the selected options from the kanban view
*/
async willStart() {
var self = this;
var user_id = self.initialState.context.uid;
var model = self.modelName;
await rpc.query({model: 'access.right', method: 'hide_buttons',
args: [[user_id, model]],
}).then(function(data) {
if(data){
if(data['is_create_or_update']){
self.activeActions.create = false;
self.activeActions.edit = false;
args: [],
}).then(function(result) {
for (var i = 0; i < result.length; i++) {
var group = result[i].module + "." + result[i].group_name
if (self.modelName == result[i].model) {
if (result[i].restriction_type == "group") {
if (session.user_has_group(group)) {
if (!session.is_admin) {
if (result[i].is_create_or_update) {
// self.props.archInfo.activeActions.create = false
// self.props.archInfo.activeActions.edit = false
this.is_action_enabled('edit')= false
this.is_action_enabled('create')= false
}
if(data['is_delete']){
self.activeActions.delete = false;
if (result[i].is_delete) {
self.props.archInfo.activeActions.delete = false
}
if(data['is_archive']){
self.archiveEnabled = false;
}
if(data['is_export']){
self.isExportEnable = false;
}
} else {
if (user_id == result[i].user[0]) {
if (!self.user.isAdmin) {
if (result[i].is_create_or_update) {
self.props.archInfo.activeActions.create = false
self.props.archInfo.activeActions.edit = false
}
if (result[i].is_delete) {
self.props.archInfo.activeActions.delete = false
}
}
}
}
}
}
});

44
model_access_rights/static/src/js/list_controller.js

@ -5,6 +5,9 @@
import ListController from 'web.ListController';
import { patch } from "@web/core/utils/patch";
import rpc from 'web.rpc';
import { useService } from "@web/core/utils/hooks";
import session from 'web.session';
patch(ListController.prototype, 'model_access_rights/static/src/js/list_controller.js.ListController', {
/**
* This function will used to hide the selected options from the list view
@ -14,23 +17,42 @@ patch(ListController.prototype, 'model_access_rights/static/src/js/list_controll
var user_id = self.initialState.context.uid;
var model = self.modelName;
await rpc.query({model: 'access.right', method: 'hide_buttons',
args: [[user_id, model]],
}).then(function(data) {
if(data){
if(data['is_create_or_update']){
args: [],
}).then(function(result) {
for (var i = 0; i < result.length; i++) {
var group = result[i].module + "." + result[i].group_name
if (self.modelName == result[i].model) {
if (result[i].restriction_type == "group") {
if (session.user_has_group(group)) {
if (!session.is_admin) {
if (result[i].is_create_or_update) {
self.activeActions.create = false;
self.activeActions.edit = false;
}
if(data['is_delete']){
if (result[i].is_export) {
self.isExportEnable = false
self.isExportEnable = false
}
if (result[i].is_delete) {
self.activeActions.delete = false;
}
if(data['is_archive']){
self.archiveEnabled = false;
}
if (data['is_export']) {
self.isExportEnable = false;
}
} else {
self.isExportEnable = true;
if (user_id == result[i].user[0]) {
if (!this.user.isAdmin) {
if (result[i].is_create_or_update) {
self.activeActions.create = false;
}
if (result[i].is_export) {
self.isExportEnable = false
self.isExportEnable = false
}
if (result[i].is_delete) {
self.activeActions.delete = false;
}
}
}
}
}
}
});

Loading…
Cancel
Save