-
<% if item.to_create is true: %>
- <%- @T('Create') %> <%= item.object %>.<%= item.name %> (<%= item.data_type %>)
+ <%- @T('Create') %>: <%= item.object %>.<%= item.name %> (<%= item.data_type %>)
<% else if item.to_delete is true: %>
- <%- @T('Delete') %> <%= item.object %>.<%= item.name %> (<%= item.data_type %>)
+ <%- @T('Delete') %>: <%= item.object %>.<%= item.name %> (<%= item.data_type %>)
<% end %>
<% end %>
diff --git a/app/assets/javascripts/app/views/object_manager/screens.jst.eco b/app/assets/javascripts/app/views/object_manager/screens.jst.eco
index 6f4e58d7d..ea147b486 100644
--- a/app/assets/javascripts/app/views/object_manager/screens.jst.eco
+++ b/app/assets/javascripts/app/views/object_manager/screens.jst.eco
@@ -20,7 +20,7 @@
<%= screen %>
<% for key, defaultValue of options: %>
- <%= @T(key) %>: checked<% end %> value="true">
+ <%- @T(key) %>: checked<% end %> value="true">
<% end %>
<% end %>
<% end %>
diff --git a/app/controllers/object_manager_attributes_controller.rb b/app/controllers/object_manager_attributes_controller.rb
index 8412fcd98..bddae29e4 100644
--- a/app/controllers/object_manager_attributes_controller.rb
+++ b/app/controllers/object_manager_attributes_controller.rb
@@ -27,36 +27,59 @@ class ObjectManagerAttributesController < ApplicationController
def create
return if deny_if_not_role(Z_ROLENAME_ADMIN)
check_params
- object_manager_attribute = ObjectManager::Attribute.add(
+
+ # check if attribute already exists
+ exists = ObjectManager::Attribute.get(
object: params[:object],
name: params[:name],
- display: params[:display],
- data_type: params[:data_type],
- data_option: params[:data_option],
- active: params[:active],
- screens: params[:screens],
- position: 1550,
- editable: true,
)
- render json: object_manager_attribute.attributes_with_associations, status: :created
+ if exists
+ render json: model_match_error('already exists'), status: :unprocessable_entity
+ return
+ end
+
+ begin
+ object_manager_attribute = ObjectManager::Attribute.add(
+ object: params[:object],
+ name: params[:name],
+ display: params[:display],
+ data_type: params[:data_type],
+ data_option: params[:data_option],
+ active: params[:active],
+ screens: params[:screens],
+ position: 1550,
+ editable: true,
+ )
+ render json: object_manager_attribute.attributes_with_associations, status: :created
+ rescue => e
+ logger.error e.message
+ logger.error e.backtrace.inspect
+ render json: model_match_error(e.message), status: :unprocessable_entity
+ end
end
# PUT /object_manager_attributes/1
def update
return if deny_if_not_role(Z_ROLENAME_ADMIN)
check_params
- object_manager_attribute = ObjectManager::Attribute.add(
- object: params[:object],
- name: params[:name],
- display: params[:display],
- data_type: params[:data_type],
- data_option: params[:data_option],
- active: params[:active],
- screens: params[:screens],
- position: 1550,
- editable: true,
- )
- render json: object_manager_attribute.attributes_with_associations, status: :ok
+ begin
+ object_manager_attribute = ObjectManager::Attribute.add(
+ object: params[:object],
+ name: params[:name],
+ display: params[:display],
+ data_type: params[:data_type],
+ data_option: params[:data_option],
+ active: params[:active],
+ screens: params[:screens],
+ position: 1550,
+ editable: true,
+ )
+ render json: object_manager_attribute.attributes_with_associations, status: :ok
+ rescue => e
+ logger.error e.message
+ logger.error e.backtrace.inspect
+ render json: model_match_error(e.message), status: :unprocessable_entity
+ end
end
# DELETE /object_manager_attributes/1
diff --git a/app/models/object_manager/attribute.rb b/app/models/object_manager/attribute.rb
index 48b96dace..cd1d44c54 100644
--- a/app/models/object_manager/attribute.rb
+++ b/app/models/object_manager/attribute.rb
@@ -490,10 +490,15 @@ returns
end
def check_name
- if name
- return true if name !~ /_(id|ids)$/i && name !~ /^id$/i && name !~ /\s/
+ return if !name
+ if name =~ /_(id|ids)$/i || name =~ /^id$/i
+ raise 'Name can\'t get used, *_id and *_ids are not allowed'
+ elsif name =~ /\s/
+ raise 'Spaces in name are not allowed'
+ elsif name !~ /^[a-z0-9_]+$/
+ raise 'Only letters from a-z, numbers from 0-9, and _ are allowed'
end
- raise "Name can't get used, *_id and *_ids are not allowed"
+ true
end
def check_editable
diff --git a/script/build/test_slice_tests.sh b/script/build/test_slice_tests.sh
index 949a50abd..e0ffce52a 100755
--- a/script/build/test_slice_tests.sh
+++ b/script/build/test_slice_tests.sh
@@ -10,6 +10,7 @@ if [ "$LEVEL" == '1' ]; then
# test/browser/aac_basic_richtext_test.rb
# test/browser/abb_one_group_test.rb
rm test/browser/admin_channel_email_test.rb
+ rm test/browser/admin_object_manager_test.rb
rm test/browser/admin_overview_test.rb
# test/browser/agent_navigation_and_title_test.rb
rm test/browser/agent_ticket_actions_level0_test.rb
@@ -51,6 +52,7 @@ elif [ "$LEVEL" == '2' ]; then
rm test/browser/aac_basic_richtext_test.rb
# test/browser/abb_one_group_test.rb
rm test/browser/admin_channel_email_test.rb
+ rm test/browser/admin_object_manager_test.rb
rm test/browser/admin_overview_test.rb
rm test/browser/agent_navigation_and_title_test.rb
rm test/browser/agent_organization_profile_test.rb
@@ -93,6 +95,7 @@ elif [ "$LEVEL" == '3' ]; then
rm test/browser/aac_basic_richtext_test.rb
# test/browser/abb_one_group_test.rb
rm test/browser/admin_channel_email_test.rb
+ rm test/browser/admin_object_manager_test.rb
rm test/browser/admin_overview_test.rb
rm test/browser/agent_navigation_and_title_test.rb
rm test/browser/agent_organization_profile_test.rb
@@ -135,6 +138,7 @@ elif [ "$LEVEL" == '4' ]; then
rm test/browser/aac_basic_richtext_test.rb
# test/browser/abb_one_group_test.rb
rm test/browser/admin_channel_email_test.rb
+ rm test/browser/admin_object_manager_test.rb
rm test/browser/admin_overview_test.rb
rm test/browser/agent_navigation_and_title_test.rb
rm test/browser/agent_organization_profile_test.rb
@@ -177,6 +181,7 @@ elif [ "$LEVEL" == '5' ]; then
rm test/browser/aac_basic_richtext_test.rb
# test/browser/abb_one_group_test.rb
# test/browser/admin_channel_email_test.rb
+ # test/browser/admin_object_manager_test.rb
# test/browser/admin_overview_test.rb
rm test/browser/agent_navigation_and_title_test.rb
# test/browser/agent_organization_profile_test.rb
diff --git a/test/browser/admin_object_manager_test.rb b/test/browser/admin_object_manager_test.rb
new file mode 100644
index 000000000..51d27841b
--- /dev/null
+++ b/test/browser/admin_object_manager_test.rb
@@ -0,0 +1,157 @@
+# encoding: utf-8
+require 'browser_test_helper'
+
+class AdminObjectManagerTest < TestCase
+ def test_basic
+ name = "some overview #{rand(99_999_999)}"
+
+ @browser = browser_instance
+ login(
+ username: 'master@example.com',
+ password: 'test',
+ url: browser_url,
+ )
+ tasks_close_all()
+
+ click(css: 'a[href="#manage"]')
+ click(css: 'a[href="#system/object_manager"]')
+
+ click(css: '#content .js-new')
+
+ modal_ready()
+
+ # already existing
+ set(
+ css: '.modal input[name="name"]',
+ value: 'customer_id',
+ )
+ set(
+ css: '.modal input[name="display"]',
+ value: 'Customer Should Not Creatable',
+ )
+ click(css: '.modal button.js-submit')
+ sleep 4
+ watch_for(
+ css: '.modal',
+ value: '(already exists)',
+ )
+
+ # invalid name
+ set(
+ css: '.modal input[name="name"]',
+ value: 'some_other_id',
+ )
+ set(
+ css: '.modal input[name="display"]',
+ value: 'Should Not Creatable',
+ )
+ click(css: '.modal button.js-submit')
+ sleep 4
+ watch_for(
+ css: '.modal',
+ value: '(are not allowed)',
+ )
+
+ # invalid name
+ set(
+ css: '.modal input[name="name"]',
+ value: 'some_other_ids',
+ )
+ set(
+ css: '.modal input[name="display"]',
+ value: 'Should Not Creatable',
+ )
+ click(css: '.modal button.js-submit')
+ sleep 4
+ watch_for(
+ css: '.modal',
+ value: '(are not allowed)',
+ )
+
+ # invalid name
+ set(
+ css: '.modal input[name="name"]',
+ value: 'some spaces',
+ )
+ set(
+ css: '.modal input[name="display"]',
+ value: 'Should Not Creatable',
+ )
+ click(css: '.modal button.js-submit')
+ sleep 4
+ watch_for(
+ css: '.modal',
+ value: '(are not allowed)',
+ )
+ click(css: '.modal .js-close')
+ modal_ready()
+
+ # valid name
+ click(css: '#content .js-new')
+ modal_ready()
+ set(
+ css: '.modal input[name="name"]',
+ value: 'browser_test1',
+ )
+ set(
+ css: '.modal input[name="display"]',
+ value: 'Browser Test 1',
+ )
+ click(css: '.modal button.js-submit')
+ watch_for(
+ css: '#content table',
+ value: 'browser_test1',
+ )
+ watch_for(
+ css: '#content',
+ value: 'Database Update required',
+ )
+ click(css: '#content .tab-pane.active div.js-execute')
+ watch_for(
+ css: '.modal',
+ value: 'New Version',
+ )
+ click(css: '.modal button.js-submit')
+
+ # create new ticket
+
+ # update ticket
+
+ # discard new attribute
+
+ watch_for(
+ css: '#content table',
+ value: 'browser_test1',
+ )
+ match_not(
+ css: '#content',
+ value: 'Database Update required',
+ )
+ click(css: '#content .tab-pane.active table tbody tr:last-child .js-delete')
+ sleep 4
+ watch_for(
+ css: '#content',
+ value: 'Database Update required',
+ )
+ watch_for(
+ css: '#content table',
+ value: 'browser_test1',
+ )
+ click(css: '#content .tab-pane.active div.js-execute')
+ watch_for(
+ css: '.modal',
+ value: 'New Version',
+ )
+ click(css: '.modal button.js-submit')
+ sleep 5
+ match_not(
+ css: '#content',
+ value: 'Database Update required',
+ )
+ match_not(
+ css: '#content table',
+ value: 'browser_test1',
+ )
+ end
+
+end
diff --git a/test/unit/object_manager_test.rb b/test/unit/object_manager_test.rb
index 532d09027..8409a694d 100644
--- a/test/unit/object_manager_test.rb
+++ b/test/unit/object_manager_test.rb
@@ -305,6 +305,69 @@ class ObjectManagerTest < ActiveSupport::TestCase
}
assert_equal(false, ObjectManager::Attribute.pending_migration?)
+ assert_raises(RuntimeError) {
+ attribute13 = ObjectManager::Attribute.add(
+ object: 'Ticket',
+ name: 'test13|',
+ display: 'Test 13',
+ data_type: 'date',
+ data_option: {
+ future: true,
+ past: false,
+ diff: 24,
+ null: true,
+ },
+ active: true,
+ screens: {},
+ position: 20,
+ created_by_id: 1,
+ updated_by_id: 1,
+ )
+ }
+ assert_equal(false, ObjectManager::Attribute.pending_migration?)
+
+ assert_raises(RuntimeError) {
+ attribute14 = ObjectManager::Attribute.add(
+ object: 'Ticket',
+ name: 'test14!',
+ display: 'Test 14',
+ data_type: 'date',
+ data_option: {
+ future: true,
+ past: false,
+ diff: 24,
+ null: true,
+ },
+ active: true,
+ screens: {},
+ position: 20,
+ created_by_id: 1,
+ updated_by_id: 1,
+ )
+ }
+ assert_equal(false, ObjectManager::Attribute.pending_migration?)
+
+ assert_raises(RuntimeError) {
+ attribute15 = ObjectManager::Attribute.add(
+ object: 'Ticket',
+ name: 'test15รค',
+ display: 'Test 15',
+ data_type: 'date',
+ data_option: {
+ future: true,
+ past: false,
+ diff: 24,
+ null: true,
+ },
+ active: true,
+ screens: {},
+ position: 20,
+ created_by_id: 1,
+ updated_by_id: 1,
+ )
+ }
+ assert_equal(false, ObjectManager::Attribute.pending_migration?)
+
end
test 'b object manager attribute' do
Database Update required
+<%- @T('Database Update required') %>
<%- @T('Changes were made that require a database update.') %> <%- @T('This might take some time where the system can\'t be used.') %> @@ -24,9 +24,9 @@ <% for item in @itemsToChange: %>