forked from zammad/zammad
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes zammad#4381 - Ticket templates are missing active flag.
- Loading branch information
Showing
13 changed files
with
216 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/ | ||
|
||
class Controllers::TemplatesControllerPolicy < Controllers::ApplicationControllerPolicy | ||
default_permit!(['ticket.agent', 'admin.template']) | ||
default_permit!('admin.template') | ||
permit! %i[index show], to: ['admin.template', 'ticket.agent'] | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/ | ||
|
||
class TemplatePolicy < ApplicationPolicy | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/ | ||
|
||
class TemplatePolicy < ApplicationPolicy | ||
class Scope < ApplicationPolicy::Scope | ||
|
||
def resolve | ||
if user.permissions?('admin.template') | ||
scope.all | ||
elsif user.permissions?('ticket.agent') | ||
scope.active | ||
else | ||
scope.none | ||
end | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
db/migrate/20221205151816_issue_4381_templates_active_field.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/ | ||
|
||
class Issue4381TemplatesActiveField < ActiveRecord::Migration[6.1] | ||
def change | ||
# return if it's a new setup | ||
return if !Setting.exists?(name: 'system_init_done') | ||
|
||
change_table :templates do |t| | ||
t.boolean :active, default: true, null: false | ||
end | ||
|
||
Template.reset_column_information | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/ | ||
|
||
require 'rails_helper' | ||
|
||
RSpec.describe TemplatePolicy::Scope do | ||
subject(:scope) { described_class.new(user, original_collection) } | ||
|
||
let(:original_collection) { Template } | ||
|
||
let(:active_template) { create(:template, :dummy_data, active: true) } | ||
let(:inactive_template) { create(:template, :dummy_data, active: false) } | ||
|
||
before do | ||
Template.destroy_all | ||
active_template && inactive_template | ||
end | ||
|
||
describe '#resolve' do | ||
context 'without user' do | ||
let(:user) { nil } | ||
|
||
it 'throws exception' do | ||
expect { scope.resolve }.to raise_error %r{Authentication required} | ||
end | ||
end | ||
|
||
context 'with customer' do | ||
let(:user) { create(:customer) } | ||
|
||
it 'returns empty' do | ||
expect(scope.resolve).to be_empty | ||
end | ||
end | ||
|
||
context 'with agent' do | ||
let(:user) { create(:agent) } | ||
|
||
it 'returns active template only' do | ||
expect(scope.resolve).to match_array [active_template] | ||
end | ||
end | ||
|
||
context 'with admin' do | ||
let(:user) { create(:admin) } | ||
|
||
it 'returns all templates' do | ||
expect(scope.resolve).to match_array [active_template, inactive_template] | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters