Skip to content

Commit

Permalink
rakeタスクとadmin画面から指定できるようにした
Browse files Browse the repository at this point in the history
  • Loading branch information
matobaa authored and Redmine Patch Meetup committed Nov 24, 2022
1 parent 4885089 commit 9f02c1a
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
5 changes: 4 additions & 1 deletion app/controllers/admin_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,11 @@ def plugins
# (roles, trackers, statuses, workflow, enumerations)
def default_configuration
if request.post?
options = {}
options[:default_projects_public] = params[:default_projects_public].presence || 'private'

begin
Redmine::DefaultData::Loader::load(params[:lang])
Redmine::DefaultData::Loader::load(params[:lang], options)
flash[:notice] = l(:notice_default_data_loaded)
rescue => e
flash[:error] = l(:error_can_t_load_default_data, ERB::Util.h(e.message))
Expand Down
3 changes: 2 additions & 1 deletion app/views/admin/_no_data.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
<%= form_tag({:action => 'default_configuration'}) do %>
<%= simple_format(l(:text_no_configuration_data)) %>
<p><%= l(:field_language) %>:
<%= select_tag 'lang', options_for_select(lang_options_for_select(false), current_language.to_s) %>
<%= select_tag 'lang', options_for_select(lang_options_for_select(false), current_language.to_s) %><br/>
<label class="inline"><%= check_box_tag :default_projects_public, 'public', true %> <%= l(:setting_default_projects_public) %></label><br/>
<%= submit_tag l(:text_load_default_configuration) %></p>
<% end %>
</div>
7 changes: 4 additions & 3 deletions lib/redmine/default_data/loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,10 @@ def load(lang=nil, options={})
support.id.to_s
]

# set new project as private
# もし環境変数 が private だったら
Setting.default_projects_public = 0
# set new project as private if default_projects_public option is exist
if options[:default_projects_public] == 'private'
Setting.default_projects_public = 0
end

if workflow
# Workflow
Expand Down
5 changes: 4 additions & 1 deletion lib/tasks/load_default_data.rake
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@ namespace :redmine do
puts "===================================="
end

options = {}
options[:default_projects_public] = ENV['REDMINE_DEFAULT_PROJECTS_PUBLIC'].presence

begin
Redmine::DefaultData::Loader.load(current_language)
Redmine::DefaultData::Loader.load(current_language, options)
puts "Default configuration data loaded."
rescue Redmine::DefaultData::DataAlreadyLoaded => error
puts error.message
Expand Down

0 comments on commit 9f02c1a

Please sign in to comment.