Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update: frappe-ui #295

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions drive/api/activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def create_new_activity_log(
doc.action_type = activity_type
doc.message = activity_message
doc.owner = frappe.session.user
doc.meta_value = field_meta_value
doc.meta_value = field_meta_value
if document_field:
doc.old_value = field_old_value
doc.new_value = field_new_value
Expand Down Expand Up @@ -56,7 +56,7 @@ def get_entity_activity_log(entity_name):

result = query.run(as_dict=True)
for i in result:
if i.action_type.startswith("share") and i.document_field == "User":
if i.action_type.startswith("share") and i.document_field == "User":
i.share_user_fullname, i.share_user_image = frappe.get_value(
"User", i.new_value, ["full_name", "user_image"]
)
Expand Down
3 changes: 2 additions & 1 deletion drive/api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def oauth_providers():
)
return out


@frappe.whitelist(allow_guest=True)
def get_server_timezone():
return frappe.db.get_single_value('System Settings', 'time_zone')
return frappe.db.get_single_value("System Settings", "time_zone")
62 changes: 31 additions & 31 deletions drive/api/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ def if_folder_exists(folder_name, parent):


@frappe.whitelist()
def get_home_folder_id(user=None):
def get_home_folder_id():
"""Returns user directory name from user's unique id"""
if not user:
user = frappe.session.user
if 'Administrator' in frappe.get_roles(user):
return get_user_directory(user).name
if 'Drive Guest' in frappe.get_roles(user):
frappe.throw("Access forbidden: You do not have permission to access this resource.", frappe.PermissionError)
return get_user_directory(user).name
if "Drive Guest" in frappe.get_roles(frappe.session.user):
frappe.throw(
"Access forbidden: You do not have permission to access this resource.",
frappe.PermissionError,
)

return hashlib.md5(frappe.session.user.encode("utf-8")).hexdigest()


@frappe.whitelist()
Expand Down Expand Up @@ -94,6 +94,7 @@ def create_document_entity(title, content, parent=None):
drive_entity.save()
return drive_entity


@frappe.whitelist()
def create_whiteboard_entity(title, content, parent=None):
try:
Expand Down Expand Up @@ -365,6 +366,7 @@ def save_doc(entity_name, doc_name, raw_content, content, file_size, mentions, s
)
return


@frappe.whitelist()
def save_whiteboard(entity_name, doc_name, content):
if not frappe.has_permission(
Expand Down Expand Up @@ -1032,42 +1034,41 @@ def list_favourites(order_by="modified", limit=100, offset=0):


@frappe.whitelist()
def add_or_remove_favourites(entity_names=None, clear_all=False):
def set_favourite(entities=None, clear_all=False):
"""
Favouite or unfavourite DriveEntities for specified user

:param entity_names: List of document-names
:param entities: List[dict] of document names and whether favorite
:type entity_names: list[str]
:raises ValueError: If decoded entity_names is not a list
"""

if clear_all:
frappe.db.delete("Drive Favourite", {"user": frappe.session.user})
return
return frappe.db.delete("Drive Favourite", {"user": frappe.session.user})

if isinstance(entity_names, str):
entity_names = json.loads(entity_names)
if not isinstance(entity_names, list):
frappe.throw(f"Expected list but got {type(entity_names)}", ValueError)
for entity in entity_names:
if not isinstance(entities, list):
frappe.throw(f"Expected list but got {type(entities)}", ValueError)

for entity in entities:
existing_doc = frappe.db.exists(
{
"doctype": "Drive Favourite",
"entity": entity,
"entity": entity["name"],
"user": frappe.session.user,
}
)
if existing_doc:
if not entity.get("is_favourite"):
entity["is_favourite"] = not existing_doc

if not entity["is_favourite"] and existing_doc:
frappe.delete_doc("Drive Favourite", existing_doc)
else:
doc = frappe.get_doc(
elif entity["is_favourite"] and not existing_doc:
frappe.get_doc(
{
"doctype": "Drive Favourite",
"entity": entity,
"entity": entity["name"],
"user": frappe.session.user,
}
)
doc.insert()
).insert()


# def toggle_is_active(doc):
Expand Down Expand Up @@ -1225,7 +1226,7 @@ def list_recents(order_by="last_interaction", limit=100, offset=0):


@frappe.whitelist()
def remove_recents(entity_names=None, clear_all=False):
def remove_recents(entity_names=[], clear_all=False):
"""
Clear recent DriveEntities for specified user

Expand All @@ -1235,12 +1236,11 @@ def remove_recents(entity_names=None, clear_all=False):
"""

if clear_all:
frappe.db.delete("Drive Entity Log", {"user": frappe.session.user})
return
if isinstance(entity_names, str):
entity_names = json.loads(entity_names)
return frappe.db.delete("Drive Entity Log", {"user": frappe.session.user})

if not isinstance(entity_names, list):
frappe.throw(f"Expected list but got {type(entity_names)}", ValueError)
print("HO", entity_names)
for entity in entity_names:
existing_doc = frappe.db.exists(
{
Expand Down Expand Up @@ -1388,7 +1388,7 @@ def search(query, home_dir):
)
return result
except Exception as e:
frappe.log_error(frappe.get_traceback(), 'Frappe Drive Search Error')
frappe.log_error(frappe.get_traceback(), "Frappe Drive Search Error")
return {"error": str(e)}


Expand Down
7 changes: 3 additions & 4 deletions drive/api/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def files(
folders_first = bool(folders_first)
general_access = eval_general_access(entity_name)

if mime_type_list and not entity_name:
if not entity_name:
entity_name = get_user_directory(frappe.session.user).name

if recents_only:
Expand All @@ -112,9 +112,8 @@ def files(
.limit(limit)
.select(*selectedFields)
)
if entity_name:
query = query.where(DriveEntity.parent_drive_entity == entity_name)
query = query.where(

query = query.where(DriveEntity.parent_drive_entity == entity_name).where(
(DriveEntity.is_active == is_active)
& (
(UserGroupMember.user == frappe.session.user)
Expand Down
14 changes: 7 additions & 7 deletions drive/api/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def get_notifications(only_unread):
"""
Get notifications for current user

:param only_unread: only get notifications where read is False
:param only_unread: only get notifications where read is False
"""
User = frappe.qb.DocType("User")
Notification = frappe.qb.DocType("Drive Notification")
Expand Down Expand Up @@ -54,9 +54,9 @@ def get_unread_count():
@frappe.whitelist()
def mark_as_read(name=None, all=False):
"""
Mark notification for current user as read
Mark notification for current user as read

:param name: ID of notification record
:param name: ID of notification record
:param all: Will mark all unread notifications as read
"""
if all:
Expand All @@ -70,7 +70,7 @@ def mark_as_read(name=None, all=False):

def notify_mentions(entity_name, document_name):
"""
Create a mention notification for each user mentioned
Create a mention notification for each user mentioned
:param entity_name: ID of entity
:param document_name: ID of document containing mentions
"""
Expand Down Expand Up @@ -101,7 +101,7 @@ def notify_mentions(entity_name, document_name):

def notify_share(entity_name, docshare_name):
"""
Create a share notification for each user
Create a share notification for each user
:param entity_name: ID of entity
:param document_name: ID of docshare containing share info
"""
Expand Down Expand Up @@ -149,9 +149,9 @@ def create_notification(from_user, to_user, type, entity, message=None):
"""
Create a notification
:param from_user: notification owner user email
:param to_user: notification receiver user email
:param to_user: notification receiver user email
:param type: subject of notification
:param entity: drive_entity name
:param entity: drive_entity name
:param message: notification message
"""
from drive.api.permissions import get_user_access
Expand Down
25 changes: 15 additions & 10 deletions drive/api/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ def get_entity_with_permissions(entity_name):
frappe.throw("Not permitted", frappe.PermissionError)

entity = get_entity(entity_name, fields)

validate_parent_folder(entity)
if not entity.is_active:
frappe.throw("Specified file has been trashed by the owner")
Expand All @@ -320,26 +320,29 @@ def get_entity_with_permissions(entity_name):

if user_access.get("read") == 0:
frappe.throw("Unauthorized", frappe.PermissionError)

owner_info = frappe.db.get_value("User", entity.owner, ["user_image", "full_name"], as_dict=True)

owner_info = frappe.db.get_value(
"User", entity.owner, ["user_image", "full_name"], as_dict=True
)
breadcrumbs = {"breadcrumbs": get_valid_breadcrumbs(entity, user_access)}
favourite = frappe.db.get_value(
"Drive Favourite",
{
"entity": entity_name,
"user": frappe.session.user,
"user": frappe.session.user,
},
["entity as is_favourite"]
["entity as is_favourite"],
)
mark_as_viewed(entity)
return_obj = entity | user_access | owner_info | breadcrumbs | {"is_favourite": favourite}
return_obj = entity | user_access | owner_info | breadcrumbs | {"is_favourite": favourite}

if entity.document:
entity_doc_content = get_doc_content(entity.document)
return_obj = return_obj | entity_doc_content

return return_obj



def validate_parent_folder(entity):
"""
Validate if the parent folder exists and is active.
Expand All @@ -348,7 +351,8 @@ def validate_parent_folder(entity):
for ancestor_name in ancestors:
if frappe.db.exists("Drive Entity", {"name": ancestor_name, "is_active": 0}):
raise IsADirectoryError(f"Parent Folder {ancestor_name} has been deleted")



def get_valid_breadcrumbs(entity, user_access):
"""
Determine user access and generate upward path (breadcrumbs).
Expand All @@ -361,10 +365,11 @@ def get_valid_breadcrumbs(entity, user_access):
x = file_path[: -len(permission_path)]
for i in reversed(x):
if i.owner == frappe.session.user:
permission_path.insert(0, i)
permission_path.insert(0, i)
file_path = permission_path
return file_path


@frappe.whitelist()
def get_general_access(entity_name):
"""
Expand Down
1 change: 0 additions & 1 deletion drive/api/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ def get_storage_allowed():
return min(usr_rem, total_rem)
else:
return total_rem



def total_disk_storage_used():
Expand Down
3 changes: 1 addition & 2 deletions drive/drive/doctype/drive_docshare/drive_docshare.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,10 @@ def validate_general_access(self):
self.user_doctype = None
elif self.user_name or self.user_doctype:
self.everyone = None
self.public= None
self.public = None
if not any([self.everyone, self.public, self.user_name, self.user_doctype]):
raise ValueError("Invalid Share")


def after_insert(self):
doc = self.get_doc()
owner = get_fullname(self.owner)
Expand Down
1 change: 0 additions & 1 deletion drive/drive/doctype/drive_entity/drive_entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ def get_children(self):
for name in child_names:
yield frappe.get_doc(self.doctype, name)


def move(self, new_parent=None):
"""
Move file or folder to the new parent folder
Expand Down
9 changes: 7 additions & 2 deletions drive/drive/doctype/drive_entity/patches/init_search_idx.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import frappe


def execute():
index_check = frappe.db.sql("""SHOW INDEX FROM `tabDrive Entity` WHERE Key_name = 'drive_entity_title_fts_idx'""")
index_check = frappe.db.sql(
"""SHOW INDEX FROM `tabDrive Entity` WHERE Key_name = 'drive_entity_title_fts_idx'"""
)

if not index_check:
frappe.db.sql("""ALTER TABLE `tabDrive Entity` ADD FULLTEXT INDEX drive_entity_title_fts_idx (title)""")
frappe.db.sql(
"""ALTER TABLE `tabDrive Entity` ADD FULLTEXT INDEX drive_entity_title_fts_idx (title)"""
)
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@


class DriveEntityActivityLog(Document):
pass
pass
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@


class TestDriveEntityActivityLog(FrappeTestCase):
pass
pass
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@


class DriveUserStorageQuota(Document):
pass
pass
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@


class TestDriveUserStorageQuota(FrappeTestCase):
pass
pass
1 change: 1 addition & 0 deletions drive/install.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import frappe


def after_install():
index_check = frappe.db.sql(
"""SHOW INDEX FROM `tabDrive Entity` WHERE Key_name = 'drive_entity_title_fts_idx'"""
Expand Down
1 change: 1 addition & 0 deletions drive/utils/user_group.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import frappe


@frappe.whitelist()
def get_name_of_all_user_groups():
try:
Expand Down
Loading