diff --git a/app/controllers/templates_controller.rb b/app/controllers/templates_controller.rb index c150673..9108ba9 100644 --- a/app/controllers/templates_controller.rb +++ b/app/controllers/templates_controller.rb @@ -190,13 +190,12 @@ def admin_create @template = Template.new(params[:template]) authorize @template - - @template.org_id = current_user.org_id + @template.org_id = current_user.org.id @template.description = params['template-desc'] @template.published = false @template.version = 0 @template.visibility = 0 - + # Generate a unique identifier for the dmptemplate_id @template.dmptemplate_id = loop do random = rand 2147483647 diff --git a/app/policies/template_policy.rb b/app/policies/template_policy.rb index 41e1f7c..77b396c 100644 --- a/app/policies/template_policy.rb +++ b/app/policies/template_policy.rb @@ -30,7 +30,7 @@ end def admin_create? - user.can_modify_templates? && (template.org_id == user.org_id) + user.can_modify_templates? end def admin_destroy? diff --git a/test/functional/templates_controller_test.rb b/test/functional/templates_controller_test.rb index 6e390ee..2266a6f 100644 --- a/test/functional/templates_controller_test.rb +++ b/test/functional/templates_controller_test.rb @@ -124,7 +124,7 @@ # POST /org/admin/templates/:id/admin_create (admin_create_template_path) # ---------------------------------------------------------- test "create a admin template" do - params = {org_id: @user.org.id, version: 0, title: 'Testing create route'} + params = {title: 'Testing create route'} # Should redirect user to the root path if they are not logged in! post admin_create_template_path(Template.last.id), {template: params}