Skip to content

Commit

Permalink
fix db_session
Browse files Browse the repository at this point in the history
  • Loading branch information
SkywalkerSpace committed Sep 19, 2020
1 parent fdeb625 commit 9598191
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
1 change: 0 additions & 1 deletion seatable_thumbnail/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,3 @@
engine = create_engine(db_url, **db_kwargs)
Base = declarative_base()
DBSession = sessionmaker(bind=engine)
db_session = DBSession()
13 changes: 7 additions & 6 deletions seatable_thumbnail/permissions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from seaserv import ccnet_api
from seatable_thumbnail import db_session
from seatable_thumbnail import DBSession
from seatable_thumbnail.models import DTables, DTableShare, \
DTableGroupShare, DTableViewUserShare, DTableViewGroupShare, \
DTableExternalLinks
Expand All @@ -9,7 +9,8 @@
class ThumbnailPermission(object):
def __init__(self, **info):
self.__dict__.update(info)
self.dtable = db_session.query(
self.db_session = DBSession()
self.dtable = self.db_session.query(
DTables).filter_by(uuid=self.dtable_uuid).first()

def check(self):
Expand Down Expand Up @@ -54,7 +55,7 @@ def check_dtable_permission(self):
return PERMISSION_READ_WRITE

if dtable: # check user's all permissions from `share`, `group-share` and checkout higher one
dtable_share = db_session.query(
dtable_share = self.db_session.query(
DTableShare).filter_by(dtable_id=dtable.id, to_user=username).first()
if dtable_share and dtable_share.permission == PERMISSION_READ_WRITE:
return dtable_share.permission
Expand All @@ -65,7 +66,7 @@ def check_dtable_permission(self):
else:
groups = ccnet_api.get_groups(username, return_ancestors=True)
group_ids = [group.id for group in groups]
group_permissions = db_session.query(
group_permissions = self.db_session.query(
DTableGroupShare.permission).filter(DTableGroupShare.dtable_id == dtable.id, DTableGroupShare.group_id.in_(group_ids)).all()

for group_permission in group_permissions:
Expand All @@ -91,7 +92,7 @@ def get_user_view_share_permission(self):
username = self.username
dtable = self.dtable

view_share = db_session.query(
view_share = self.db_session.query(
DTableViewUserShare).filter_by(dtable_id=dtable.id, to_user=username).order_by(DTableViewUserShare.permission.desc()).first()
if not view_share:
return ''
Expand All @@ -103,7 +104,7 @@ def get_group_view_share_permission(self):
username = self.username
dtable = self.dtable

view_shares = db_session.query(
view_shares = self.db_session.query(
DTableViewGroupShare).filter_by(dtable_id=dtable.id).order_by(DTableViewGroupShare.permission.desc()).all()

target_view_share = None
Expand Down
8 changes: 4 additions & 4 deletions seatable_thumbnail/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from email.utils import formatdate

from seaserv import seafile_api
from seatable_thumbnail import db_session
from seatable_thumbnail import DBSession
import seatable_thumbnail.settings as settings
from seatable_thumbnail.constants import FILE_EXT_TYPE_MAP, \
IMAGE, PSD, VIDEO, XMIND
Expand All @@ -14,13 +14,13 @@

class ThumbnailSerializer(object):
def __init__(self, request):
self.db_session = DBSession()
self.request = request
self.check()
self.gen_thumbnail_info()

def check(self):
self.params_check()
db_session.commit() # clear db session cache
self.session_check()
self.resource_check()
self.gen_thumbnail_info()
Expand All @@ -40,7 +40,7 @@ def parse_django_session(self, session_data):

def session_check(self):
session_key = self.request.cookies[settings.SESSION_KEY]
django_session = db_session.query(
django_session = self.db_session.query(
DjangoSession).filter_by(session_key=session_key).first()
self.session_data = self.parse_django_session(django_session.session_data)

Expand Down Expand Up @@ -102,7 +102,7 @@ def resource_check(self):
file_path = self.params['file_path']
size = self.params['size']

workspace = db_session.query(
workspace = self.db_session.query(
Workspaces).filter_by(id=workspace_id).first()
repo_id = workspace.repo_id
workspace_owner = workspace.owner
Expand Down

0 comments on commit 9598191

Please sign in to comment.