Skip to content

Commit

Permalink
Merge pull request #31 from centosadmin/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
constXife authored Mar 19, 2018
2 parents 6d6876e + 03c229d commit 7cdab7a
Show file tree
Hide file tree
Showing 10 changed files with 139 additions and 4 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# 0.2.1

* Copying issues only from active project
* Plugin association removed from settings
* Add warning in plugin settings page
* Add Russian readme

# 0.2.0

* Fix UTC-related issues
Expand Down
101 changes: 101 additions & 0 deletions README-RU.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# Redmine Recurring Tasks

[![Build Status](https://travis-ci.org/centosadmin/redmine_recurring_tasks.svg?branch=master)](https://travis-ci.org/centosadmin/redmine_recurring_tasks)

Плагин для запланированного создания задач с шаблонов

# Установка

* Ruby 2.2+
* Redmine 3.3+
* Стандартная установка плагина:

```
cd {REDMINE_ROOT}
git clone https://github.com/centosadmin/redmine_recurring_tasks.git plugins/redmine_recurring_tasks
bundle install
bundle exec rake redmine:plugins:migrate RAILS_ENV=production
```

# Использование

Чтобы воспользоваться плагином, вам необходимо включить его в настройках модулей проекта. Далее, переходите на страницу задачи
и вы увидите секцию "Расписание" с ссылкой "Добавить".

# Запуск

Чтобы создать запланированные задачи, вам необходимо запустить rake задачу

```
cd {REDMINE_ROOT}
bundle exec rake redmine_recurring_tasks:exec
```

И чтобы запуск происходил периодически, можно воспользоваться cron или другим планировщиком.

## Планировщики

### Sidekiq-cron

Чтобы запустить sidekiq-cron:

- Установить redis (*yum install redis*)
- Установить плагин [redmine_sidekiq](https://github.com/ogom/redmine_sidekiq)
- Создать файл инициализации. Для примера

```
# /opt/redmine/config/initializers/zz-cron.rb
class RecurringTaskWorker
include Sidekiq::Worker
def perform
checker = RedmineRecurringTasks::IssueChecker.new(Setting.plugin_redmine_recurring_tasks)
checker.call
end
end
cron_job_array = [
{
'name' => 'Weekly schedule worker',
'class' => 'RecurringTaskWorker',
'cron' => '*/5 * * * *'
}
]
Sidekiq::Cron::Job.load_from_array cron_job_array
```

### Whenever

```
cd {REDMINE_ROOT}
whenever --update-crontab --load-file plugins/redmine_recurring_tasks/config/schedule.rb
```

### Cron manual

```
$ crontab -e
```

Добавляем строку с cron job

```
*/5 * * * * /bin/bash -l -c 'cd /home/redmine && RAILS_ENV=production bundle exec rake redmine_recurring_tasks:exec
```

# Настройки

Если у вас есть какие-то другие плагины, которые по каким-то причинам не копируются в задачи, то
вы можете указать связи для копирования в настройках плагина. Вниамени! Эти опции могут сломать работу плагина.

Для примера, если вы используете *Redmine checklists*, вы можете выделить "checklists" в настройках.

# Лицензия

[MIT](https://github.com/centosadmin/redmine_recurring_tasks/blob/master/LICENSE)

# Автор плагина

Плагин разработан [Southbridge](https://southbridge.io)
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

[![Build Status](https://travis-ci.org/centosadmin/redmine_recurring_tasks.svg?branch=master)](https://travis-ci.org/centosadmin/redmine_recurring_tasks)

[Русская версия](README-RU.md)

Plugin for creating scheduled tasks from templates.

# Installation
Expand Down
2 changes: 2 additions & 0 deletions app/models/recurring_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ def self.schedules(current_time = Time.now)

# @return [Issue] copied issue
def copy_issue(associations = nil)
return if issue.project.archived? || issue.project.closed?

new_issue = issue.deep_clone include: associations
new_issue.init_journal(issue.author)
new_author =
Expand Down
3 changes: 2 additions & 1 deletion app/views/settings/_redmine_recurring_tasks.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
<%= label_tag 'settings[associations]', l(:settings_associations) %>
<%= select_tag 'settings[associations]',
options_for_select(RedmineRecurringTasks.issue_associations, @settings[:associations]),
{multiple: true, size: 20, style: 'width: 50%;'} %>
{ multiple: true, size: 20, style: 'width: 50%;' } %>
<p class="notice"><%= l(:settings_associations_warning) %></p>
</p>
<p>
<%= button_tag l(:button_reset), type: :button, onClick: '$("#settings_associations option:selected").prop("selected", false);' %>
Expand Down
1 change: 1 addition & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ en:
label_edit_schedule: Edit schedule

settings_associations: Issue associations to copy
settings_associations_warning: Warning! Incorrect settings may break plugin work. In case of problem try to turn off all options.
settings_use_anonymous_user: Use anonymous user while copying issues
3 changes: 2 additions & 1 deletion config/locales/ru.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ ru:
permission_view_schedule: Просмотр расписания
permission_manage_schedule: Управление расписанием

settings_associations: Связи Задачи для копирования
settings_associations: Связи для копирования
settings_associations_warning: Внимание! Некорректные настройки могут нарушить корректную работу плагина. При возникновении проблем попробуйте снять все опции.
settings_use_anonymous_user: Использовать анонимного пользователя для создания задач

activerecord:
Expand Down
2 changes: 1 addition & 1 deletion init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
name 'Redmine Recurring Tasks'
author 'Southbridge'
description 'Plugin for creating scheduled tasks from template'
version '0.2.0'
version '0.2.1'
url 'https://github.com/centosadmin/redmine_recurring_tasks'
author_url 'https://github.com/centosadmin'

Expand Down
2 changes: 1 addition & 1 deletion lib/redmine_recurring_tasks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ def self.issue_associations
default_associations = ['parent', 'project', 'tracker', 'status', 'author', 'assigned_to', 'fixed_version',
'priority', 'category', 'journals', 'visible_journals', 'time_entries', 'changesets',
'relations_from', 'relations_to', 'attachments', 'custom_values', 'watchers',
'watcher_users', 'weekly_schedule']
'watcher_users', 'recurring_task']

Issue.reflections.keys.dup - default_associations
end
Expand Down
20 changes: 20 additions & 0 deletions test/unit/recurring_task_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,14 @@ def test_copy_has_anonymous_author_when_anonymous_user_used
assert default_schedule.copy_issue.author_id == User.anonymous.id
end

def test_copy_when_project_is_closed
assert closed_project_schedule.copy_issue.nil?
end

def test_copy_when_project_is_archived
assert archived_project_schedule.copy_issue.nil?
end

def test_execute
default_schedule.execute
assert default_schedule.last_try_at.present?
Expand Down Expand Up @@ -184,4 +192,16 @@ def default_issue
def default_schedule
@default_schedule ||= RecurringTask.create(issue: default_issue, tracker_id: default_issue.tracker_id)
end

def closed_project_schedule
project = Project.new
project.status = Project::STATUS_CLOSED
RecurringTask.new(issue: Issue.new(project: project))
end

def archived_project_schedule
project = Project.new
project.status = Project::STATUS_ARCHIVED
RecurringTask.new(issue: Issue.new(project: project))
end
end

0 comments on commit 7cdab7a

Please sign in to comment.