Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow administering gem typo exceptions thru admin interface #4131

Merged
merged 1 commit into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions app/avo/resources/gem_typo_exception_resource.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class GemTypoExceptionResource < Avo::BaseResource
self.title = :name
self.includes = []
self.search_query = lambda {
scope.where("name ILIKE ?", "%#{params[:q]}%")
}

field :id, as: :id, hide_on: :index
# Fields generated from the model
field :name, as: :text, link_to_resource: true
field :info, as: :textarea
# add fields here
field :created_at, as: :date_time, sortable: true
field :updated_at, as: :date_time, sortable: true
end
4 changes: 4 additions & 0 deletions app/controllers/avo/gem_typo_exceptions_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# This controller has been generated to enable Rails' resource routes.
# More information on https://docs.avohq.io/2.0/controllers.html
class Avo::GemTypoExceptionsController < Avo::ResourcesController
end
20 changes: 20 additions & 0 deletions app/policies/gem_typo_exception_policy.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
class GemTypoExceptionPolicy < ApplicationPolicy
class Scope < Scope
def resolve
scope.all
end
end

def avo_index?
rubygems_org_admin?
end

def avo_show?
rubygems_org_admin?
end

def avo_create? = rubygems_org_admin?
def avo_update? = rubygems_org_admin?
def avo_destroy? = rubygems_org_admin?
def act_on? = rubygems_org_admin?
end
42 changes: 42 additions & 0 deletions test/policies/gem_typo_exception_policy_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
require "test_helper"

class GemTypoExceptionPolicyTest < ActiveSupport::TestCase
setup do
@exception = create(:gem_typo_exception)

@admin = create(:admin_github_user, :is_admin)
@non_admin = create(:admin_github_user)
end

def test_scope
assert_equal [@exception], Pundit.policy_scope!(
@admin,
GemTypoException
).to_a
end

def test_avo_index
assert_predicate Pundit.policy!(@admin, GemTypoException), :avo_index?
refute_predicate Pundit.policy!(@non_admin, GemTypoException), :avo_index?
end

def test_avo_show
assert_predicate Pundit.policy!(@admin, @exception), :avo_show?
refute_predicate Pundit.policy!(@non_admin, @exception), :avo_show?
end

def test_avo_create
assert_predicate Pundit.policy!(@admin, GemTypoException), :avo_create?
refute_predicate Pundit.policy!(@non_admin, GemTypoException), :avo_create?
end

def test_avo_update
assert_predicate Pundit.policy!(@admin, @exception), :avo_update?
refute_predicate Pundit.policy!(@non_admin, @exception), :avo_update?
end

def test_avo_destroy
assert_predicate Pundit.policy!(@admin, @exception), :avo_destroy?
refute_predicate Pundit.policy!(@non_admin, @exception), :avo_destroy?
end
end