From 34982774fe80910236c27e7c5864fc68c1142229 Mon Sep 17 00:00:00 2001 From: Nik Il Date: Thu, 14 Oct 2021 10:32:52 +0300 Subject: [PATCH] Release 0.6.7 (#76) * added actions (#73) * added actions * add actions per channels * add files * add model * bump * fix: Gemfile & Gemfile.lock to reduce vulnerabilities (#75) The following vulnerabilities are fixed with an upgrade: - https://snyk.io/vuln/SNYK-RUBY-PUMA-1730572 * Bump addressable from 2.7.0 to 2.8.0 (#65) Bumps [addressable](https://github.com/sporkmonger/addressable) from 2.7.0 to 2.8.0. - [Release notes](https://github.com/sporkmonger/addressable/releases) - [Changelog](https://github.com/sporkmonger/addressable/blob/main/CHANGELOG.md) - [Commits](https://github.com/sporkmonger/addressable/compare/addressable-2.7.0...addressable-2.8.0) --- updated-dependencies: - dependency-name: addressable dependency-type: indirect ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * update readme Co-authored-by: t-kap <66311472+t-kap@users.noreply.github.com> Co-authored-by: Snyk bot Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- CHANGELOG.md | 5 +++++ Gemfile | 2 +- Gemfile.lock | 8 +++---- app/assets/javascripts/actions.coffee | 3 +++ app/assets/stylesheets/actions.scss | 3 +++ app/controllers/actions_controller.rb | 22 +++++++++++++++++++ app/helpers/actions_helper.rb | 2 ++ app/models/action.rb | 2 ++ app/views/actions/index.html.erb | 21 ++++++++++++++++++ app/views/layouts/application.html.erb | 1 + bot/bot.rb | 4 ++-- bot/commands.rb | 15 ++++++++----- config/initializers/version.rb | 2 +- config/routes.rb | 1 + db/migrate/20211008084226_create_actions.rb | 8 +++++++ .../20211008094835_add_problem_to_actions.rb | 6 +++++ .../20211011083709_add_channel_to_actions.rb | 5 +++++ db/schema.rb | 14 ++++++++---- test/controllers/actions_controller_test.rb | 7 ++++++ test/fixtures/actions.yml | 11 ++++++++++ test/models/action_test.rb | 7 ++++++ 21 files changed, 132 insertions(+), 17 deletions(-) create mode 100644 app/assets/javascripts/actions.coffee create mode 100644 app/assets/stylesheets/actions.scss create mode 100644 app/controllers/actions_controller.rb create mode 100644 app/helpers/actions_helper.rb create mode 100644 app/models/action.rb create mode 100644 app/views/actions/index.html.erb create mode 100644 db/migrate/20211008084226_create_actions.rb create mode 100644 db/migrate/20211008094835_add_problem_to_actions.rb create mode 100644 db/migrate/20211011083709_add_channel_to_actions.rb create mode 100644 test/controllers/actions_controller_test.rb create mode 100644 test/fixtures/actions.yml create mode 100644 test/models/action_test.rb diff --git a/CHANGELOG.md b/CHANGELOG.md index bf9310b..b541973 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,9 @@ # Changelog +## 0.6.7 +### Improvements +- Added actions table, bot will suggest "actions" on certain "problems" +- Bump addressable,puma,nio4r due to security issues + ## 0.6.6 ### Improvements - Switched to Ruby 2.7.3 diff --git a/Gemfile b/Gemfile index 214932c..90130f0 100644 --- a/Gemfile +++ b/Gemfile @@ -21,7 +21,7 @@ gem 'rails', '~> 5.2.4', '>= 5.2.4.5' # Use sqlite3 as the database for Active Record gem 'sqlite3' # Use Puma as the app server -gem 'puma', '~> 4.3.8' +gem 'puma', '~> 4.3.9' # Use SCSS for stylesheets gem 'sass-rails', '~> 5.1', '>= 5.1.0' # Use Uglifier as compressor for JavaScript assets diff --git a/Gemfile.lock b/Gemfile.lock index ca58a5c..263f9c2 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -42,7 +42,7 @@ GEM i18n (>= 0.7, < 2) minitest (~> 5.1) tzinfo (~> 1.1) - addressable (2.7.0) + addressable (2.8.0) public_suffix (>= 2.0.2, < 5.0) archive-zip (0.12.0) io-like (~> 0.3.0) @@ -138,13 +138,13 @@ GEM minitest (5.14.4) msgpack (1.4.2) multipart-post (2.1.1) - nio4r (2.5.7) + nio4r (2.5.8) nokogiri (1.11.5) mini_portile2 (~> 2.5.0) racc (~> 1.4) popper_js (1.16.0) public_suffix (4.0.6) - puma (4.3.8) + puma (4.3.10) nio4r (~> 2.0) racc (1.5.2) rack (2.2.3) @@ -273,7 +273,7 @@ DEPENDENCIES listen (>= 3.0.5, < 3.2) mail nokogiri (>= 1.11.4) - puma (~> 4.3.8) + puma (~> 4.3.9) rails (~> 5.2.4, >= 5.2.4.5) sass-rails (~> 5.1, >= 5.1.0) selenium-webdriver diff --git a/app/assets/javascripts/actions.coffee b/app/assets/javascripts/actions.coffee new file mode 100644 index 0000000..24f83d1 --- /dev/null +++ b/app/assets/javascripts/actions.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/stylesheets/actions.scss b/app/assets/stylesheets/actions.scss new file mode 100644 index 0000000..5ff9d7b --- /dev/null +++ b/app/assets/stylesheets/actions.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the actions controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/actions_controller.rb b/app/controllers/actions_controller.rb new file mode 100644 index 0000000..838e0fa --- /dev/null +++ b/app/controllers/actions_controller.rb @@ -0,0 +1,22 @@ +class ActionsController < ApplicationController + skip_before_action :verify_authenticity_token + def index + @actions = Action.all + respond_to do |format| + format.html # index.html.erb + format.xml { render xml: @actions } + format.json { render json: @actions } + end + end + + def create + action = Action.new(problem: params["problem"], action: params["aktion"], channel: params["channel"]) + action.save + end + + def destroy + Action.find(params[:id]).destroy + flash[:success] = "Record deleted" + redirect_to actions_url + end +end diff --git a/app/helpers/actions_helper.rb b/app/helpers/actions_helper.rb new file mode 100644 index 0000000..9611c69 --- /dev/null +++ b/app/helpers/actions_helper.rb @@ -0,0 +1,2 @@ +module ActionsHelper +end diff --git a/app/models/action.rb b/app/models/action.rb new file mode 100644 index 0000000..0e15737 --- /dev/null +++ b/app/models/action.rb @@ -0,0 +1,2 @@ +class Action < ApplicationRecord +end diff --git a/app/views/actions/index.html.erb b/app/views/actions/index.html.erb new file mode 100644 index 0000000..f026f9a --- /dev/null +++ b/app/views/actions/index.html.erb @@ -0,0 +1,21 @@ + + + + + + + + + + + + <% @actions.each do |action| %> + + + + + + + <% end %> +
IdProblemActionChannel
<%= action.id %><%= action.problem %><%= action.action %><%= action.channel %>
+ diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 9f00baf..16f95f0 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -17,6 +17,7 @@ Replied messages Users Answers + Actions diff --git a/bot/bot.rb b/bot/bot.rb index eb187a3..3564017 100644 --- a/bot/bot.rb +++ b/bot/bot.rb @@ -72,7 +72,7 @@ class Bot < SlackRubyBot::Bot Commands.unknown(client: client, data: data) end - scan(/.*/) do |client, data| - Commands.watch(client: client, data: data) + scan(/(.*)/) do |client, data, match| + Commands.watch(client: client, data: data, match: match) end end \ No newline at end of file diff --git a/bot/commands.rb b/bot/commands.rb index 93c077a..38c6e3c 100644 --- a/bot/commands.rb +++ b/bot/commands.rb @@ -292,7 +292,7 @@ def self.reply_in_not_working_time (client, reason, data, answer) message_processor.save_message(data: data) end - def self.watch(client:, data:) + def self.watch(client:, data:, match:) message_processor = MessageProcessor.new time = DateTime.strptime(data.ts, '%s') @@ -313,11 +313,10 @@ def self.watch(client:, data:) # don't reply on duty person messages return if data.user == duty.user.slack_user_id - # check if message written in channel if data.respond_to?(:thread_ts) == false message_processor.collectUserInfo(data: data) - reason = self.answer(time,duty) + reason = self.answer(time,duty, match, data) reply_in_not_working_time(client, reason, data, answer) unless reason.nil? return end @@ -325,7 +324,7 @@ def self.watch(client:, data:) # check if message written in thread without answer from bot message = Message.where('ts=? OR thread_ts=?',data.thread_ts,data.thread_ts).where(reply_counter: 1) if message.blank? - reason = self.answer(time,duty) + reason = self.answer(time,duty, match, data) reply_in_not_working_time(client, reason, data, answer) unless reason.nil? end rescue StandardError => e @@ -333,7 +332,7 @@ def self.watch(client:, data:) end end - def self.answer(time,duty) + def self.answer(time,duty, match, data) reason = nil if time.utc.strftime('%H%M%S%N') < duty.duty_from.utc.strftime('%H%M%S%N') or time.utc.strftime('%H%M%S%N') > duty.duty_to.utc.strftime('%H%M%S%N') @@ -355,6 +354,12 @@ def self.answer(time,duty) reason = I18n.t('commands.user.status.enabled.holidays') end + Action.where(channel: data.channel).each do |action| + Regexp.new(/#{action.problem}/i).match(match[0][0]) do |_| + reason = action.action + end + end + reason end diff --git a/config/initializers/version.rb b/config/initializers/version.rb index 8c6df4e..a46e3e9 100644 --- a/config/initializers/version.rb +++ b/config/initializers/version.rb @@ -1,5 +1,5 @@ module Whoisondutytoday class Application - VERSION = "0.6.6" + VERSION = "0.6.7" end end \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 0a3a560..32bff8f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -5,5 +5,6 @@ resources :messages resources :users resources :answers + resources :actions # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html end diff --git a/db/migrate/20211008084226_create_actions.rb b/db/migrate/20211008084226_create_actions.rb new file mode 100644 index 0000000..2cd34fa --- /dev/null +++ b/db/migrate/20211008084226_create_actions.rb @@ -0,0 +1,8 @@ +class CreateActions < ActiveRecord::Migration[5.2] + def change + create_table :actions do |t| + + t.timestamps + end + end +end diff --git a/db/migrate/20211008094835_add_problem_to_actions.rb b/db/migrate/20211008094835_add_problem_to_actions.rb new file mode 100644 index 0000000..f024981 --- /dev/null +++ b/db/migrate/20211008094835_add_problem_to_actions.rb @@ -0,0 +1,6 @@ +class AddProblemToActions < ActiveRecord::Migration[5.2] + def change + add_column :actions, :problem, :string + add_column :actions, :action, :string + end +end diff --git a/db/migrate/20211011083709_add_channel_to_actions.rb b/db/migrate/20211011083709_add_channel_to_actions.rb new file mode 100644 index 0000000..4b8f2d1 --- /dev/null +++ b/db/migrate/20211011083709_add_channel_to_actions.rb @@ -0,0 +1,5 @@ +class AddChannelToActions < ActiveRecord::Migration[5.2] + def change + add_column :actions, :channel, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index 3c658cf..bd98fe4 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,15 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2021_03_24_071457) do +ActiveRecord::Schema.define(version: 2021_10_11_083709) do + + create_table "actions", force: :cascade do |t| + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.string "problem" + t.string "action" + t.string "channel" + end create_table "answers", force: :cascade do |t| t.text "body" @@ -25,9 +33,7 @@ t.text "description" t.datetime "created_at", null: false t.datetime "updated_at", null: false - t.integer "channel_id" t.boolean "reminder_enabled" - t.index ["channel_id"], name: "index_channels_on_channel_id" t.index ["slack_channel_id"], name: "index_channels_on_slack_channel_id", unique: true end @@ -52,7 +58,7 @@ t.datetime "created_at", null: false t.datetime "updated_at", null: false t.integer "reply_counter" - t.integer "#" + t.integer "#" t.boolean "remind_needed" t.string "channel_id" end diff --git a/test/controllers/actions_controller_test.rb b/test/controllers/actions_controller_test.rb new file mode 100644 index 0000000..de1f2d6 --- /dev/null +++ b/test/controllers/actions_controller_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class ActionsControllerTest < ActionDispatch::IntegrationTest + # test "the truth" do + # assert true + # end +end diff --git a/test/fixtures/actions.yml b/test/fixtures/actions.yml new file mode 100644 index 0000000..80aed36 --- /dev/null +++ b/test/fixtures/actions.yml @@ -0,0 +1,11 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +# This model initially had no columns defined. If you add columns to the +# model remove the '{}' from the fixture names and add the columns immediately +# below each fixture, per the syntax in the comments below +# +one: {} +# column: value +# +two: {} +# column: value diff --git a/test/models/action_test.rb b/test/models/action_test.rb new file mode 100644 index 0000000..12116b7 --- /dev/null +++ b/test/models/action_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class ActionTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end