예제 #1
0
	def validate_user_limit(self):
		'''
			Validate if user limit has been reached for System Users
			Checked in 'Validate' event as we don't want welcome email sent if max users are exceeded.
		'''

		if self.user_type == "Website User":
			return

		if not self.enabled:
			# don't validate max users when saving a disabled user
			return

		limits = get_limits()
		if not limits.users:
			# no limits defined
			return

		total_users = get_total_users()
		if self.is_new():
			# get_total_users gets existing users in database
			# a new record isn't inserted yet, so adding 1
			total_users += 1

		if total_users > limits.users:
			frappe.throw(_("Sorry. You have reached the maximum user limit for your subscription. You can either disable an existing user or buy a higher subscription plan."),
				MaxUsersReachedError)
예제 #2
0
파일: user.py 프로젝트: bopopescu/frappe11
    def validate_user_limit(self):
        '''
			Validate if user limit has been reached for System Users
			Checked in 'Validate' event as we don't want welcome email sent if max users are exceeded.
		'''

        if self.user_type == "Website User":
            return

        if not self.enabled:
            # don't validate max users when saving a disabled user
            return

        limits = get_limits()
        if not limits.users:
            # no limits defined
            return

        total_users = get_total_users()
        if self.is_new():
            # get_total_users gets existing users in database
            # a new record isn't inserted yet, so adding 1
            total_users += 1

        if total_users > limits.users:
            frappe.throw(
                _("Sorry. You have reached the maximum user limit for your subscription. You can either disable an existing user or buy a higher subscription plan."
                  ), MaxUsersReachedError)
예제 #3
0
def get():
    """get session boot info"""
    from frappe.desk.notifications import \
     get_notification_info_for_boot, get_notifications
    from frappe.boot import get_bootinfo, get_unseen_notes
    from frappe.limits import get_limits, get_expiry_message

    bootinfo = None
    if not getattr(frappe.conf, 'disable_session_cache', None):
        # check if cache exists
        bootinfo = frappe.cache().hget("bootinfo", frappe.session.user)
        if bootinfo:
            bootinfo['from_cache'] = 1
            bootinfo["notification_info"].update(get_notifications())
            bootinfo["user"]["recent"] = json.dumps(\
             frappe.cache().hget("user_recent", frappe.session.user))

    if not bootinfo:
        # if not create it
        bootinfo = get_bootinfo()
        bootinfo["notification_info"] = get_notification_info_for_boot()
        frappe.cache().hset("bootinfo", frappe.session.user, bootinfo)
        try:
            frappe.cache().ping()
        except redis.exceptions.ConnectionError:
            message = _(
                "Redis cache server not running. Please contact Administrator / Tech support"
            )
            if 'messages' in bootinfo:
                bootinfo['messages'].append(message)
            else:
                bootinfo['messages'] = [message]

        # check only when clear cache is done, and don't cache this
        if frappe.local.request:
            bootinfo["change_log"] = get_change_log()
            bootinfo["in_setup_wizard"] = not cint(
                frappe.db.get_single_value('System Settings',
                                           'setup_complete'))
            bootinfo["is_first_startup"] = cint(
                frappe.db.get_single_value('System Settings',
                                           'is_first_startup'))

    bootinfo["metadata_version"] = frappe.cache().get_value("metadata_version")
    if not bootinfo["metadata_version"]:
        bootinfo["metadata_version"] = frappe.reset_metadata_version()

    bootinfo.notes = get_unseen_notes()

    for hook in frappe.get_hooks("extend_bootinfo"):
        frappe.get_attr(hook)(bootinfo=bootinfo)

    bootinfo["lang"] = frappe.translate.get_user_lang()
    bootinfo["disable_async"] = frappe.conf.disable_async

    # limits
    bootinfo.limits = get_limits()
    bootinfo.expiry_message = get_expiry_message()

    return bootinfo
예제 #4
0
def restrict_email_group(doc, method):
	from frappe.limits import get_limits

	email_group_limit = get_limits().get('email_group')
	if not email_group_limit:
		return

	email_group = frappe.get_doc("Email Group", doc.email_group)
	if email_group.get_total_subscribers() >= email_group_limit:
		frappe.throw(_("Please Upgrade to add more than {0} subscribers").format(email_group_limit))
예제 #5
0
def restrict_email_group(doc, method):
	from frappe.limits import get_limits

	email_group_limit = get_limits().get('email_group')
	if not email_group_limit:
		return

	email_group = frappe.get_doc("Email Group", doc.email_group)
	if email_group.get_total_subscribers() >= email_group_limit:
		frappe.throw(_("Please Upgrade to add more than {0} subscribers").format(email_group_limit))
예제 #6
0
def get():
	"""get session boot info"""
	from frappe.desk.notifications import \
		get_notification_info_for_boot, get_notifications
	from frappe.boot import get_bootinfo, get_unseen_notes
	from frappe.limits import get_limits, get_expiry_message

	bootinfo = None
	if not getattr(frappe.conf,'disable_session_cache', None):
		# check if cache exists
		bootinfo = frappe.cache().hget("bootinfo", frappe.session.user)
		if bootinfo:
			bootinfo['from_cache'] = 1
			bootinfo["notification_info"].update(get_notifications())
			bootinfo["user"]["recent"] = json.dumps(\
				frappe.cache().hget("user_recent", frappe.session.user))

	if not bootinfo:
		# if not create it
		bootinfo = get_bootinfo()
		bootinfo["notification_info"] = get_notification_info_for_boot()
		frappe.cache().hset("bootinfo", frappe.session.user, bootinfo)
		try:
			frappe.cache().ping()
		except redis.exceptions.ConnectionError:
			message = _("Redis cache server not running. Please contact Administrator / Tech support")
			if 'messages' in bootinfo:
				bootinfo['messages'].append(message)
			else:
				bootinfo['messages'] = [message]

		# check only when clear cache is done, and don't cache this
		if frappe.local.request:
			bootinfo["change_log"] = get_change_log()
			bootinfo["in_setup_wizard"] = not cint(frappe.db.get_single_value('System Settings', 'setup_complete'))
			bootinfo["is_first_startup"] = cint(frappe.db.get_single_value('System Settings', 'is_first_startup'))

	bootinfo["metadata_version"] = frappe.cache().get_value("metadata_version")
	if not bootinfo["metadata_version"]:
		bootinfo["metadata_version"] = frappe.reset_metadata_version()

	bootinfo.notes = get_unseen_notes()

	for hook in frappe.get_hooks("extend_bootinfo"):
		frappe.get_attr(hook)(bootinfo=bootinfo)

	bootinfo["lang"] = frappe.translate.get_user_lang()
	bootinfo["disable_async"] = frappe.conf.disable_async

	# limits
	bootinfo.limits = get_limits()
	bootinfo.expiry_message = get_expiry_message()

	return bootinfo
예제 #7
0
def restrict_email_group(doc, method):
    warnings.warn(
        "restrict_email_group will be deprecated. Please create a custom method for this functionality.",
        FutureWarning)
    from frappe.limits import get_limits

    email_group_limit = get_limits().get('email_group')
    if not email_group_limit:
        return

    email_group = frappe.get_doc("Email Group", doc.email_group)
    if email_group.get_total_subscribers() >= email_group_limit:
        frappe.throw(
            _("Please Upgrade to add more than {0} subscribers").format(
                email_group_limit))
예제 #8
0
def clear_limits(context, site, limits):
	"""Clears given limit from the site config, and removes limit from site config if its empty"""
	from frappe.limits import clear_limit as _clear_limit
	if not limits:
		return

	if not site:
		site = get_site(context)

	with frappe.init_site(site):
		_clear_limit(limits)

		# Remove limits from the site_config, if it's empty
		limits = get_limits()
		if not limits:
			update_site_config('limits', 'None', validate=False)
예제 #9
0
파일: site.py 프로젝트: nikunj1222/frappe7
def clear_limits(context, site, limits):
    """Clears given limit from the site config, and removes limit from site config if its empty"""
    from frappe.limits import clear_limit as _clear_limit
    if not limits:
        return

    if not site:
        site = get_site(context)

    with frappe.init_site(site):
        _clear_limit(limits)

        # Remove limits from the site_config, if it's empty
        limits = get_limits()
        if not limits:
            update_site_config('limits', 'None', validate=False)
예제 #10
0
	def prevent_email_queue_delete(self):
		'''If email limit is set, don't allow users to delete Email Queue record'''
		if get_limits().emails and frappe.session.user != 'Administrator':
			frappe.throw(_('Only Administrator can delete Email Queue'))
	def prevent_email_queue_delete(self):
		'''If email limit is set, don't allow users to delete Email Queue record'''
		if get_limits().emails and frappe.session.user != 'Administrator':
			frappe.throw(_('Only Administrator can delete Email Queue'))
예제 #12
0
def execute():
    limits = get_limits()
    if limits and limits.upgrade_link:
        upgrade_url = limits.upgrade_link
        clear_limit('upgrade_link')
        update_limits({'upgrade_url': upgrade_url})
def execute():
	limits = get_limits()
	if limits and limits.upgrade_link:
		upgrade_url = limits.upgrade_link
		clear_limit('upgrade_link')
		update_limits({'upgrade_url': upgrade_url})
예제 #14
0
>>>>>>> 176d241496ede1357a309fa44a037b757a252581

	bootinfo["metadata_version"] = frappe.cache().get_value("metadata_version")
	if not bootinfo["metadata_version"]:
		bootinfo["metadata_version"] = frappe.reset_metadata_version()

	bootinfo.notes = get_unseen_notes()

	for hook in frappe.get_hooks("extend_bootinfo"):
		frappe.get_attr(hook)(bootinfo=bootinfo)

	bootinfo["lang"] = frappe.translate.get_user_lang()
	bootinfo["disable_async"] = frappe.conf.disable_async

	# limits
	bootinfo.limits = get_limits()
	bootinfo.expiry_message = get_expiry_message()

	return bootinfo

def get_csrf_token():
	if not frappe.local.session.data.csrf_token:
		generate_csrf_token()

	return frappe.local.session.data.csrf_token

def generate_csrf_token():
	frappe.local.session.data.csrf_token = frappe.generate_hash()
	frappe.local.session_obj.update(force=True)

	# send sid and csrf token to the user