REMOVE LDAP

This commit is contained in:
beabigegg
2025-09-25 08:44:44 +08:00
commit 333a640a3b
53 changed files with 4231 additions and 0 deletions

69
models.py Normal file
View File

@@ -0,0 +1,69 @@
from flask_sqlalchemy import SQLAlchemy
from flask_login import UserMixin
from datetime import datetime
from utils.timezone import taiwan_now
from werkzeug.security import generate_password_hash, check_password_hash
db = SQLAlchemy()
class User(db.Model, UserMixin):
# 修改 table name
__tablename__ = 'tst_user'
id = db.Column(db.Integer, primary_key=True)
username = db.Column(db.String(120), unique=True, nullable=False)
password_hash = db.Column(db.String(255), nullable=False)
name = db.Column(db.String(100), nullable=False)
role = db.Column(db.Enum('viewer', 'editor', 'admin'), nullable=False, default='viewer')
last_login = db.Column(db.DateTime)
def set_password(self, password: str) -> None:
self.password_hash = generate_password_hash(password)
def check_password(self, password: str) -> bool:
return check_password_hash(self.password_hash, password)
class TempSpec(db.Model):
# 新增並設定 table name
__tablename__ = 'tst_temp_spec'
id = db.Column(db.Integer, primary_key=True)
spec_code = db.Column(db.String(20), nullable=False)
applicant = db.Column(db.String(50))
title = db.Column(db.String(100))
content = db.Column(db.Text)
start_date = db.Column(db.Date)
end_date = db.Column(db.Date)
status = db.Column(db.Enum('pending_approval', 'active', 'expired', 'terminated'), nullable=False, default='pending_approval')
created_at = db.Column(db.DateTime)
extension_count = db.Column(db.Integer, default=0)
termination_reason = db.Column(db.Text, nullable=True)
notification_emails = db.Column(db.Text, nullable=True) # 儲存通知郵件清單,以分號分隔
# 關聯到 Upload 和 SpecHistory並設定級聯刪除
uploads = db.relationship('Upload', back_populates='spec', cascade='all, delete-orphan')
history = db.relationship('SpecHistory', back_populates='spec', cascade='all, delete-orphan')
class Upload(db.Model):
# 新增並設定 table name
__tablename__ = 'tst_upload'
id = db.Column(db.Integer, primary_key=True)
# 注意:這裡的 ForeignKey 也要更新為新的 table name
temp_spec_id = db.Column(db.Integer, db.ForeignKey('tst_temp_spec.id', ondelete='CASCADE'), nullable=False)
filename = db.Column(db.String(200))
upload_time = db.Column(db.DateTime)
spec = db.relationship('TempSpec', back_populates='uploads')
class SpecHistory(db.Model):
# 修改 table name
__tablename__ = 'tst_spec_history'
id = db.Column(db.Integer, primary_key=True)
# 注意:這裡的 ForeignKey 也要更新為新的 table name
spec_id = db.Column(db.Integer, db.ForeignKey('tst_temp_spec.id', ondelete='CASCADE'), nullable=False)
user_id = db.Column(db.Integer, db.ForeignKey('tst_user.id', ondelete='SET NULL'), nullable=True)
action = db.Column(db.String(50), nullable=False)
details = db.Column(db.Text, nullable=True)
timestamp = db.Column(db.DateTime, default=taiwan_now)
# 建立與 User 和 TempSpec 的關聯,方便查詢
user = db.relationship('User')
spec = db.relationship('TempSpec', back_populates='history')