Skip to content

Commit

Permalink
Issue#3069 - (DCC Issue 675) - Org Admin and Super Admin searches and
Browse files Browse the repository at this point in the history
    pagination of user's plans broken.

    Fix for issue #3069 and DCC issue
    https://github.com/DigitalCurationCentre/DMPonline-Service/issues/675.

    Changes:
      - Replaced view files /paginable/plans/org_admin_other_user with /paginable/plans/_index.html.erb
        with extra checks for plan.owner.present? as missing plan.owner broke a DCC user's plans being render by org_admin.
      - Replaced partial with '/paginable/plans/org_admin_other_user'  with '/paginable/plans/index',
         replaced action'org_admin_other_user' with 'index' in paginable_renderiser() method in views
        /org_admin/users/edit.html.erb. /org_admin/users/plans.html.erb and /super_admin/users/edit.html.erb.
      - In Paginable::PlansController replaced -
        # GET /paginable/plans/org_admin/:page  with # GET /paginable/users/:id/plans
        associated with method org_admin_other_user()  renamed index()
      - Routes replaced
        get "org_admin_other_user/:page", action: :org_admin_other_user,
                                        on: :collection, as: :org_admin_other_user
        # Paginable actions for users
        resources :users, only: [] do
          get "index/:page", action: :index, on: :collection, as: :index

        with

        resources :users, only: %i[index] do
           member do
             resources :plans, only: %(index)
           end
        end
  • Loading branch information
John Pinto committed Jan 5, 2022
1 parent 43c5b03 commit 2c00cde
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 17 deletions.
9 changes: 5 additions & 4 deletions app/controllers/paginable/plans_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,19 @@ def org_admin
)
end

# GET /paginable/plans/org_admin/:page
def org_admin_other_user
# GET /paginable/users/:id/plans
def index
@user = User.find(params[:id])
authorize @user
unless current_user.present? && current_user.can_org_admin? && @user.present?
raise Pundit::NotAuthorizedError
end

paginable_renderise(
partial: "org_admin_other_user",
partial: "index",
scope: Plan.active(@user),
query_params: { sort_field: "plans.updated_at", sort_direction: :desc }
query_params: { sort_field: "plans.updated_at", sort_direction: :desc },
format: :json
)
end

Expand Down
4 changes: 2 additions & 2 deletions app/views/org_admin/users/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@
<div class="row">
<div class="col-md-12">
<%= paginable_renderise(
partial: '/paginable/plans/org_admin_other_user',
partial: '/paginable/plans/index',
controller: 'paginable/plans',
action: 'org_admin_other_user',
action: 'index',
scope: @plans,
query_params: { sort_field: 'plans.updated_at', sort_direction: 'desc' }) %>
</div>
Expand Down
4 changes: 2 additions & 2 deletions app/views/org_admin/users/plans.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
<div class="row">
<div class="col-md-12">
<%= paginable_renderise(
partial: '/paginable/plans/org_admin_other_user',
partial: '/paginable/plans/index',
controller: 'paginable/plans',
action: 'org_admin_other_user',
action: 'index',
remote: true,
scope: @plans,
query_params: { sort_field: 'plans.updated_at', sort_direction: 'desc' }) %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
<% end %>
</td>
<td><%= plan.template.title %></td>
<td><%= plan.owner.org.name %></td>
<td><%= plan.owner.name(false) %></td>
<td><%= plan.owner.org.name if plan.owner.present? %></td>
<td><%= plan.owner.name(false) if plan.owner.present? %></td>
<td><%= l(plan.updated_at.to_date, formats: :short) %></td>
<td class="plan-visibility">
<%= plan.visibility === 'is_test' ? _('Test') : sanitize(display_visibility(plan.visibility)) %>
Expand Down
4 changes: 2 additions & 2 deletions app/views/super_admin/users/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@
<div class="row">
<div class="col-md-12">
<%= paginable_renderise(
partial: '/paginable/plans/org_admin_other_user',
partial: '/paginable/plans/index',
controller: 'paginable/plans',
action: 'org_admin_other_user',
action: 'index',
scope: @plans,
query_params: { sort_field: 'plans.updated_at', sort_direction: 'desc' }) %>
</div>
Expand Down
10 changes: 5 additions & 5 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -210,17 +210,17 @@

get "org_admin/:page", action: :org_admin, on: :collection, as: :org_admin

get "org_admin_other_user/:page", action: :org_admin_other_user,
on: :collection, as: :org_admin_other_user

# Paginable actions for contributors
resources :contributors, only: %i[index] do
get "index/:page", action: :index, on: :collection, as: :index
end
end

# Paginable actions for users
resources :users, only: [] do
get "index/:page", action: :index, on: :collection, as: :index
resources :users, only: %i[index] do
member do
resources :plans, only: %(index)
end
end
# Paginable actions for themes
resources :themes, only: [] do
Expand Down

0 comments on commit 2c00cde

Please sign in to comment.