feat: Set expiry to document link

This commit is contained in:
Suraj Shetty 2022-01-13 11:45:45 +05:30
parent 64985a5d1a
commit 4ee99ce7e1
10 changed files with 104 additions and 17 deletions

View file

@ -1286,7 +1286,7 @@ class Document(BaseDocument):
"reference_docname": self.name,
"status": "Active",
"key": key
})
}, cache=True)
def get_liked_by(self):
liked_by = getattr(self, "_liked_by", None)

View file

@ -712,4 +712,7 @@
<symbol xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" id="icon-crop">
<path d="M14.88,11.63H4.33V1.12m7.34,10.51v3.25M6,4.37h5.64V10M1.13,4.37h3.2" stroke-linecap="round" stroke-linejoin="round"/>
</symbol>
<symbol viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg" id="icon-clipboard">
<path fill-rule="evenodd" clip-rule="evenodd" d="M5.5 4.0029C5.28752 4.00587 5.11559 4.01186 4.96784 4.02393C4.69617 4.04612 4.59545 4.0838 4.54601 4.10899C4.35785 4.20487 4.20487 4.35785 4.10899 4.54601C4.0838 4.59545 4.04612 4.69617 4.02393 4.96784C4.00078 5.25117 4 5.62345 4 6.2V10.8C4 11.3766 4.00078 11.7488 4.02393 12.0322C4.04612 12.3038 4.0838 12.4045 4.10899 12.454C4.20487 12.6422 4.35785 12.7951 4.54601 12.891C4.59545 12.9162 4.69617 12.9539 4.96784 12.9761C5.25117 12.9992 5.62345 13 6.2 13H9.8C10.3766 13 10.7488 12.9992 11.0322 12.9761C11.3038 12.9539 11.4045 12.9162 11.454 12.891C11.6422 12.7951 11.7951 12.6422 11.891 12.454C11.9162 12.4045 11.9539 12.3038 11.9761 12.0322C11.9992 11.7488 12 11.3766 12 10.8V6.2C12 5.62345 11.9992 5.25117 11.9761 4.96784C11.9539 4.69617 11.9162 4.59545 11.891 4.54601C11.7951 4.35785 11.6422 4.20487 11.454 4.10899C11.4045 4.0838 11.3038 4.04612 11.0322 4.02393C10.8844 4.01186 10.7125 4.00587 10.5 4.0029C10.4984 4.82999 9.82746 5.5 9 5.5H7C6.17254 5.5 5.50157 4.82999 5.5 4.0029ZM10.2924 3.00087C11.0944 3.00548 11.548 3.03457 11.908 3.21799C12.2843 3.40973 12.5903 3.71569 12.782 4.09202C13 4.51984 13 5.0799 13 6.2V10.8C13 11.9201 13 12.4802 12.782 12.908C12.5903 13.2843 12.2843 13.5903 11.908 13.782C11.4802 14 10.9201 14 9.8 14H6.2C5.0799 14 4.51984 14 4.09202 13.782C3.71569 13.5903 3.40973 13.2843 3.21799 12.908C3 12.4802 3 11.9201 3 10.8V6.2C3 5.07989 3 4.51984 3.21799 4.09202C3.40973 3.71569 3.71569 3.40973 4.09202 3.21799C4.45199 3.03457 4.90558 3.00548 5.70764 3.00087C6.09322 2.11745 6.9745 1.5 8 1.5C9.0255 1.5 9.90678 2.11745 10.2924 3.00087ZM6.5 4C6.5 3.17157 7.17157 2.5 8 2.5C8.82843 2.5 9.5 3.17157 9.5 4C9.5 4.27614 9.27614 4.5 9 4.5H7C6.72386 4.5 6.5 4.27614 6.5 4Z" stroke="none" fill="var(--icon-stroke)"/>
</symbol>
</svg>

Before

Width:  |  Height:  |  Size: 93 KiB

After

Width:  |  Height:  |  Size: 94 KiB

View file

@ -58,7 +58,7 @@ frappe.ui.form.ControlData = class ControlData extends frappe.ui.form.ControlInp
this.has_input = true;
this.bind_change_event();
this.setup_autoname_check();
this.setup_copy_button();
if (this.df.options == 'URL') {
this.setup_url_field();
}
@ -112,6 +112,18 @@ frappe.ui.form.ControlData = class ControlData extends frappe.ui.form.ControlInp
});
}
setup_copy_button() {
if (this.df.with_copy_button) {
this.$wrapper.find('.control-input').append(
`<button class="btn action-btn">
${frappe.utils.icon('clipboard', 'sm')}
</button>`
).find(".action-btn").click(() => {
frappe.utils.copy_to_clipboard(this.value);
});
}
}
setup_barcode_field() {
this.$wrapper.find('.control-input').append(
`<span class="link-btn">

View file

@ -62,6 +62,8 @@ frappe.ui.form.ControlDate = class ControlDate extends frappe.ui.form.ControlDat
dateFormat: date_format,
startDate: this.get_start_date(),
keyboardNav: false,
minDate: this.df.min_date,
maxDate: this.df.max_date,
onSelect: () => {
this.$input.trigger('change');
},

View file

@ -1139,6 +1139,47 @@ frappe.ui.form.Form = class FrappeForm {
});
}
share_doc_link() {
const share_document_url_dialog = new frappe.ui.Dialog({
fields: [{
fieldname: "visibility",
label: "Visibility",
fieldtype: "Select",
options: "Public\nPrivate",
default: "Public",
read_only_depends_on: "eval: doc.link"
}, {
fieldname: "link_expiration_date",
label: "Link Expiration Date",
fieldtype: "Date",
min_date: new Date(),
read_only_depends_on: "eval: doc.link"
}, {
fieldtype: "Button",
label: "Generate Link",
click: () => {
this.call("get_new_document_key").then(res => {
let key = res.message;
share_document_url_dialog.set_value("link", this.get_share_link(key))
})
}
}, {
fieldname: "link",
label: "Link",
fieldtype: "Data",
depends_on: "eval: doc.link",
with_copy_button: true
}],
size: "small",
title: __("Share {} Link", [this.doctype]),
})
share_document_url_dialog.show()
}
get_share_link(key) {
return `${window.origin}/${this.doctype}/${this.docname}?key=${key}`;
}
copy_doc(onload, from_amend) {
this.validate_form_action("Create");
var newdoc = frappe.model.copy_doc(this.doc, from_amend);

View file

@ -265,6 +265,13 @@ frappe.ui.form.Toolbar = class Toolbar {
});
}
// share print view link
if (frappe.model.can_email(null, me.frm) && me.frm.doc.docstatus < 2) {
this.page.add_menu_item(__("Share Link", [me.frm.doctype]), function() {
me.frm.share_doc_link();
}, true);
}
// go to field modal
this.page.add_menu_item(__("Jump to field"), function() {
me.show_jump_to_field_dialog();

View file

@ -288,13 +288,25 @@ textarea.form-control {
position: relative;
}
.link-btn {
position: absolute;
top: 4px;
right: 4px;
padding: 3px;
display: none;
z-index: 3;
.frappe-control {
.action-btn {
position: absolute;
top: 4px;
right: 4px;
padding: 3px;
z-index: 3;
}
button.action-btn {
padding: 3px 5px;
background-color: var(--fg-color);
}
.link-btn {
@extend .action-btn;
background-color: none;
display: none;
}
}
.phone-btn {

View file

@ -219,7 +219,7 @@
--border-radius-full: 999px;
--primary-color: #2490EF;
--btn-height: 28px;
--btn-height: 30px;
// Checkbox
--checkbox-right-margin: var(--margin-xs);

View file

@ -11,11 +11,16 @@
</style>
</head>
<body>
<div class="print-format-gutter">
<div class="print-format">
{{ body }}
</div>
<div class="hidden-print w-100 bg-secondary text-center" style="padding: 10px">
{{ _("Your key has been expired!") }}
</div>
{% if hideewe %}
<div class="print-format-gutter">
<div class="print-format">
{{ body }}
</div>
</div>
{% endif %}
<script>
document.addEventListener('DOMContentLoaded', () => {
const page_div = document.querySelector('.page-break');

View file

@ -37,11 +37,16 @@ def get_context(context):
make_access_log(doctype=frappe.form_dict.doctype, document=frappe.form_dict.name, file_type='PDF', method='Print')
return {
"body": get_rendered_template(doc, print_format = print_format,
try:
body = get_rendered_template(doc, print_format = print_format,
meta=meta, trigger_print = frappe.form_dict.trigger_print,
no_letterhead=frappe.form_dict.no_letterhead, letterhead=letterhead,
settings=settings),
settings=settings)
except frappe.exceptions.LinkExpiredError:
body = "Link Expired"
return {
"body": body,
"css": get_print_style(frappe.form_dict.style, print_format),
"comment": frappe.session.user,
"title": doc.get(meta.title_field) if meta.title_field else doc.name,