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

Resolving and deleting comments

roundabout,
created on Thursday, 23 May 2024, 06:40:26 (1716446426), received on Wednesday, 31 July 2024, 06:54:48 (1722408888)
Author identity: vlad <vlad.muntoiu@gmail.com>

d0ebe40a67ebeccbb830d9eb7b6bb944d9e3a644

app.py

@@ -808,6 +808,7 @@ def repository_commit(username, repository, sha):

                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                        data=db.session.get(Commit, f"/{username}/{repository}/{sha}"),
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                        repo_data=repo_data,
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                        comment_query=Comment.query,
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                    permission_level=get_permission_level(flask.session.get("username"), username, repository),
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                )
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                            
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                            
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        

@@ -840,6 +841,43 @@ def repository_commit_add_comment(username, repository, sha):

                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                )
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                            
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                            
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        @repositories.route("/<username>/<repository>/commit/<sha>/delete_comment/<int:id>", methods=["POST"])
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        def repository_commit_delete_comment(username, repository, sha, id):
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            repo_data = Repo.query.filter_by(route=f"/{username}/{repository}").first()
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            print(f"/{username}/{repository}/{flask.request.form.get('id')}")
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            comment = Comment.query.filter_by(identifier=f"/{username}/{repository}/{id}").first()
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            commit = Commit.query.filter_by(identifier=f"/{username}/{repository}/{sha}").first()
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            if (
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                comment.owner.username == flask.session.get("username")
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                or get_permission_level(flask.session.get("username"), username, repository) >= 2
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                or comment.commit.owner.username == flask.session.get("username")
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            ):
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                db.session.delete(comment)
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                db.session.commit()
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            return flask.redirect(
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                flask.url_for(".repository_commit", username=username, repository=repository, sha=sha),
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                code=303
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            )
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        @repositories.route("/<username>/<repository>/commit/<sha>/resolve_comment/<int:id>", methods=["POST"])
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        def repository_commit_resolve_comment(username, repository, sha, id):
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            comment = Comment.query.filter_by(identifier=f"/{username}/{repository}/{id}").first()
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            if (
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                comment.commit.owner.username == flask.session.get("username")
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                or get_permission_level(flask.session.get("username"), username, repository) >= 2
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                or comment.owner.username == flask.session.get("username")
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            ):
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                comment.state = int(not comment.state)
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                db.session.commit()
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            return flask.redirect(
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                flask.url_for(".repository_commit", username=username, repository=repository, sha=sha),
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                code=303
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            )
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                            @repositories.route("/<username>/<repository>/forum/")
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                            def repository_forum(username, repository):
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                server_repo_location = os.path.join(config.REPOS_PATH, username, repository)
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                            
                                

static/style.css

@@ -292,7 +292,7 @@ x-buttonbox.segmented > * {

                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                text-align: center;
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                            }
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                            
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        .reply-area {
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        .reply-area, .resolved-comments {
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                box-shadow: var(--shadow-card);
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                margin: var(--margin-card);
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                border-radius: var(--radius-card);
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        

@@ -305,7 +305,7 @@ x-buttonbox.segmented > * {

                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                height: 100%;
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                            }
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                            
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        .reply-area > summary {
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        .reply-area > summary, .resolved-comments > summary {
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                display: flex;
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                align-items: center;
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                cursor: pointer;
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        

@@ -321,7 +321,7 @@ x-buttonbox.segmented > * {

                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                padding-top: var(--padding-card-top);
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                            }
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                            
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        .reply-area > summary::before {
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        .reply-area > summary::before, .resolved-comments > summary::before {
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                content: " ";
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                background-image: url("/static/efficient-ui/icons/expand.svg");
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                transform: rotate(-90deg);
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        

@@ -332,7 +332,7 @@ x-buttonbox.segmented > * {

                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                transition: transform 250ms cubic-bezier(0.33, 1, 0.68, 1);
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                            }
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                            
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        .reply-area[open] > summary::before {
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        .reply-area[open] > summary::before, .resolved-comments[open] > summary::before {
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                transform: rotate(0);
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                            }
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                            
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        

@@ -597,4 +597,11 @@ strong, em {

                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                z-index: 2;
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                border-radius: var(--radius-card);
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                border: var(--border-card);
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            display: flex;
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            flex-flow: column nowrap;
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        }
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        .resolved-comments {
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            grid-column: 1 / -1;
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            font: var(--body-font);
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                            }
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                            
                                

templates/repository/repo-commit.html

@@ -65,14 +65,48 @@

                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                                                    {% endif %}
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                                                {% endif %}
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                                            {% endif %}
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                                        {% for comment in comment_query.filter_by(commit=data, file=file, line_number=vars.original_line).all() %}
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                                        {% for comment in comment_query.filter_by(commit=data, file=file, line_number=vars.original_line, state=1).all() %}
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                                                <div class="comment">
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                                                    {{ comment.message }}
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                                                <x-buttonbox>
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                                                    {% if comment.author == current_user or data.owner == current_user or permission_level >= 2 %}
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                                                        <form method="post" action="{{ repo_data.route }}/commit/{{ data.sha }}/resolve_comment/{{ comment.number }}">
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                                                            <button type="submit">
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                                                                Resolve
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                                                            </button>
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                                                        </form>
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                                                        <form method="post" action="{{ repo_data.route }}/commit/{{ data.sha }}/delete_comment/{{ comment.number }}">
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                                                            <button type="submit" class="button-flat">Delete</button>
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                                                        </form>
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                                                    {% endif %}
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                                                </x-buttonbox>
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                                                </div>
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                                            {% endfor %}
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                                        {% if comment_query.filter_by(commit=data, file=file, line_number=vars.original_line, state=0).count() %}
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                                            <details class="resolved-comments">
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                                                <summary>{% trans count=comment_query.filter_by(commit=data, file=file, line_number=vars.original_line, state=0).count() %}Resolved comments ({{ count }}){% endtrans %}</summary>
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                                                {% for comment in comment_query.filter_by(commit=data, file=file, line_number=vars.original_line, state=0).all() %}
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                                                    <div class="comment">
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                                                        {{ comment.message }}
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                                                        <x-buttonbox>
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                                                            {% if comment.author == current_user or data.owner == current_user or permission_level >= 2 %}
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                                                                <form method="post" action="{{ repo_data.route }}/commit/{{ data.sha }}/resolve_comment/{{ comment.number }}">
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                                                                    <button type="submit">
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                                                                        Un-resolve
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                                                                    </button>
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                                                                </form>
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                                                                <form method="post" action="{{ repo_data.route }}/commit/{{ data.sha }}/delete_comment/{{ comment.number }}">
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                                                                    <button type="submit" class="button-flat">Delete</button>
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                                                                </form>
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                                                            {% endif %}
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                                                        </x-buttonbox>
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                                                    </div>
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                                                {% endfor %}
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                                            </details>
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                                        {% endif %}
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                                        {% endfor %}
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                                        {% if vars.hunk_started %}
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                                        </pre> <!-- close the last hunk -->
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                                        </pre> {# close the last hunk #}
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                                        {% endif %}
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                                    </section>
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                                </article>