Beispiel #1
0
def update_permission(group, user, perm, value):
    pathname = get_pathname(group)
    if not get_access(pathname).get("admin"):
        raise frappe.PermissionError

    permission = frappe.get_doc("Website Route Permission", {
        "website_route": pathname,
        "user": user
    })
    permission.set(perm, int(value))
    permission.save(ignore_permissions=True)

    # send email
    if perm == "admin" and int(value):
        group_title = frappe.db.get_value("Website Route", pathname,
                                          "page_title")

        subject = "You have been made Administrator of Group " + group_title

        send(recipients=[user],
             subject=subject,
             add_unsubscribe_link=False,
             message="""<h3>Group Notification<h3>\
			<p>%s</p>\
			<p style="color: #888">This is just for your information.</p>""" % subject)
Beispiel #2
0
def add_comment(args=None):
    """
		args = {
			'comment': '',
			'comment_by': '',
			'comment_by_fullname': '',
			'comment_doctype': '',
			'comment_docname': '',
			'page_name': '',
		}
	"""

    if not args:
        args = frappe.local.form_dict
    args['doctype'] = "Comment"

    page_name = args.get("page_name")
    if "page_name" in args:
        del args["page_name"]
    if "cmd" in args:
        del args["cmd"]

    comment = frappe.get_doc(args)
    comment.ignore_permissions = True
    comment.insert()

    # since comments are embedded in the page, clear the web cache
    clear_cache(page_name)

    # notify commentors
    commentors = [
        d[0] for d in frappe.db.sql(
            """select comment_by from tabComment where
		comment_doctype=%s and comment_docname=%s and
		ifnull(unsubscribed, 0)=0""", (comment.comment_doctype,
                                 comment.comment_docname))
    ]

    owner = frappe.db.get_value(comment.comment_doctype,
                                comment.comment_docname, "owner")
    recipients = commentors if owner == "Administrator" else list(
        set(commentors + [owner]))

    from frappe.utils.email_lib.bulk import send
    send(recipients=recipients,
         doctype='Comment',
         email_field='comment_by',
         subject=_("New comment on {0} {1}").format(comment.comment_doctype,
                                                    comment.comment_docname),
         message=_("{0} by {1}").format(
             markdown2.markdown(args.get("comment")),
             comment.comment_by_fullname),
         ref_doctype=comment.comment_doctype,
         ref_docname=comment.comment_docname)

    template = frappe.get_template("templates/includes/comment.html")

    return template.render({"comment": comment.as_dict()})
Beispiel #3
0
def add_comment(args=None):
    """
		args = {
			'comment': '',
			'comment_by': '',
			'comment_by_fullname': '',
			'comment_doctype': '',
			'comment_docname': '',
			'page_name': '',
		}
	"""

    if not args:
        args = frappe.local.form_dict
    args["doctype"] = "Comment"

    page_name = args.get("page_name")
    if "page_name" in args:
        del args["page_name"]
    if "cmd" in args:
        del args["cmd"]

    comment = frappe.get_doc(args)
    comment.ignore_permissions = True
    comment.insert()

    # since comments are embedded in the page, clear the web cache
    clear_cache(page_name)

    # notify commentors
    commentors = [
        d[0]
        for d in frappe.db.sql(
            """select comment_by from tabComment where
		comment_doctype=%s and comment_docname=%s and
		ifnull(unsubscribed, 0)=0""",
            (comment.comment_doctype, comment.comment_docname),
        )
    ]

    owner = frappe.db.get_value(comment.comment_doctype, comment.comment_docname, "owner")
    recipients = commentors if owner == "Administrator" else list(set(commentors + [owner]))

    from frappe.utils.email_lib.bulk import send

    send(
        recipients=recipients,
        doctype="Comment",
        email_field="comment_by",
        subject=_("New comment on {0} {1}").format(comment.comment_doctype, comment.comment_docname),
        message=_("{0} by {1}").format(markdown2.markdown(args.get("comment")), comment.comment_by_fullname),
        ref_doctype=comment.comment_doctype,
        ref_docname=comment.comment_docname,
    )

    template = frappe.get_template("templates/includes/comment.html")

    return template.render({"comment": comment.as_dict()})
Beispiel #4
0
	def test_bulk(self):
		from frappe.utils.email_lib.bulk import send
		send(recipients = ['*****@*****.**', '*****@*****.**'], 
			sender="*****@*****.**",
			doctype='User', email_field='email',
			subject='Testing Bulk', message='This is a bulk mail!')
		
		bulk = frappe.db.sql("""select * from `tabBulk Email` where status='Not Sent'""", as_dict=1)
		self.assertEquals(len(bulk), 2)
		self.assertTrue('*****@*****.**' in [d['recipient'] for d in bulk])
		self.assertTrue('*****@*****.**' in [d['recipient'] for d in bulk])
		self.assertTrue('Unsubscribe' in bulk[0]['message'])
Beispiel #5
0
def add_comment(args=None):
	"""
		args = {
			'comment': '',
			'comment_by': '',
			'comment_by_fullname': '',
			'comment_doctype': '',
			'comment_docname': '',
			'page_name': '',
		}
	"""
	
	if not args: 
		args = frappe.local.form_dict
	args['doctype'] = "Comment"

	page_name = args.get("page_name")
	if "page_name" in args:
		del args["page_name"]
	if "cmd" in args:
		del args["cmd"]

	comment = frappe.bean(args)
	comment.ignore_permissions = True
	comment.insert()
	
	# since comments are embedded in the page, clear the web cache
	clear_cache(page_name)

	# notify commentors 
	commentors = [d[0] for d in frappe.db.sql("""select comment_by from tabComment where
		comment_doctype=%s and comment_docname=%s and
		ifnull(unsubscribed, 0)=0""", (comment.doc.comment_doctype, comment.doc.comment_docname))]
	
	owner = frappe.db.get_value(comment.doc.comment_doctype, comment.doc.comment_docname, "owner")
	
	from frappe.utils.email_lib.bulk import send
	send(recipients=list(set(commentors + [owner])), 
		doctype='Comment', 
		email_field='comment_by', 
		subject='New Comment on %s: %s' % (comment.doc.comment_doctype, 
			comment.doc.title or comment.doc.comment_docname), 
		message='%(comment)s<p>By %(comment_by_fullname)s</p>' % args,
		ref_doctype=comment.doc.comment_doctype, ref_docname=comment.doc.comment_docname)
	
	template = frappe.get_template("templates/includes/comment.html")
	
	return template.render({"comment": comment.doc.fields})
	
Beispiel #6
0
    def test_bulk(self):
        from frappe.utils.email_lib.bulk import send
        send(recipients=['*****@*****.**', '*****@*****.**'],
             sender="*****@*****.**",
             doctype='User',
             email_field='email',
             subject='Testing Bulk',
             message='This is a bulk mail!')

        bulk = frappe.db.sql(
            """select * from `tabBulk Email` where status='Not Sent'""",
            as_dict=1)
        self.assertEquals(len(bulk), 2)
        self.assertTrue('*****@*****.**' in [d['recipient'] for d in bulk])
        self.assertTrue('*****@*****.**' in [d['recipient'] for d in bulk])
        self.assertTrue('Unsubscribe' in bulk[0]['message'])
Beispiel #7
0
	def send_bulk(self):
		self.validate_send()

		sender = self.send_from or frappe.utils.get_formatted_email(self.owner)

		from frappe.utils.email_lib.bulk import send

		if not frappe.flags.in_test:
			frappe.db.auto_commit_on_many_writes = True

		send(recipients = self.recipients, sender = sender,
			subject = self.subject, message = self.message,
			doctype = self.send_to_doctype, email_field = self.email_field or "email_id",
			ref_doctype = self.doctype, ref_docname = self.name)

		if not frappe.flags.in_test:
			frappe.db.auto_commit_on_many_writes = False
Beispiel #8
0
	def send_bulk(self):
		self.validate_send()

		sender = self.doc.send_from or frappe.utils.get_formatted_email(self.doc.owner)
		
		from frappe.utils.email_lib.bulk import send
		
		if not frappe.flags.in_test:
			frappe.db.auto_commit_on_many_writes = True

		send(recipients = self.recipients, sender = sender, 
			subject = self.doc.subject, message = self.doc.message,
			doctype = self.send_to_doctype, email_field = self.email_field or "email_id",
			ref_doctype = self.doc.doctype, ref_docname = self.doc.name)

		if not frappe.flags.in_test:
			frappe.db.auto_commit_on_many_writes = False
Beispiel #9
0
    def test_bulk(self):
        from frappe.utils.email_lib.bulk import send

        send(
            recipients=["*****@*****.**", "*****@*****.**"],
            sender="*****@*****.**",
            doctype="User",
            email_field="email",
            subject="Testing Bulk",
            message="This is a bulk mail!",
        )

        bulk = frappe.db.sql("""select * from `tabBulk Email` where status='Not Sent'""", as_dict=1)
        self.assertEquals(len(bulk), 2)
        self.assertTrue("*****@*****.**" in [d["recipient"] for d in bulk])
        self.assertTrue("*****@*****.**" in [d["recipient"] for d in bulk])
        self.assertTrue("Unsubscribe" in bulk[0]["message"])
Beispiel #10
0
    def send_email_on_reply(self):
        owner_fullname = get_fullname(self.owner)

        parent_post = frappe.get_doc("Post", self.parent_post)

        message = self.get_reply_email_message(self.name, owner_fullname)

        # send email to the owner of the post, if he/she is different
        if parent_post.owner != self.owner:
            send(
                recipients=[parent_post.owner],
                subject="{someone} replied to your post".format(
                    someone=owner_fullname),
                message=message,

                # to allow unsubscribe
                doctype='Post',
                email_field='owner',

                # for tracking sent status
                ref_doctype=self.doctype,
                ref_docname=self.name)

        # send email to members who part of the conversation
        participants = frappe.db.sql(
            """select owner, name from `tabPost`
			where parent_post=%s and owner not in (%s, %s) order by creation asc""",
            (self.parent_post, parent_post.owner, self.owner),
            as_dict=True)

        send(
            recipients=[p.owner for p in participants],
            subject="{someone} replied to a post by {other}".format(
                someone=owner_fullname, other=get_fullname(parent_post.owner)),
            message=message,

            # to allow unsubscribe
            doctype='Post',
            email_field='owner',

            # for tracking sent status
            ref_doctype=self.doctype,
            ref_docname=self.name)
Beispiel #11
0
def update_permission(group, user, perm, value):
	doc = frappe.get_doc("Website Group", group)
	pathname = doc.get_route()
	if not get_access(doc, pathname).get("admin"):
		raise frappe.PermissionError

	permission = frappe.get_doc("Website Route Permission",
		{"website_route": pathname, "user": user, "reference": group})
	permission.set(perm, int(value))
	permission.save(ignore_permissions=True)

	# send email
	if perm=="admin" and int(value):
		subject = "You have been made Administrator of Group " + doc.group_title

		send(recipients=[user],
			subject= subject, add_unsubscribe_link=False,
			message="""<h3>Group Notification<h3>\
			<p>%s</p>\
			<p style="color: #888">This is just for your information.</p>""" % subject)
Beispiel #12
0
def send_daily_summary(for_date=None, event_date=None):
	if not for_date:
		for_date = add_days(today(), days=-1)
	if not event_date:
		event_date = today()
	
	formatted_date = getdate(for_date).strftime("%a, %d %B, %Y")
	formatted_event_date = getdate(event_date).strftime("%a, %d %B, %Y")
	subject = "[AAP Ka Manch] Updates for {formatted_date}".format(formatted_date=formatted_date)
	posts, events = get_posts_and_events(for_date, event_date)
	
	if not (posts or events):
		# no updates!
		return
		
	for user in frappe.conn.sql_list("""select name from `tabProfile`
		where user_type='Website User' and enabled=1 
		and name not in ('Administrator', 'Guest')"""):
		
		summary = prepare_daily_summary(user, posts, events, {
			"formatted_date": formatted_date, 
			"formatted_event_date": formatted_event_date
		})
		
		if not summary:
			# no access!
			continue
			
		send(recipients=[user], 
			subject=subject, 
			message=summary,
		
			# to allow unsubscribe
			doctype='Profile', 
			email_field='name', 
			
			# for tracking sent status
			ref_doctype="Profile", ref_docname=user)
Beispiel #13
0
	def send_email_on_reply(self):
		owner_fullname = get_fullname(self.owner)

		parent_post = frappe.get_doc("Post", self.parent_post)

		message = self.get_reply_email_message(self.name, owner_fullname)

		# send email to the owner of the post, if he/she is different
		if parent_post.owner != self.owner:
			send(recipients=[parent_post.owner],
				subject="{someone} replied to your post".format(someone=owner_fullname),
				message=message,

				# to allow unsubscribe
				doctype='Post',
				email_field='owner',

				# for tracking sent status
				ref_doctype=self.doctype, ref_docname=self.name)

		# send email to members who part of the conversation
		participants = frappe.db.sql("""select owner, name from `tabPost`
			where parent_post=%s and owner not in (%s, %s) order by creation asc""",
			(self.parent_post, parent_post.owner, self.owner), as_dict=True)

		send(recipients=[p.owner for p in participants],
			subject="{someone} replied to a post by {other}".format(someone=owner_fullname,
				other=get_fullname(parent_post.owner)),
			message=message,

			# to allow unsubscribe
			doctype='Post',
			email_field='owner',

			# for tracking sent status
			ref_doctype=self.doctype, ref_docname=self.name)
Beispiel #14
0
    def test_unsubscribe(self):
        from frappe.utils.email_lib.bulk import unsubscribe, send
        frappe.local.form_dict = {
            'email': '*****@*****.**',
            'type': 'Profile',
            'email_field': 'email',
            "from_test": True
        }
        unsubscribe()

        send(recipients=['*****@*****.**', '*****@*****.**'],
             sender="*****@*****.**",
             doctype='Profile',
             email_field='email',
             subject='Testing Bulk',
             message='This is a bulk mail!')

        bulk = frappe.db.sql(
            """select * from `tabBulk Email` where status='Not Sent'""",
            as_dict=1)
        self.assertEquals(len(bulk), 1)
        self.assertFalse('*****@*****.**' in [d['recipient'] for d in bulk])
        self.assertTrue('*****@*****.**' in [d['recipient'] for d in bulk])
        self.assertTrue('Unsubscribe' in bulk[0]['message'])