Skip to content

Commit

Permalink
chore: format
Browse files Browse the repository at this point in the history
  • Loading branch information
safwansamsudeen committed Jan 10, 2025
1 parent 39437d2 commit a287600
Show file tree
Hide file tree
Showing 15 changed files with 44 additions and 32 deletions.
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")
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
6 changes: 4 additions & 2 deletions drive/utils/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,9 @@ def invite_users(emails, role="Drive User"):

@frappe.whitelist(allow_guest=True)
@rate_limit(key="reference_name", limit=10, seconds=60 * 60)
def add_comment(reference_name: str, content: str, comment_email: str, comment_by: str) -> "Comment":
def add_comment(
reference_name: str, content: str, comment_email: str, comment_by: str
) -> "Comment":
"""Allow logged user with permission to read document to add a comment"""
entity = frappe.get_doc("Drive Entity", reference_name)
if not entity.allow_comments:
Expand All @@ -263,4 +265,4 @@ def add_comment(reference_name: str, content: str, comment_email: str, comment_b
}
)
comment.insert(ignore_permissions=True)
return comment
return comment

0 comments on commit a287600

Please sign in to comment.