Initial commit
ci/woodpecker/manual/test_build Pipeline failed

This commit is contained in:
2026-06-07 17:56:08 +05:00
commit e436d0e8d8
77 changed files with 4533 additions and 0 deletions
@@ -0,0 +1,122 @@
# This file is a part of Redmine Checklists (redmine_checklists) plugin,
# issue checklists management plugin for Redmine
#
# Copyright (C) 2011-2024 RedmineUP
# http://www.redmineup.com/
#
# redmine_checklists is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# redmine_checklists is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with redmine_checklists. If not, see <http://www.gnu.org/licenses/>.
class ChecklistsController < ApplicationController
before_action :find_checklist_item, :except => [:index, :create]
before_action :find_issue_by_id, :only => [:index, :create]
before_action :authorize, :except => [:done]
helper :issues
accept_api_auth :index, :update, :destroy, :create, :show
def index
@checklists = @issue.checklists
respond_to do |format|
format.api
end
end
def show
respond_to do |format|
format.api
end
end
def destroy
@checklist_item.destroy
respond_to do |format|
format.api { render_api_ok }
end
end
def create
@checklist_item = Checklist.new
@checklist_item.safe_attributes = params[:checklist]
@checklist_item.issue = @issue
respond_to do |format|
format.api {
if @checklist_item.save
recalculate_issue_ratio(@checklist_item)
render :action => 'show', :status => :created, :location => checklist_url(@checklist_item)
else
render_validation_errors(@checklist_item)
end
}
end
end
def update
@checklist_item.safe_attributes = params[:checklist]
respond_to do |format|
format.api {
if with_issue_journal { @checklist_item.save }
recalculate_issue_ratio(@checklist_item)
render_api_ok
else
render_validation_errors(@checklist_item)
end
}
end
end
def done
(render_403; return false) unless User.current.allowed_to?(:done_checklists, @checklist_item.issue.project)
with_issue_journal do
@checklist_item.is_done = params[:is_done] == 'true'
if @checklist_item.save
recalculate_issue_ratio(@checklist_item)
true
end
end
respond_to do |format|
format.js
format.html { redirect_to :back }
end
end
private
def find_issue_by_id
@issue = Issue.find(params[:issue_id])
@project = @issue.project
rescue ActiveRecord::RecordNotFound
render_404
end
def find_checklist_item
@checklist_item = Checklist.find(params[:id])
@project = @checklist_item.issue.project
rescue ActiveRecord::RecordNotFound
render_404
end
def with_issue_journal(&block)
return unless yield
true
end
def recalculate_issue_ratio(checklist_item)
if (Setting.issue_done_ratio == 'issue_field') && RedmineChecklists.issue_done_ratio?
Checklist.recalc_issue_done_ratio(checklist_item.issue.id)
checklist_item.issue.reload
end
end
end
@@ -0,0 +1,58 @@
# encoding: utf-8
#
# This file is a part of Redmine Checklists (redmine_checklists) plugin,
# issue checklists management plugin for Redmine
#
# Copyright (C) 2011-2024 RedmineUP
# http://www.redmineup.com/
#
# redmine_checklists is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# redmine_checklists is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with redmine_checklists. If not, see <http://www.gnu.org/licenses/>.
module ChecklistsHelper
def link_to_remove_checklist_fields(name, f, options={})
f.hidden_field(:_destroy) + link_to(name, "javascript:void(0)", options)
end
def new_object(f, association)
@new_object ||= f.object.class.reflect_on_association(association).klass.new
end
def checklist_fields(f, association)
@fields ||= f.fields_for(association, new_object(f, association), :child_index => "new_#{association}") do |builder|
render(association.to_s.singularize + "_fields", :f => builder)
end
end
def new_or_show(f)
if f.object.new_record?
if f.object.subject.present?
"show"
else
"new"
end
else
"show"
end
end
def done_css(f)
if f.object.is_done
"is-done-checklist-item"
else
""
end
end
end
@@ -0,0 +1,79 @@
# This file is a part of Redmine Checklists (redmine_checklists) plugin,
# issue checklists management plugin for Redmine
#
# Copyright (C) 2011-2024 RedmineUP
# http://www.redmineup.com/
#
# redmine_checklists is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# redmine_checklists is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with redmine_checklists. If not, see <http://www.gnu.org/licenses/>.
class Checklist < ApplicationRecord
include Redmine::SafeAttributes
belongs_to :issue
belongs_to :author, :class_name => "User", :foreign_key => "author_id"
acts_as_event :datetime => :created_at,
:url => Proc.new {|o| {:controller => 'issues', :action => 'show', :id => o.issue_id}},
:type => 'issue issue-closed',
:title => Proc.new {|o| o.subject },
:description => Proc.new {|o| "#{l(:field_issue)}: #{o.issue.subject}" }
acts_as_activity_provider :type => "checklists",
:permission => :view_checklists,
:scope => preload({:issue => :project})
acts_as_searchable :columns => ["#{table_name}.subject"],
:scope => lambda { includes([:issue => :project]).order("#{table_name}.id") },
:project_key => "#{Issue.table_name}.project_id"
up_acts_as_list scope: :issue
validates_presence_of :subject
validates_length_of :subject, maximum: 512
validates_presence_of :position
validates_numericality_of :position
def self.recalc_issue_done_ratio(issue_id)
issue = Issue.find(issue_id)
return false if (Setting.issue_done_ratio != 'issue_field') || !RedmineChecklists.issue_done_ratio? || issue.checklists.reject(&:is_section).empty?
done_checklist = issue.checklists.reject(&:is_section).map { |c| c.is_done ? 1 : 0 }
done_ratio = (done_checklist.count(1) * 10) / done_checklist.count * 10
issue.update(done_ratio: done_ratio)
end
def self.old_format?(detail)
(detail.old_value.is_a?(String) && detail.old_value.match(/^\[[ |x]\] .+$/).present?) ||
(detail.value.is_a?(String) && detail.value.match(/^\[[ |x]\] .+$/).present?)
end
safe_attributes 'subject', 'position', 'issue_id', 'is_done', 'is_section'
def editable_by?(usr = User.current)
usr && (usr.allowed_to?(:edit_checklists, project) || (author == usr && usr.allowed_to?(:edit_own_checklists, project)))
end
def project
issue.project if issue
end
def info
"[#{is_done ? 'x' : ' '}] #{subject.strip}"
end
def add_to_list_bottom
return unless issue.checklists.select(&:persisted?).map(&:position).include?(self[position_column])
self[position_column] = bottom_position_in_list.to_i + 1
end
end
@@ -0,0 +1,127 @@
# This file is a part of Redmine Checklists (redmine_checklists) plugin,
# issue checklists management plugin for Redmine
#
# Copyright (C) 2011-2024 RedmineUP
# http://www.redmineup.com/
#
# redmine_checklists is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# redmine_checklists is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with redmine_checklists. If not, see <http://www.gnu.org/licenses/>.
class JournalChecklistHistory
def self.can_fixup?(journal_details)
return false if journal_details.journal.nil?
issue = journal_details.journal.journalized
return false unless issue.is_a?(Issue)
prev_journal_scope = issue.journals.order('id DESC')
prev_journal_scope = prev_journal_scope.where('id <> ?', journal_details.journal_id) if journal_details.journal_id
prev_journal = prev_journal_scope.first
return false unless prev_journal
return false if prev_journal.user_id != journal_details.journal.user_id
return false if Time.zone.now > prev_journal.created_on + 1.minute
prev_journal.details.all? { |x| x.prop_key == 'checklist' } &&
journal_details.journal.details.all? { |x| x.prop_key == 'checklist' } &&
journal_details.journal.notes.blank? &&
prev_journal.notes.blank? &&
prev_journal.details.select { |x| x.prop_key == 'checklist' }.size == 1
end
def self.fixup(journal_details)
issue = journal_details.journal.journalized
prev_journal_scope = issue.journals.order('id DESC')
prev_journal_scope = prev_journal_scope.where('id <> ?', journal_details.journal_id) if journal_details.journal_id
prev_journal = prev_journal_scope.first
checklist_details = prev_journal.details.find{ |x| x.prop_key == 'checklist'}
if new(checklist_details.old_value, journal_details.value).empty_diff?
prev_journal.destroy
else
checklist_details.update(value: journal_details.value)
journal_details.journal.destroy unless journal_details.journal.new_record? && journal_details.journal.details.any?{ |x| x.prop_key != 'checklist'}
end
end
def initialize(was, become)
@was = force_object(was)
@become = force_object(become)
@was_ids = @was.map(&:id)
@become_ids = @become.map(&:id)
@both_ids = @become_ids & @was_ids
end
def diff
{
:undone => undone,
:done => done
}
end
def empty_diff?
diff.all?{ |_,v| v.empty? }
end
def journal_details(opts = {})
JournalDetail.new(opts.merge({
:property => 'attr',
:prop_key => 'checklist',
:old_value => @was.map(&:to_h).to_json,
:value => @become.map(&:to_h).to_json
}))
end
private
def undone
@both_ids.map do |id|
was_is_done = was_by_id(id).is_done
become_is_done = become_by_id(id).is_done
if was_is_done != become_is_done && was_is_done
become_by_id(id)
else
nil
end
end.compact
end
def done
@both_ids.map do |id|
was_is_done = was_by_id(id).is_done
become_is_done = become_by_id(id).is_done
if was_is_done != become_is_done && become_is_done
become_by_id(id)
else
nil
end
end.compact
end
def was_by_id(id)
@was.find{ |x| x.id == id }
end
def become_by_id(id)
@become.find{ |x| x.id == id }
end
def force_object(unk)
if unk.is_a?(String)
json = JSON.parse(unk)
json = [json] unless json.is_a?(Array)
json.map{ |x| OpenStruct2.new(x.has_key?('checklist') ? x['checklist'] : x) }
else
unk.map{ |x| OpenStruct2.new(x.attributes) }
end
end
end
@@ -0,0 +1,11 @@
<li id="checklist_item_<%= checklist_item.id %>" class="<%= 'is-done-checklist-item' if checklist_item.is_done %> <%= 'checklist-section' if checklist_item.is_section %>">
<% unless checklist_item.is_section %>
<%= check_box_tag 'checklist_item', '', checklist_item.is_done,
disabled: !User.current.allowed_to?(:done_checklists, checklist_item.issue.project) && !User.current.allowed_to?(:edit_checklists, checklist_item.issue.project),
data_url: url_for({ controller: 'checklists', action: 'done', id: checklist_item.id }),
class: 'checklist-checkbox',
id: "checklist-checkbox-#{checklist_item.id}"
%>
<% end %>
<%= textilizable(checklist_item, :subject).gsub(/<\/?(p|h\d+|li|ul|hr \/)>/, '').strip.html_safe %>
</li>
@@ -0,0 +1,17 @@
$("#checklist_item_<%= @checklist_item.id %>").toggleClass('is-done-checklist-item');
$('#checklist_form .checklist-item#<%= @checklist_item.id %> input[type=checkbox]').trigger('click');
$('.issue .attributes table.progress').parent().html('<%= j(progress_bar(@checklist_item.issue.done_ratio, :width => '80px', :legend => "#{@checklist_item.issue.done_ratio}%")) %>');
$('#issue_done_ratio').val('<%= @checklist_item.issue.done_ratio %>');
var checkedCheckboxes = $('#checklist_items .checklist-checkbox:checkbox:checked');
if(localStorage.getItem("hide_closed_checklists") === '0' && checkedCheckboxes.length > 0){
$("#checklist_item_<%= @checklist_item.id %>").fadeOut(1000).hide(15);
$('#switch_link').text('<%= l("label_checklist_show_closed") %>' + '(' + checkedCheckboxes.length + ')');
}
if(checkedCheckboxes.length < 1 && localStorage.getItem("hide_closed_checklists") === '1'){
$('#switch_link').hide();
}
if(checkedCheckboxes.length > 0){
$('#switch_link').show();
}
@@ -0,0 +1,15 @@
api.array :checklists, api_meta(:total_count => @checklists.size) do
@checklists.each do |checklist|
api.checklist do
api.id checklist.id
api.issue_id checklist.issue_id
api.subject checklist.subject
api.is_done checklist.is_done
api.position checklist.position
api.is_section checklist.is_section
api.created_at checklist.created_at
api.updated_at checklist.updated_at
end
end
end
@@ -0,0 +1,11 @@
api.checklist do
api.id @checklist_item.id
api.issue_id @checklist_item.issue_id
api.subject @checklist_item.subject
api.is_done @checklist_item.is_done
api.position @checklist_item.position
api.is_section @checklist_item.is_section
api.created_at @checklist_item.created_at
api.updated_at @checklist_item.updated_at
end
@@ -0,0 +1,19 @@
<% if !@issue.blank? && @issue.checklists.any? && User.current.allowed_to?(:view_checklists, @project) %>
<hr />
<div id="checklist">
<div class="contextual">
<%= link_to l("label_checklist_hide_closed"), '#', id: 'switch_link' %>
</div>
<p><strong><%=l(:label_checklist_plural)%></strong></p>
<ul id="checklist_items">
<% @issue.checklists.each do |checklist_item| %>
<%= render :partial => 'checklists/checklist_item', :object => checklist_item %>
<% end %>
</ul>
</div>
<%= javascript_tag do %>
new Redmine.ChecklistToggle('<%= l("label_checklist_show_closed") %>', '<%= l("label_checklist_hide_closed") %>');
$("#checklist_items").checklist();
<% end %>
<% end %>
@@ -0,0 +1,26 @@
<span class="checklist-item <%= new_or_show(f) %> <%= 'checklist-section' if f.object.is_section %> existing" id="<%= f.object.id %>">
<% unless f.object.is_section %>
<span class="checklist-show-only checklist-checkbox"><%= f.check_box :is_done %></span>
<% end %>
<span class="checklist-show checklist-subject <%= done_css(f) %>">
<%= f.object.subject.to_s.strip.gsub('<', '&lt;').gsub('>', '&gt;').html_safe %>
</span>
<span class="checklist-edit checklist-new checklist-edit-box">
<%= text_field_tag nil, f.object.subject, class: 'edit-box' %>
<%= f.hidden_field :subject, class: 'checklist-subject-hidden' %>
</span>
<span class="checklist-edit-only checklist-edit-save-button"><%= submit_tag l(:button_save), type: 'button', class: 'item item-save small' %> </span>
<span class="checklist-edit-only checklist-edit-reset-button"><% concat l(:button_cancel) %> </span>
<span class="checklist-show-only checklist-remove"><%= link_to_remove_checklist_fields "", f, class: 'icon icon-del' %></span>
<%= f.hidden_field :position, class: 'checklist-item-position' %>
<%= f.hidden_field :is_section, class: 'checklist-item-is_section' %>
<%= f.hidden_field :id, class: 'checklist-item-id' %>
<span class="icon icon-add checklist-new-only save-new-by-button"></span>
<br>
</span>
@@ -0,0 +1,23 @@
<% if User.current.allowed_to?(:edit_checklists, @project, :global => true) %>
<div class="tabular">
<p id="checklist_form">
<label><%=l(:label_checklist_plural)%></label>
<% @issue.checklists.build if @issue.checklists.blank? || @issue.checklists.last.subject.present? %>
<%= fields_for @issue do |f| -%>
<span id="checklist_form_items" data-checklist-fields='<%= checklist_fields(f, :checklists) %>'>
<%= f.fields_for :checklists do |builder| %>
<%= render :partial => 'checklist_fields', :locals => {:f => builder, :checklist => @checklist} %>
<% end %>
</span>
<% end %>
</p>
</div>
<% end %>
<%= javascript_tag do %>
<% unless User.current.allowed_to?(:done_checklists, @project) %>
$("#checklist_items input").attr("disabled", true);
<% end %>
$("span#checklist_form_items").checklist();
<% end %>
@@ -0,0 +1,8 @@
<% checklist_tabs = [
{:name => 'general', :partial => 'settings/checklists/general', :label => :label_general}]
%>
<%= render_tabs checklist_tabs %>
<% html_title(l(:label_settings), l(:label_checklists)) -%>
@@ -0,0 +1,13 @@
<% if Setting.issue_done_ratio == "issue_field" %>
<p>
<label for="settings_issue_done_ratio"><%= l(:label_checklist_done_ratio) %></label>
<%= hidden_field_tag 'settings[issue_done_ratio]', 0, :id => nil %>
<%= check_box_tag 'settings[issue_done_ratio]', 1, @settings["issue_done_ratio"].to_i > 0 %>
</p>
<% end %>
<p>
<label for="settings_block_issue_closing"><%= l(:label_checklist_block_issue_closing) %></label>
<%= hidden_field_tag 'settings[block_issue_closing]', 0, :id => nil %>
<%= check_box_tag 'settings[block_issue_closing]', 1, @settings["block_issue_closing"].to_i > 0 %>
</p>