By using this site, you agree to have cookies stored on your device, strictly for functional purposes, such as storing your session and preferences.

Dismiss

Add posts to schema

roundabout,
created on Monday, 11 December 2023, 19:25:45 (1702322745), received on Wednesday, 31 July 2024, 06:54:39 (1722408879)
Author identity: vlad <vlad.muntoiu@gmail.com>

e14841424e18b6b8aaa11087febcc168f21bc0a5

app.py

@@ -94,6 +94,9 @@ with app.app_context():

                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                    repositories = db.relationship("Repo", back_populates="owner")
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                    repoAccess = db.relationship("RepoAccess", back_populates="user")
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                            
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                commits = db.relationship("Commit", back_populates="owner")
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                posts = db.relationship("Post", back_populates="owner")
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                    def __init__(self, username, password, email=None, displayName=None):
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                        self.username = username
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                        self.passwordHashed = bcrypt.generate_password_hash(password, config.HASHING_ROUNDS).decode("utf-8")
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        

@@ -130,8 +133,11 @@ with app.app_context():

                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                    defaultBranch = db.Column(db.String(64), nullable=True, default="")
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                            
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                    commits = db.relationship("Commit", back_populates="repo")
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                posts = db.relationship("Post", back_populates="repo")
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                    repoAccess = db.relationship("RepoAccess", back_populates="repo")
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                            
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                lastPostID = db.Column(db.Integer, nullable=False, default=0)
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                    def __init__(self, owner, name, visibility):
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                        self.route = f"/{owner.username}/{name}"
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                        self.name = name
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        

@@ -147,13 +153,14 @@ with app.app_context():

                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                class Commit(db.Model):
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                    identifier = db.Column(db.String(227), unique=True, nullable=False, primary_key=True)
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                    sha = db.Column(db.String(128), nullable=False)
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                repoName = db.Column(db.String(97), db.ForeignKey("repo.route"), nullable=False)
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                repoName = db.Column(db.String(98), db.ForeignKey("repo.route"), nullable=False)
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                    ownerName = db.Column(db.String(32), db.ForeignKey("user.username"), nullable=False)
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                    ownerIdentity = db.Column(db.String(321))
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                    receiveDate = db.Column(db.DateTime, default=datetime.now)
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                    authorDate = db.Column(db.DateTime)
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                    message = db.Column(db.UnicodeText)
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                    repo = db.relationship("Repo", back_populates="commits")
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                owner = db.relationship("User", back_populates="commits")
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                            
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                    def __init__(self, sha, owner, repo, date, message, ownerIdentity):
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                        self.identifier = f"/{owner.username}/{repo.name}/{sha}"
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        

@@ -167,6 +174,33 @@ with app.app_context():

                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                        self.ownerIdentity = ownerIdentity
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                            
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                            
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            class Post(db.Model):
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                identifier = db.Column(db.String(109), unique=True, nullable=False, primary_key=True)
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                repoName = db.Column(db.String(98), db.ForeignKey("repo.route"), nullable=False)
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                ownerName = db.Column(db.String(32), db.ForeignKey("user.username"), nullable=False)
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                parentID = db.Column(db.String(109), db.ForeignKey("post.identifier"), nullable=True)
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                date = db.Column(db.DateTime, default=datetime.now)
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                subject = db.Column(db.Unicode(384))
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                message = db.Column(db.UnicodeText)
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                repo = db.relationship("Repo", back_populates="posts")
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                owner = db.relationship("User", back_populates="posts")
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                parent = db.relationship("Post", back_populates="children", remote_side="Post.identifier")
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                children = db.relationship("Post", back_populates="parent", remote_side="Post.parentID")
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                def __init__(self, owner, repo, parent, subject, message):
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                    self.identifier = f"/{owner.username}/{repo.name}/{repo.lastPostID}"
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                    self.repoName = repo.route
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                    self.repo = repo
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                    self.ownerName = owner.username
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                    self.owner = owner
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                    self.subject = subject
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                    self.message = message
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                    self.parent = parent
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                    repo.lastPostID += 1
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                            def getPermissionLevel(loggedIn, username, repository):
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                user = User.query.filter_by(username=loggedIn).first()
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                repo = Repo.query.filter_by(route=f"/{username}/{repository}").first()
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        

@@ -582,7 +616,21 @@ def repositoryForum(username, repository):

                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                                                                                  repository) is not None):
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                    flask.abort(403)
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                            
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            return flask.render_template("repo-forum.html", username=username, repository=repository)
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            serverRepoLocation = os.path.join(config.REPOS_PATH, os.path.join(username, repository))
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            app.logger.info(f"Loading {serverRepoLocation}")
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            if not os.path.exists(serverRepoLocation):
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                app.logger.error(f"Cannot load {serverRepoLocation}")
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                return flask.render_template("not-found.html"), 404
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            repo = git.Repo(serverRepoLocation)
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            repoData = Repo.query.filter_by(route=f"/{username}/{repository}").first()
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            user = User.query.filter_by(username=username).first()
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            relationships = RepoAccess.query.filter_by(repo=repoData)
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            userRelationship = RepoAccess.query.filter_by(repo=repoData, user=user).first()
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            return flask.render_template("repo-forum.html", username=username, repository=repository, repoData=repoData, relationships=relationships, repo=repo, userRelationship=userRelationship, Post=Post)
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                            
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                            
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                            @app.route("/<username>/<repository>/users/", methods=["GET", "POST"])
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                            
                                

templates/repo-forum.html

@@ -0,0 +1,12 @@

                                
                                
                                
                            
                                
                                    
                                        
                                        {% extends "repo.html" %}
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        {% block title %}
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            Forum of {{ username }}/{{ repository }}
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        {% endblock %}
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        {% block content %}
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        <x-vbox>
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            <x-frame style="--width: 896px;" class="flexible-space">
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                {% for post in Post.query.filter_by(repo=repoData) %}
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                {% endfor %}
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            </x-frame>
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        </x-vbox>
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        {% endblock %}
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                            
                                

templates/repo.html

@@ -19,6 +19,7 @@

                                
                                
                                
                            
                                
                                    
                                        
                                            
                                            <!--            <li><a href="/{{ username }}/{{ repository }}/activity">Activity</a></li>-->
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                            <!--            <li><a href="/{{ username }}/{{ repository }}/people">People</a></li>-->
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                            <!--            <li><a href="/{{ username }}/{{ repository }}/ci">CI</a></li>-->
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                    <li><a href="/{{ username }}/{{ repository }}/forum">Forum</a></li>
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                        <li><a href="/{{ username }}/{{ repository }}/users">Users</a></li>
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                        <li><a href="/{{ username }}/{{ repository }}/settings">Settings</a></li>
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                    </ul>