2022-05-04 23:09:46 +00:00
|
|
|
import time
|
|
|
|
|
2023-07-07 23:07:11 +00:00
|
|
|
from flask import g
|
2022-11-15 09:19:08 +00:00
|
|
|
from sqlalchemy import Column, ForeignKey
|
|
|
|
from sqlalchemy.orm import relationship, scoped_session
|
|
|
|
from sqlalchemy.sql.sqltypes import *
|
|
|
|
|
|
|
|
from files.classes import Base
|
2023-03-12 13:03:58 +00:00
|
|
|
from files.helpers.config.const import *
|
2022-11-15 09:19:08 +00:00
|
|
|
from files.helpers.lazy import lazy
|
2022-05-04 23:09:46 +00:00
|
|
|
|
2022-11-15 09:19:08 +00:00
|
|
|
from .comment import Comment
|
2023-06-07 23:26:32 +00:00
|
|
|
from .post import Post
|
2022-11-15 09:19:08 +00:00
|
|
|
|
|
|
|
class OauthApp(Base):
|
2022-05-04 23:09:46 +00:00
|
|
|
__tablename__ = "oauth_apps"
|
|
|
|
|
|
|
|
id = Column(Integer, primary_key=True)
|
|
|
|
client_id = Column(String)
|
|
|
|
app_name = Column(String)
|
|
|
|
redirect_uri = Column(String)
|
|
|
|
description = Column(String)
|
|
|
|
author_id = Column(Integer, ForeignKey("users.id"))
|
2022-09-19 20:40:33 +00:00
|
|
|
created_utc = Column(Integer)
|
2022-05-04 23:09:46 +00:00
|
|
|
|
2022-07-18 00:46:46 +00:00
|
|
|
author = relationship("User", back_populates="apps")
|
2022-05-04 23:09:46 +00:00
|
|
|
|
2022-09-19 20:40:33 +00:00
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
if "created_utc" not in kwargs: kwargs["created_utc"] = int(time.time())
|
|
|
|
super().__init__(*args, **kwargs)
|
|
|
|
|
2022-07-02 06:48:04 +00:00
|
|
|
def __repr__(self):
|
2022-11-29 21:02:38 +00:00
|
|
|
return f"<{self.__class__.__name__}(id={self.id})>"
|
2022-05-04 23:09:46 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
@lazy
|
2022-07-02 06:48:04 +00:00
|
|
|
def permalink(self):
|
2022-11-26 04:41:56 +00:00
|
|
|
return f"{SITE_FULL}/admin/app/{self.id}"
|
2022-05-04 23:09:46 +00:00
|
|
|
|
|
|
|
@lazy
|
2023-05-05 21:44:24 +00:00
|
|
|
def idlist(self, cls, page=1):
|
2023-07-07 23:04:21 +00:00
|
|
|
items = g.db.query(cls).options(load_only(cls.id)).filter_by(app_id=self.id)
|
2023-05-05 21:44:24 +00:00
|
|
|
total = items.count()
|
2022-05-04 23:09:46 +00:00
|
|
|
|
2023-05-05 21:44:24 +00:00
|
|
|
items = items.order_by(cls.created_utc.desc())
|
|
|
|
items = items.offset(100*(page-1)).limit(100)
|
|
|
|
items = [x.id for x in items.all()]
|
|
|
|
|
|
|
|
return items, total
|
2022-05-04 23:09:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
class ClientAuth(Base):
|
|
|
|
__tablename__ = "client_auths"
|
|
|
|
user_id = Column(Integer, ForeignKey("users.id"), primary_key=True)
|
|
|
|
oauth_client = Column(Integer, ForeignKey("oauth_apps.id"), primary_key=True)
|
|
|
|
access_token = Column(String)
|
2022-09-19 20:40:33 +00:00
|
|
|
created_utc = Column(Integer)
|
2022-09-12 10:19:35 +00:00
|
|
|
|
2022-07-02 06:48:04 +00:00
|
|
|
user = relationship("User")
|
|
|
|
application = relationship("OauthApp")
|
|
|
|
|
2022-09-19 20:40:33 +00:00
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
if "created_utc" not in kwargs: kwargs["created_utc"] = int(time.time())
|
|
|
|
super().__init__(*args, **kwargs)
|
|
|
|
|
2022-07-02 06:48:04 +00:00
|
|
|
def __repr__(self):
|
2022-09-29 05:43:29 +00:00
|
|
|
return f"<ClientAuth(user_id={self.user_id}, oauth_client={self.oauth_client})>"
|