#4467 Add a take button to adopt orphaned package
Merged 4 years ago by pingou. Opened 4 years ago by pingou.

@@ -104,7 +104,8 @@ 

              <div class="text-muted">Created {{repo.date_created|humanize}}</div>

              <div class="text-muted">

                Maintained by

-               <a href="{{ url_for('ui_ns.view_user', username=repo.user.user)}}">

+               <a href="{{ url_for('ui_ns.view_user', username=repo.user.user)}}"

+                  id="point_of_contact">

                  {{- repo.user.user -}}

                </a>

              </div>

@@ -79,7 +79,7 @@ 

        <a class="dropdown-item pl-2" id="no_monitoring_option_button">

          <div class="media">

            <div class="align-self-center check-icon pr-2">

-               <span class="fa fa-fw"></span>

+             <span class="fa fa-fw"></span>

            </div>

            <div class="media-body">

                No-Monitoring
@@ -89,26 +89,41 @@ 

        <a class="dropdown-item pl-2" id="monitoring_option_button">

          <div class="media">

              <div class="align-self-center check-icon pr-2">

-                 <span class="fa fa-fw"></span>

+               <span class="fa fa-fw"></span>

              </div>

              <div class="media-body">

-                 Monitoring

+               Monitoring

              </div>

            </div>

        </a>

        <a class="dropdown-item pl-2" id="monitoring_and_scratch_option_button">

          <div class="media">

            <div class="align-self-center check-icon pr-2">

-               <span class="fa fa-fw"></span>

+             <span class="fa fa-fw"></span>

            </div>

            <div class="media-body">

-               monitoring and scratch builds

+             monitoring and scratch builds

            </div>

          </div>

        </a>

      </div>

    </div>

  

+   {% if g.authenticated and repo.user.user == "orphan" %}

+   <div id="take-orphan-section">

+     <div class="col-xs-2" style="height:1em;"></div>

+     <p>Orphaned:</p>

+     <div class="btn-group">

+       <a href="#" title="Adopt this orphaned package"

+           class="btn btn-sm btn-outline-primary"

+           id="take-orphan-button">

+         <i id="take-orphan-icon" class="fa fa-fw fa-hand-paper-o"></i>

+         Take

+       </a>

+     </div>

+   </div>

+   {% endif %}

+ 

    <script type="text/javascript" nonce="{{ g.nonce }}">

      window.addEventListener('load', function() {

  
@@ -140,31 +155,53 @@ 

  

        {% if g.authenticated %}

        $(".monitoring-menu a").click(function(){

-           var selectedValue = $(this).attr('id');

-           var _status = "no-monitoring";

-           if (selectedValue === "monitoring_option_button") {

-               _status = "monitoring";

-           } else if (selectedValue === "monitoring_and_scratch_option_button") {

-               _status = "monitoring-with-scratch"

+         var selectedValue = $(this).attr('id');

+         var _status = "no-monitoring";

+         if (selectedValue === "monitoring_option_button") {

+             _status = "monitoring";

+         } else if (selectedValue === "monitoring_and_scratch_option_button") {

+             _status = "monitoring-with-scratch"

+         }

+ 

+         $.ajax({

+           url: "{{ url_for('distgit_ns.anitya_patch_endpoint', repo=repo.name, namespace=repo.namespace) }}",

+           type: 'PATCH',

+           data: {

+             anitya_status: _status,

+           },

+           dataType: 'json',

+           success: function(res) {

+             set_up_monitoring(res.monitoring)

+           },

+           error: function() {

+             alert('Unable to change the monitoring status! ' + error);

            }

+         });

+       });

+       {% endif %}

  

-           $.ajax({

-             url: "{{ url_for('distgit_ns.anitya_patch_endpoint', repo=repo.name, namespace=repo.namespace) }}",

-             type: 'PATCH',

-             data: {

-               anitya_status: _status,

-             },

-             dataType: 'json',

-             success: function(res) {

-               set_up_monitoring(res.monitoring)

-             },

-             error: function() {

-               alert('Unable to change the monitoring status! ' + error);

-             }

-           });

+       {% if g.authenticated and repo.user.user == "orphan" %}

+       $("#take-orphan-button").click(function(){

  

+         $.ajax({

+           url: "{{ url_for('distgit_ns.take_orphan_endpoint', repo=repo.name, namespace=repo.namespace) }}",

+           type: 'POST',

+           dataType: 'json',

+           success: function(res) {

+             $("#point_of_contact").html("{{ g.fas_user.username }}");

+             $("#take-orphan-section").hide();

+           },

+           error: function(res) {

+             if (res.responseJSON.errors) {

+               alert('Unable to change the point of contact: ' + res.responseJSON.errors);

+             } else {

+               alert('Unable to change the point of contact: ' + res.responseJSON.error);

+             }

+           }

+         });

        });

        {% endif %}

+ 

      });

    </script>

    {% endif %}

file modified
+32 -13
@@ -3084,6 +3084,8 @@ 

              flask.abort(

                  404, description="No such user %s found" % new_username

              )

+ 

+         failed = False

          try:

              old_main_admin = repo.user.user

              pagure.lib.query.set_project_owner(
@@ -3092,25 +3094,14 @@ 

                  new_owner,

                  required_groups=pagure_config.get("REQUIRED_GROUPS"),

              )

-             # If the person doing the action is the former main admin, keep

-             # them as admins

-             if flask.g.fas_user.username == old_main_admin:

-                 pagure.lib.query.add_user_to_project(

-                     flask.g.session,

-                     repo,

-                     new_user=flask.g.fas_user.username,

-                     user=flask.g.fas_user.username,

-                 )

              flask.g.session.commit()

-             pagure.lib.git.generate_gitolite_acls(project=repo)

-             flask.flash(

-                 "The project has been transferred to %s" % new_username

-             )

          except pagure.exceptions.PagureException as msg:

+             failed = True

              flask.g.session.rollback()

              _log.debug(msg)

              flask.flash(str(msg), "error")

          except SQLAlchemyError:  # pragma: no cover

+             failed = True

              flask.g.session.rollback()

              flask.flash(

                  "Due to a database error, this project could not be "
@@ -3118,6 +3109,34 @@ 

                  "error",

              )

  

+         if not failed:

+             try:

+                 # If the person doing the action is the former main admin, keep

+                 # them as admins

+                 if flask.g.fas_user.username == old_main_admin:

+                     pagure.lib.query.add_user_to_project(

+                         flask.g.session,

+                         repo,

+                         new_user=flask.g.fas_user.username,

+                         user=flask.g.fas_user.username,

+                     )

+                 flask.g.session.commit()

+             except pagure.exceptions.PagureException as msg:

+                 flask.g.session.rollback()

+                 _log.debug(msg)

+             except SQLAlchemyError:  # pragma: no cover

+                 flask.g.session.rollback()

+                 flask.flash(

+                     "Due to a database error, this access could not be "

+                     "entirely set.",

+                     "error",

+                 )

+ 

+             pagure.lib.git.generate_gitolite_acls(project=repo)

+             flask.flash(

+                 "The project has been transferred to %s" % new_username

+             )

+ 

      return flask.redirect(

          flask.url_for(

              "ui_ns.view_repo",

no initial comment

Metadata Update from @pingou:
- Pull-request tagged with: RFE

4 years ago

rebased onto aceb382415193d07c2acd21be6636ac57d9e56d8

4 years ago

rebased onto 15904895ca4005c308ccfcbb3b27a32151d5671e

4 years ago

Could you put a picture of what this looks like?

It should be ensured that retired packages cannot be claimed unless they were just retired recently. Will this be checked at a later stage? It might be less confusing if the UI shows this as well. Maybe it would be better to introduce a user named "dead" or something to indicate that a package is retired to make these kind of checks easier.

@till This is the PR where the logic is implemented:
https://pagure.io/pagure-dist-git/pull-request/72
I worked with Mohan to be sure the logic was sound.

rebased onto f29ffd8

4 years ago

Thanks for the review :)

Pull-Request has been merged by pingou

4 years ago