Fix primary site not being preserved

by roundabout, Monday, 29 April 2024, 07:06:01 (1714374361), pushed by roundabout, Wednesday, 31 July 2024, 06:54:47 (1722408887)

Author identity: vlad <vlad.muntoiu@gmail.com>

306aa026976ba44e84569215b1198a12d32b6e3e

app.py

@@ -1503,14 +1503,15 @@ def repository_settings_post(username, repository):

                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                old_branch = repo.site_branch
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                if flask.request.form.get("site_branch"):
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                    repo.site_branch = flask.request.form.get("site_branch")
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                if flask.request.form.get("primary_site") and had_site != 2:
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                    # Remove primary site from other repos
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                    for other_repo in Repo.query.filter_by(owner=repo.owner, has_site=2):
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                        other_repo.has_site = 1                           # switch it to a regular site
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                        flask.flash(Markup(
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                                _("Your repository {repository} has been demoted from a primary site to a regular site because there can only be one primary site per user.").format(
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                                        repository=other_repo.route
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                                )), category="warning")
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                if flask.request.form.get("primary_site"):
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                    if had_site != 2:
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                        # Remove primary site from other repos
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                        for other_repo in Repo.query.filter_by(owner=repo.owner, has_site=2):
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                            other_repo.has_site = 1                           # switch it to a regular site
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                            flask.flash(Markup(
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                                    _("Your repository {repository} has been demoted from a primary site to a regular site because there can only be one primary site per user.").format(
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                                            repository=other_repo.route
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                                    )), category="warning")
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                        repo.has_site = 2
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                    else:
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                        repo.has_site = 1
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                            
                                

templates/home.html

@@ -14,8 +14,8 @@

                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                    <h2>{% trans %}Search{% endtrans %}</h2>
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                    <form action="/search" method="get">
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                        <x-buttonbox>
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                        <input type="text" name="q" placeholder="Search repositories...">
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                        <button type="submit">Search</button>
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                        <input type="text" name="q" placeholder="{% trans %}Search repositories...{% endtrans %}" required>
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                        <button type="submit">{% trans %}Search{% endtrans %}</button>
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                        </x-buttonbox>
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                    </form>
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                </x-frame>
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                            
                                

templates/repository/repo-settings.html

@@ -51,7 +51,7 @@ Note that only branch names are supported, not other references like tags or com

                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                                            </select>
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                                        </x-vbox>
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                                        <label>
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                                        <input type="checkbox" name="primary_site" value="1" {% if repo_data.has_site == 2 %}checked{% endif %}>
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                                        <input type="checkbox" name="primary_site" {% if repo_data.has_site == 2 %}checked{% endif %}>
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                                            {% trans %}Make this the primary site{% endtrans %}
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                                        </label>
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                                        <p>
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                            
                                

templates/repository/repo-users.html

@@ -27,7 +27,7 @@

                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                                                    <select id="update-level" name="update-level">
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                                                        <option value="-1">{% trans %}Remove{% endtrans %}</option>
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                                                        <option value="0" {% if relationship.access_level == 0 %}selected{% endif %}>
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                                                        {% if repoData.visibility %}
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                                                                        {% if repo_data.visibility %}
                                        
                                        
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                                                                {% trans %}Contributor{% endtrans %}
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                                                            {% else %}
                                        
                                        
                                            
                                            
                                            
                                            
                                        
                                    
                                
                                
                                
                            
                                
                                    
                                        
                                            
                                                                                                {% trans %}Read-only{% endtrans %}