Skip to content

Commit

Permalink
Merge pull request #20 from seatable/DepartmentsV2
Browse files Browse the repository at this point in the history
DepartmentsV2
  • Loading branch information
freeplant authored Sep 7, 2023
2 parents 714c6ec + 51173b3 commit 167fd92
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
2 changes: 1 addition & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ RUN rm -f /usr/bin/python && \
ln -s /usr/local/bin/pip3.6 /usr/bin/pip && \
ln -s /usr/local/bin/pip3.6 /usr/bin/pip3

RUN pip3 install uvicorn==0.16.0 pillow sqlalchemy==1.4.6 pymysql future requests redis django==3.2.* \
RUN pip3 install uvicorn==0.16.0 pillow==8.4.0 sqlalchemy==1.4.6 pymysql==1.0.2 future==0.18.2 requests==2.27.1 redis==4.2.2 django==3.2.* \
-i https://mirrors.aliyun.com/pypi/simple && rm -r /root/.cache/pip


Expand Down
26 changes: 26 additions & 0 deletions seatable_thumbnail/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,29 @@ class DTableCollectionTables(Base):
config = Column(Text, nullable=True)
token = Column(String(36), unique=True)
created_at = Column(DateTime, nullable=True)


class DepartmentsV2(Base):
__tablename__ = 'departments_v2'
id = Column(Integer, primary_key=True)
name = Column(String(255))
created_at = Column(DateTime)
parent_id = Column(Integer, index=True)
org_id = Column(Integer)
id_in_org = Column(Integer)


class DepartmentMembersV2(Base):
__tablename__ = 'department_members_v2'
id = Column(Integer, primary_key=True)
department_id = Column(Integer, ForeignKey('departments_v2.id'))
username = Column(String(255), index=True)
is_staff = Column(Boolean)
created_at = Column(DateTime)


class DepartmentV2Groups(Base):
__tablename__ = 'department_v2_groups'
id = Column(Integer, primary_key=True)
department_id = Column(Integer, ForeignKey('departments_v2.id'))
group_id = Column(Integer, index=True)
17 changes: 16 additions & 1 deletion seatable_thumbnail/permissions.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from seaserv import ccnet_api
from seatable_thumbnail.models import DTables, DTableShare, \
DTableGroupShare, DTableViewUserShare, DTableViewGroupShare, \
DTableExternalLinks, DTableCollectionTables
DTableExternalLinks, DTableCollectionTables, DepartmentMembersV2, DepartmentV2Groups
from seatable_thumbnail.constants import PERMISSION_READ, PERMISSION_READ_WRITE
from seatable_thumbnail import redis_client

Expand Down Expand Up @@ -88,10 +88,25 @@ def has_collection_table_permission(self):

return self.collection_table['dtable_uuid'] == self.dtable_uuid

def is_department_v2_group_member(self, group_id, email):
group = self.db_session.query(
DepartmentV2Groups).filter_by(group_id=group_id).first()
if not group:
return False
department_id = group.department_id
member = self.db_session.query(
DepartmentMembersV2).filter_by(department_id=department_id, username=email).first()
if member:
return True
return False

def is_group_member(self, group_id, email, in_structure=None):

group_id = int(group_id)

if self.is_department_v2_group_member(group_id, email):
return True

if in_structure in (True, False):
return ccnet_api.is_group_user(group_id, email, in_structure)

Expand Down

0 comments on commit 167fd92

Please sign in to comment.