def execute():
	from frappe.core.page.user_properties import user_properties
	for warehouse, user in frappe.db.sql("""select parent, user from `tabWarehouse User`"""):
		user_properties.add(user, "Warehouse", warehouse)
	
	frappe.delete_doc("DocType", "Warehouse User")
	frappe.reload_doc("stock", "doctype", "warehouse")
Пример #2
0
    def test_allow_in_restriction(self):
        self.add_restricted_on_blogger()

        frappe.set_user("*****@*****.**")
        doc = frappe.get_doc("Blog Post", "_test-blog-post-1")
        self.assertFalse(doc.has_permission("read"))

        frappe.set_user("*****@*****.**")
        add("*****@*****.**", "Blog Post", "_test-blog-post-1")

        frappe.set_user("*****@*****.**")
        doc = frappe.get_doc("Blog Post", "_test-blog-post-1")

        self.assertTrue(doc.has_permission("read"))
Пример #3
0
	def test_allow_in_restriction(self):
		self.add_restricted_on_blogger()

		frappe.set_user("*****@*****.**")
		doc = frappe.get_doc("Blog Post", "_test-blog-post-1")
		self.assertFalse(doc.has_permission("read"))

		frappe.set_user("*****@*****.**")
		add("*****@*****.**", "Blog Post", "_test-blog-post-1")

		frappe.set_user("*****@*****.**")
		doc = frappe.get_doc("Blog Post", "_test-blog-post-1")

		self.assertTrue(doc.has_permission("read"))
Пример #4
0
    def test_allow_in_restriction(self):
        self.add_restricted_on_blogger()

        frappe.set_user("*****@*****.**")
        bean = frappe.bean("Blog Post", "_test-blog-post-1")
        self.assertFalse(bean.has_read_perm())

        frappe.set_user("*****@*****.**")
        add("*****@*****.**", "Blog Post", "_test-blog-post-1")

        frappe.set_user("*****@*****.**")
        bean = frappe.bean("Blog Post", "_test-blog-post-1")

        self.assertTrue(bean.has_read_perm())
Пример #5
0
def add(args=None):
	"""add in someone's to do list"""
	if not args:
		args = frappe.local.form_dict

	if frappe.db.sql("""select owner from `tabToDo`
		where reference_type=%(doctype)s and reference_name=%(name)s and status="Open"
		and owner=%(assign_to)s""", args):
		frappe.msgprint(_("Already in todo"), raise_exception=True)
		return
	else:
		from frappe.utils import nowdate

		d = frappe.get_doc({
			"doctype":"ToDo",
			"owner": args['assign_to'],
			"reference_type": args['doctype'],
			"reference_name": args['name'],
			"description": args.get('description'),
			"priority": args.get("priority", "Medium"),
			"status": "Open",
			"date": args.get('date', nowdate()),
			"assigned_by": args.get('assigned_by', frappe.user.name),
		}).insert(ignore_permissions=True)

		# set assigned_to if field exists
		if frappe.get_meta(args['doctype']).get_field("assigned_to"):
			frappe.db.set_value(args['doctype'], args['name'], "assigned_to", args['assign_to'])

	try:
		if cint(args.get("restrict")):
			from frappe.core.page.user_properties import user_properties
			user_properties.add(args['assign_to'], args['doctype'], args['name'])
			frappe.msgprint(_("Restriction added"))
	except frappe.PermissionError:
		frappe.throw(_("Not permitted to restrict User {0} for {1} {2}").format(args["assign_to"],
			args["doctype"], args["name"]))

	# notify
	if not args.get("no_notification"):
		notify_assignment(d.assigned_by, d.owner, d.reference_type, d.reference_name, action='ASSIGN', description=args.get("description"), notify=args.get('notify'))

	return get(args)
Пример #6
0
 def add_restriction_to_user2(self):
     frappe.set_user("*****@*****.**")
     add("*****@*****.**", "Blog Post", "_test-blog-post")
Пример #7
0
def add(args=None):
    """add in someone's to do list"""
    if not args:
        args = frappe.local.form_dict

    if frappe.db.sql(
            """select owner from `tabToDo`
		where reference_type=%(doctype)s and reference_name=%(name)s and status="Open"
		and owner=%(assign_to)s""", args):
        frappe.msgprint(_("Already in todo"), raise_exception=True)
        return
    else:
        from frappe.utils import nowdate

        d = frappe.get_doc({
            "doctype":
            "ToDo",
            "owner":
            args['assign_to'],
            "reference_type":
            args['doctype'],
            "reference_name":
            args['name'],
            "description":
            args.get('description'),
            "priority":
            args.get("priority", "Medium"),
            "status":
            "Open",
            "date":
            args.get('date', nowdate()),
            "assigned_by":
            args.get('assigned_by', frappe.user.name),
        }).insert(ignore_permissions=True)

        # set assigned_to if field exists
        if frappe.get_meta(args['doctype']).get_field("assigned_to"):
            frappe.db.set_value(args['doctype'], args['name'], "assigned_to",
                                args['assign_to'])

    try:
        if cint(args.get("restrict")):
            from frappe.core.page.user_properties import user_properties
            user_properties.add(args['assign_to'], args['doctype'],
                                args['name'])
            frappe.msgprint(_("Restriction added"))
    except frappe.PermissionError:
        frappe.throw(
            _("Not permitted to restrict User {0} for {1} {2}").format(
                args["assign_to"], args["doctype"], args["name"]))

    # notify
    if not args.get("no_notification"):
        notify_assignment(d.assigned_by,
                          d.owner,
                          d.reference_type,
                          d.reference_name,
                          action='ASSIGN',
                          description=args.get("description"),
                          notify=args.get('notify'))

    return get(args)
Пример #8
0
	def add_restriction_to_user2(self):
		frappe.set_user("*****@*****.**")
		add("*****@*****.**", "Blog Post", "_test-blog-post")
Пример #9
0
def add(args=None):
    """add in someone's to do list"""
    if not args:
        args = frappe.local.form_dict

    if frappe.db.sql(
            """select owner from `tabToDo`
		where reference_type=%(doctype)s and reference_name=%(name)s and status="Open"
		and owner=%(assign_to)s""", args):
        frappe.msgprint("Already in todo", raise_exception=True)
        return
    else:
        from frappe.utils import nowdate

        d = frappe.bean({
            "doctype":
            "ToDo",
            "owner":
            args['assign_to'],
            "reference_type":
            args['doctype'],
            "reference_name":
            args['name'],
            "description":
            args.get('description'),
            "priority":
            args.get("priority", "Medium"),
            "status":
            "Open",
            "date":
            args.get('date', nowdate()),
            "assigned_by":
            args.get('assigned_by', frappe.user.name),
        }).insert(ignore_permissions=True).doc

        # set assigned_to if field exists
        from frappe.model.meta import has_field
        if has_field(args['doctype'], "assigned_to"):
            frappe.db.set_value(args['doctype'], args['name'], "assigned_to",
                                args['assign_to'])

    try:
        if cint(args.get("restrict")):
            from frappe.core.page.user_properties import user_properties
            user_properties.add(args['assign_to'], args['doctype'],
                                args['name'])
            frappe.msgprint(_("Restriction added"))
    except frappe.PermissionError:
        frappe.throw(
            "{cannot}: {user}, {_for}: {doctype} {_and}: {name}".format(
                cannot=_("You cannot restrict User"),
                user=args['assign_to'],
                _for=_("for DocType"),
                doctype=_(args['doctype']),
                _and=_("and Name"),
                name=args['name']))

    # notify
    if not args.get("no_notification"):
        notify_assignment(d.assigned_by,
                          d.owner,
                          d.reference_type,
                          d.reference_name,
                          action='ASSIGN',
                          description=args.get("description"),
                          notify=args.get('notify'))

    # update feeed
    try:
        from erpnext.home import make_feed
        from frappe.utils import get_fullname
        make_feed('Assignment', d.reference_type, d.reference_name,
                  frappe.session['user'],
                  '[%s] Assigned to %s' % (d.priority, get_fullname(d.owner)),
                  '#C78F58')
    except ImportError, e:
        pass