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

Collection table permission #6

Merged
merged 2 commits into from
Mar 12, 2021
Merged
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
2 changes: 0 additions & 2 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ COPY src/seatable-thumbnail-server /opt/seatable-thumbnail/seatable-thumbnail-se

RUN ln -sf /opt/seatable-thumbnail/seafile/lib/libsearpc.so.1.0.2 /opt/seatable-thumbnail/seafile/lib/libsearpc.so.1
RUN ln -sf /opt/seatable-thumbnail/seafile/lib/libsearpc.so.1.0.2 /opt/seatable-thumbnail/seafile/lib/libsearpc.so
RUN ln -sf /opt/seatable-thumbnail/seafile/lib/libccnet.so.0.0.0 /opt/seatable-thumbnail/seafile/lib/libccnet.so.0
RUN ln -sf /opt/seatable-thumbnail/seafile/lib/libccnet.so.0.0.0 /opt/seatable-thumbnail/seafile/lib/libccnet.so


# scripts
Expand Down
18 changes: 17 additions & 1 deletion docker/scripts/enterpoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ fi

# letsencrypt renew cert 86400*30
if [[ -f /shared/ssl/renew_cert ]]; then
ln -sf /shared/ssl/renew_cert /var/spool/cron/crontabs/root
env > /opt/dockerenv
sed -i '1,3d' /opt/dockerenv

cp /shared/ssl/renew_cert /var/spool/cron/crontabs/root
chmod 600 /var/spool/cron/crontabs/root

openssl x509 -checkend 2592000 -noout -in /opt/ssl/$SEATABLE_THUMBNAIL_SERVER_HOSTNAME.crt
if [[ $? != "0" ]]; then
Expand All @@ -48,6 +52,18 @@ if [[ -f /shared/ssl/renew_cert ]]; then
fi


# autorun
echo
echo "Starting SeaTable Thumbnail"
echo

/scripts/seatable-thumbnail.sh start

wait

sleep 1


#
log "This is a idle script (infinite loop) to keep container running."

Expand Down
21 changes: 16 additions & 5 deletions docker/scripts/init_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,19 +140,30 @@ def init_https():
# crontab letsencrypt renew cert
with open('/opt/ssl/renew_cert', 'w') as f:
f.write('0 1 1 * * /scripts/renew_cert.sh 2>> /opt/ssl/letsencrypt.log\n')
os.system('ln -s /opt/ssl/renew_cert /var/spool/cron/crontabs/root')
os.system('cp /opt/ssl/renew_cert /var/spool/cron/crontabs/root')
os.system('chmod 600 /var/spool/cron/crontabs/root')
os.system('env > /opt/dockerenv')
os.system("sed -i '1,3d' /opt/dockerenv")

#
nginx_https_config = """
log_format seatableformat '\$http_x_forwarded_for \$remote_addr [\$time_local] "\$request" \$status \$body_bytes_sent "\$http_referer" "\$http_user_agent" \$upstream_response_time';

server {
if ($host = %s) {
return 301 https://$host$request_uri;
}
listen 80;
server_name %s;
return 404;

# for letsencrypt
location /.well-known/acme-challenge/ {
alias /var/www/challenges/;
try_files $uri =404;
}

location / {
if ($host = %s) {
return 301 https://$host$request_uri;
}
}
}

server {
Expand Down
11 changes: 0 additions & 11 deletions docker/scripts/monitor.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,6 @@ function check_process() {
}

# monitor
function monitor_ccnet() {
process_name="ccnet-server"
check_num=$(check_process $process_name)
if [ $check_num -eq 0 ]; then
log "Start $process_name"
ccnet-server -F /opt/seatable-thumbnail/conf -c /opt/seatable-thumbnail/ccnet -f /opt/seatable-thumbnail/logs/ccnet.log -d -L /opt/seatable-thumbnail -P /opt/seatable-thumbnail/pids/ccnet.pid - &
sleep 0.2
fi
}

function monitor_seafile() {
process_name="seaf-server"
check_num=$(check_process $process_name)
Expand Down Expand Up @@ -66,7 +56,6 @@ function monitor_seatable_thumbnail() {
log "Start Monitor"

while [ 1 ]; do
monitor_ccnet
monitor_seafile
monitor_seatable_thumbnail

Expand Down
4 changes: 0 additions & 4 deletions docker/scripts/seatable-thumbnail.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/bin/bash

function stop_server() {
pkill -9 -f ccnet-server
pkill -9 -f seaf-server
pkill -9 -f uvicorn
pkill -9 -f multiprocessing
Expand Down Expand Up @@ -43,9 +42,6 @@ function start_server() {

set_env

ccnet-server -F /opt/seatable-thumbnail/conf -c /opt/seatable-thumbnail/ccnet -f /opt/seatable-thumbnail/logs/ccnet.log -d -L /opt/seatable-thumbnail -P /opt/seatable-thumbnail/pids/ccnet.pid - &
sleep 0.2

seaf-server -F /opt/seatable-thumbnail/conf -c /opt/seatable-thumbnail/ccnet -d /opt/seatable-thumbnail/seafile-data -l /opt/seatable-thumbnail/logs/seafile.log -L /opt/seatable-thumbnail -P /opt/seatable-thumbnail/pids/seafile.pid - &
sleep 0.2

Expand Down
11 changes: 11 additions & 0 deletions seatable_thumbnail/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,14 @@ class DTableSystemPlugins(Base):
added_time = Column(DateTime)
info = Column(Text)
name = Column(String(255), index=True)


class DTableCollectionTables(Base):
__tablename__ = 'dtable_collection_tables'
id = Column(Integer, primary_key=True)
username = Column(String(255), index=True)
workspace_id = Column(Integer, index=True)
dtable_uuid = Column(String(36), index=True)
config = Column(Text, nullable=True)
token = Column(String(36), unique=True)
created_at = Column(DateTime, nullable=True)
16 changes: 15 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
DTableExternalLinks, DTableCollectionTables
from seatable_thumbnail.constants import PERMISSION_READ, PERMISSION_READ_WRITE


Expand All @@ -23,6 +23,8 @@ def has_dtable_asset_read_permission(self):

if self.can_access_image_through_external_link():
return True
if self.has_collection_table_permission():
return True
if 'r' in self.check_dtable_permission():
return True
if 'r' in self.get_view_share_permission():
Expand Down Expand Up @@ -136,3 +138,15 @@ def is_group_member(self, group_id, email, in_structure=None):
return ccnet_api.is_group_user(group_id, email, in_structure=False)
else:
return ccnet_api.is_group_user(group_id, email)

def has_collection_table_permission(self):
if not hasattr(self, 'collection_table'):
return False

token = self.collection_table['token']
obj = self.db_session.query(
DTableCollectionTables).filter_by(token=token).first()
if not obj:
return False

return self.collection_table['dtable_uuid'] == self.dtable_uuid
3 changes: 2 additions & 1 deletion seatable_thumbnail/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,11 @@ def session_check(self):

username = self.session_data.get('_auth_user_name')
external_link = self.session_data.get('external_link')
collection_table = self.session_data.get('collection_table')
if username:
self.session_data['username'] = username

if not username and not external_link:
if not username and not external_link and not collection_table:
raise AssertionError(400, 'django session invalid.')

def get_enable_file_type(self):
Expand Down