frappe / erpnext

Free and Open Source Enterprise Resource Planning (ERP)
https://erpnext.com
GNU General Public License v3.0
20.48k stars 7.09k forks source link

[BUG] [v12] Possible Bug in Permissions. Users are unable to create doctype if Only if Creator Checked #32763

Closed adityaduggal closed 1 year ago

adityaduggal commented 3 years ago

Description of the issue

Users having access to create Stock Reconciliation or maybe any other doctype are unable to create the document if they are limited to view only documents created by the user.

Context information (for bug reports)

Output of bench version

aditya:v12-bench$ bench version
WARN: bench is installed in editable mode!

This is not the recommended mode of installation for production. Instead, install the package from PyPI with: `pip install frappe-bench`

erpnext 12.13.0
frappe 12.11.0

Steps to reproduce the issue

  1. Create a User and give it a permission for Stock Reconciliation as shown below (Check Only If Creator) image

  2. Now ask the user to create the Stock Reconciliation, the user gets an error that he/she does not have access to stock reconciliation.

Observed result

The user is not allowed to create or save the stock reconciliation but since its a permission issue it should be applicable to all other doctypes as well.

Expected result

The user should be able to create the document since the user has the permission to create the document as shown in the image above

Stacktrace / full error message

Traceback (most recent call last):
  File "/data/v12-bench/apps/frappe/frappe/desk/form/save.py", line 21, in savedocs
    doc.save()
  File "/data/v12-bench/apps/frappe/frappe/model/document.py", line 273, in save
    return self._save(*args, **kwargs)
  File "/data/v12-bench/apps/frappe/frappe/model/document.py", line 309, in _save
    self.run_before_save_methods()
  File "/data/v12-bench/apps/frappe/frappe/model/document.py", line 896, in run_before_save_methods
    self.run_method("validate")
  File "/data/v12-bench/apps/frappe/frappe/model/document.py", line 797, in run_method
    out = Document.hook(fn)(self, *args, **kwargs)
  File "/data/v12-bench/apps/frappe/frappe/model/document.py", line 1073, in composer
    return composed(self, method, *args, **kwargs)
  File "/data/v12-bench/apps/frappe/frappe/model/document.py", line 1056, in runner
    add_to_return_value(self, fn(self, *args, **kwargs))
  File "/data/v12-bench/apps/frappe/frappe/model/document.py", line 791, in <lambda>
    fn = lambda self, *args, **kwargs: getattr(self, method)(*args, **kwargs)
  File "/data/v12-bench/apps/erpnext/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py", line 30, in validate
    self.remove_items_with_no_change()
  File "/data/v12-bench/apps/erpnext/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py", line 81, in remove_items_with_no_change
    items = list(filter(lambda d: _changed(d), self.items))
  File "/data/v12-bench/apps/erpnext/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py", line 81, in <lambda>
    items = list(filter(lambda d: _changed(d), self.items))
  File "/data/v12-bench/apps/erpnext/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py", line 54, in _changed
    item_dict = get_stock_balance_for(item.item_code, item.warehouse,
  File "/data/v12-bench/apps/erpnext/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py", line 506, in get_stock_balance_for
    frappe.has_permission("Stock Reconciliation", "write", throw = True)
  File "/data/v12-bench/apps/frappe/frappe/__init__.py", line 619, in has_permission
    frappe.throw(_("No permission for {0}").format(doctype))
  File "/data/v12-bench/apps/frappe/frappe/__init__.py", line 377, in throw
    msgprint(msg, raise_exception=exc, title=title, indicator='red', is_minimizable=is_minimizable)
  File "/data/v12-bench/apps/frappe/frappe/__init__.py", line 356, in msgprint
    _raise_exception()
  File "/data/v12-bench/apps/frappe/frappe/__init__.py", line 316, in _raise_exception
    raise raise_exception(msg)
frappe.exceptions.ValidationError: No permission for Stock Reconciliation

request.js:355 Traceback (most recent call last):
  File "/data/v12-bench/apps/frappe/frappe/app.py", line 64, in application
    response = frappe.api.handle()
  File "/data/v12-bench/apps/frappe/frappe/api.py", line 59, in handle
    return frappe.handler.handle()
  File "/data/v12-bench/apps/frappe/frappe/handler.py", line 24, in handle
    data = execute_cmd(cmd)
  File "/data/v12-bench/apps/frappe/frappe/handler.py", line 64, in execute_cmd
    return frappe.call(method, **frappe.form_dict)
  File "/data/v12-bench/apps/frappe/frappe/__init__.py", line 1064, in call
    return fn(*args, **newargs)
  File "/data/v12-bench/apps/frappe/frappe/desk/form/save.py", line 21, in savedocs
    doc.save()
  File "/data/v12-bench/apps/frappe/frappe/model/document.py", line 273, in save
    return self._save(*args, **kwargs)
  File "/data/v12-bench/apps/frappe/frappe/model/document.py", line 309, in _save
    self.run_before_save_methods()
  File "/data/v12-bench/apps/frappe/frappe/model/document.py", line 896, in run_before_save_methods
    self.run_method("validate")
  File "/data/v12-bench/apps/frappe/frappe/model/document.py", line 797, in run_method
    out = Document.hook(fn)(self, *args, **kwargs)
  File "/data/v12-bench/apps/frappe/frappe/model/document.py", line 1073, in composer
    return composed(self, method, *args, **kwargs)
  File "/data/v12-bench/apps/frappe/frappe/model/document.py", line 1056, in runner
    add_to_return_value(self, fn(self, *args, **kwargs))
  File "/data/v12-bench/apps/frappe/frappe/model/document.py", line 791, in <lambda>
    fn = lambda self, *args, **kwargs: getattr(self, method)(*args, **kwargs)
  File "/data/v12-bench/apps/erpnext/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py", line 30, in validate
    self.remove_items_with_no_change()
  File "/data/v12-bench/apps/erpnext/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py", line 81, in remove_items_with_no_change
    items = list(filter(lambda d: _changed(d), self.items))
  File "/data/v12-bench/apps/erpnext/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py", line 81, in <lambda>
    items = list(filter(lambda d: _changed(d), self.items))
  File "/data/v12-bench/apps/erpnext/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py", line 54, in _changed
    item_dict = get_stock_balance_for(item.item_code, item.warehouse,
  File "/data/v12-bench/apps/erpnext/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py", line 506, in get_stock_balance_for
    frappe.has_permission("Stock Reconciliation", "write", throw = True)
  File "/data/v12-bench/apps/frappe/frappe/__init__.py", line 619, in has_permission
    frappe.throw(_("No permission for {0}").format(doctype))
  File "/data/v12-bench/apps/frappe/frappe/__init__.py", line 377, in throw
    msgprint(msg, raise_exception=exc, title=title, indicator='red', is_minimizable=is_minimizable)
  File "/data/v12-bench/apps/frappe/frappe/__init__.py", line 356, in msgprint
    _raise_exception()
  File "/data/v12-bench/apps/frappe/frappe/__init__.py", line 316, in _raise_exception
    raise raise_exception(msg)
frappe.exceptions.ValidationError: No permission for Stock Reconciliation

Additional information

OS version / distribution, Frappe install method, etc.

ankush commented 1 year ago