def assign_post(post, profile=None): post = webnotes.bean("Post", post) if not get_access(post.doc.unit).get("write"): raise webnotes.PermissionError("You are not allowed edit this post") if profile and not get_access(post.doc.unit, profile).get("write"): raise webnotes.PermissionError("Selected user does not have 'write' access to this post") if profile and post.doc.assigned_to: webnotes.throw("Someone is already assigned to this post. Please refresh.") if not profile and post.doc.status == "Completed": webnotes.throw("You cannot revoke assignment of a completed task.") post.doc.status = "Assigned" if profile else None post.doc.assigned_to = profile post.doc.assigned_to_fullname = get_fullname(profile) if profile else None post.ignore_permissions = True post.save() return { "post_settings_html": get_post_settings(post.doc.unit, post.doc.name), "assigned_to_fullname": post.doc.assigned_to_fullname, "status": post.doc.status }
def add_post(unit, content, picture, picture_name, parent_post=None): access = get_access(unit) if not access.get("write"): raise webnotes.PermissionError post = webnotes.bean({ "doctype":"Post", "content": markdown2.markdown(content), "unit": unit, "parent_post": parent_post or None }) post.ignore_permissions = True post.insert() if picture_name and picture: file_data = save_file(picture_name, picture, "Post", post.doc.name, decode=True) post.doc.picture_url = file_data.file_name or file_data.file_url webnotes.conn.set_value("Post", post.doc.name, "picture_url", post.doc.picture_url) post.doc.fields.update(webnotes.conn.get_value("Profile", webnotes.session.user, ["first_name", "last_name", "fb_username"], as_dict=True)) webnotes.cache().delete_value("unit_html:" + unit) return webnotes.get_template("templates/includes/inline_post.html").render({"post":post.doc.fields, "write": access.get("write")})
def update_permission(unit, profile, perm, value): if not get_access(unit).get("admin"): raise webnotes.PermissionError unit = webnotes.bean("Unit", unit) unit.doclist.get({"profile":profile})[0].fields[perm] = int(value) unit.ignore_permissions = True unit.save()
def set_event(post, event_datetime): post = webnotes.bean("Post", post) if not get_access(post.doc.unit).get("write"): raise webnotes.PermissionError("You are not allowed edit this post") post.doc.event_datetime = event_datetime post.ignore_permissions = True post.save() return get_post_settings(post.doc.unit, post.doc.name)
def update_task_status(post, status): post = webnotes.bean("Post", post) if not get_access(post.doc.unit).get("write"): raise webnotes.PermissionError("You are not allowed edit this post") if post.doc.assigned_to and status: post.doc.status = status post.ignore_permissions = True post.save() return get_post_settings(post.doc.unit, post.doc.name)
def get_unit_settings_html(unit): if not get_access(unit).get("admin"): raise webnotes.PermissionError unit_profiles = webnotes.conn.sql("""select pr.first_name, pr.last_name, pr.fb_username, pr.fb_location, pr.fb_hometown, up.profile, up.`read`, up.`write`, up.`admin` from tabProfile pr, `tabUnit Profile` up where up.profile = pr.name and up.parent=%s""", (unit,), as_dict=1) return webnotes.get_template("templates/includes/unit_settings.html").render({ "public": webnotes.conn.get_value("Unit", unit, "public"), "unit_profiles": unit_profiles })
def get_post_settings(unit, post_name): if not get_access(unit).get("write"): raise webnotes.PermissionError post = webnotes.bean("Post", post_name).doc if post.unit != unit: raise webnotes.ValidationError("Post does not belong to unit.") profile = None if post.assigned_to: profile = webnotes.conn.get_value("Profile", post.assigned_to, ["first_name", "last_name", "fb_username", "fb_location", "fb_hometown"], as_dict=True) return webnotes.get_template("templates/includes/post_settings.html").render({ "post": post, "unit_profile": profile, "status_options": (webnotes.get_doctype("Post").get_options("status") or "").split("\n") })
def get_post_list_html(unit, limit_start=0, limit_length=20): access = get_access(unit) if webnotes.local.form_dict.cmd=="get_post_list_html": # for paging if not access.get("read"): raise webnotes.PermissionError posts = webnotes.conn.sql("""select p.name, p.unit, p.status, p.assigned_to, p.event_datetime, p.assigned_to_fullname, p.picture_url, p.creation, p.content, pr.fb_username, pr.first_name, pr.last_name, (select count(pc.name) from `tabPost` pc where pc.parent_post=p.name) as post_reply_count from tabPost p, tabProfile pr where p.unit=%s and pr.name = p.owner and ifnull(p.parent_post, '')='' order by p.creation desc limit %s, %s""", (unit, limit_start, limit_length), as_dict=True) return webnotes.get_template("templates/includes/post_list.html", filters={"scrub_url": scrub_url})\ .render({"posts": posts, "limit_start":limit_start, "write": access.get("write")})
def add_unit_profile(unit, profile): if not get_access(unit).get("admin"): raise webnotes.PermissionError unit = webnotes.bean("Unit", unit) unit.doclist.append({ "doctype": "Unit Profile", "parentfield": "unit_profiles", "profile": profile, "read": 1 }) unit.ignore_permissions = True unit.save() unit_profile = unit.doclist[-1].fields unit_profile.update(webnotes.conn.get_value("Profile", unit_profile.profile, ["first_name", "last_name", "fb_username", "fb_location", "fb_hometown"], as_dict=True)) return webnotes.get_template("templates/includes/unit_profile.html").render({ "unit_profile": unit_profile })