[Minor] Allow user to change files private to public and vice-versa (#2079)

* [Minor] Allow user to change files private to public and vice-versa

* [Fix] Using db_get instead of get_doc
This commit is contained in:
Shreyas Patil 2016-09-26 18:15:26 +05:30 committed by Rushabh Mehta
parent 1ee9ee886e
commit 0770b2a224
2 changed files with 49 additions and 5 deletions

View file

@ -3,15 +3,18 @@
"allow_import": 1,
"allow_rename": 0,
"autoname": "",
"beta": 0,
"creation": "2012-12-12 11:19:22",
"custom": 0,
"docstatus": 0,
"doctype": "DocType",
"editable_grid": 0,
"fields": [
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "file_name",
"fieldtype": "Data",
"hidden": 0,
@ -38,6 +41,7 @@
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"depends_on": "eval:!doc.is_folder",
"fieldname": "is_private",
"fieldtype": "Check",
@ -53,17 +57,18 @@
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 1,
"read_only": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 1,
"set_only_once": 0,
"unique": 0
},
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "preview",
"fieldtype": "Section Break",
"hidden": 0,
@ -89,6 +94,7 @@
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "preview_html",
"fieldtype": "HTML",
"hidden": 0,
@ -114,6 +120,7 @@
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "section_break_5",
"fieldtype": "Section Break",
"hidden": 0,
@ -138,6 +145,7 @@
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"depends_on": "",
"fieldname": "is_home_folder",
"fieldtype": "Check",
@ -164,6 +172,7 @@
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "is_attachments_folder",
"fieldtype": "Check",
"hidden": 1,
@ -189,6 +198,7 @@
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "file_size",
"fieldtype": "Int",
"hidden": 0,
@ -213,6 +223,7 @@
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "column_break_5",
"fieldtype": "Column Break",
"hidden": 0,
@ -237,6 +248,7 @@
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"depends_on": "eval:!doc.is_folder",
"fieldname": "file_url",
"fieldtype": "Code",
@ -262,6 +274,7 @@
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "thumbnail_url",
"fieldtype": "Small Text",
"hidden": 0,
@ -287,6 +300,7 @@
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "folder",
"fieldtype": "Link",
"hidden": 1,
@ -313,6 +327,7 @@
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "is_folder",
"fieldtype": "Check",
"hidden": 0,
@ -338,6 +353,7 @@
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"depends_on": "eval:!doc.is_folder",
"fieldname": "section_break_8",
"fieldtype": "Section Break",
@ -363,6 +379,7 @@
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "attached_to_doctype",
"fieldtype": "Link",
"hidden": 0,
@ -388,6 +405,7 @@
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "column_break_10",
"fieldtype": "Column Break",
"hidden": 0,
@ -412,6 +430,7 @@
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "attached_to_name",
"fieldtype": "Data",
"hidden": 0,
@ -436,6 +455,7 @@
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "content_hash",
"fieldtype": "Data",
"hidden": 1,
@ -460,6 +480,7 @@
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "lft",
"fieldtype": "Int",
"hidden": 1,
@ -485,6 +506,7 @@
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "rgt",
"fieldtype": "Int",
"hidden": 1,
@ -510,6 +532,7 @@
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "old_parent",
"fieldtype": "Data",
"hidden": 1,
@ -536,6 +559,7 @@
"hide_toolbar": 0,
"icon": "icon-file",
"idx": 1,
"image_view": 0,
"in_create": 0,
"in_dialog": 0,
"is_submittable": 0,
@ -543,7 +567,7 @@
"istable": 0,
"max_attachments": 0,
"menu_index": 0,
"modified": "2016-02-22 09:23:59.892258",
"modified": "2016-09-21 12:23:34.017457",
"modified_by": "Administrator",
"module": "Core",
"name": "File",
@ -590,7 +614,10 @@
"write": 1
}
],
"quick_entry": 0,
"read_only": 0,
"read_only_onload": 0,
"title_field": "file_name"
"sort_order": "ASC",
"title_field": "file_name",
"track_seen": 0
}

View file

@ -12,6 +12,7 @@ import frappe
import json
import urllib
import os
import shutil
import requests
import requests.exceptions
import StringIO
@ -72,6 +73,23 @@ class File(NestedSet):
self.set_folder_size()
if frappe.db.exists('File', {'name': self.name, 'is_folder': 0}):
if not self.is_folder and (self.is_private != self.db_get('is_private')):
private_files = frappe.get_site_path('private', 'files')
public_files = frappe.get_site_path('public', 'files')
if not self.is_private:
shutil.move(os.path.join(private_files, self.file_name),
os.path.join(public_files, self.file_name))
self.file_url = "/files/{0}".format(self.file_name)
else:
shutil.move(os.path.join(public_files, self.file_name),
os.path.join(private_files, self.file_name))
self.file_url = "/private/files/{0}".format(self.file_name)
def set_folder_size(self):
"""Set folder size if folder"""
if self.is_folder and not self.is_new():
@ -350,4 +368,3 @@ def check_file_permission(file_url):
return True
raise frappe.PermissionError