Skip to content

Commit

Permalink
Release 0.6.7 (#76)
Browse files Browse the repository at this point in the history
* 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](sporkmonger/addressable@addressable-2.7.0...addressable-2.8.0)

---
updated-dependencies:
- dependency-name: addressable
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <[email protected]>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* update readme

Co-authored-by: t-kap <[email protected]>
Co-authored-by: Snyk bot <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
  • Loading branch information
4 people authored Oct 14, 2021
1 parent f95abd7 commit 3498277
Show file tree
Hide file tree
Showing 21 changed files with 132 additions and 17 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions app/assets/javascripts/actions.coffee
Original file line number Diff line number Diff line change
@@ -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/
3 changes: 3 additions & 0 deletions app/assets/stylesheets/actions.scss
Original file line number Diff line number Diff line change
@@ -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/
22 changes: 22 additions & 0 deletions app/controllers/actions_controller.rb
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions app/helpers/actions_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module ActionsHelper
end
2 changes: 2 additions & 0 deletions app/models/action.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class Action < ApplicationRecord
end
21 changes: 21 additions & 0 deletions app/views/actions/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

<table class="table">
<thead class="thead-dark">
<tr>
<th scope="col">Id</th>
<th scope="col">Problem</th>
<th scope="col">Action</th>
<th scope="col">Channel</th>
</tr>
</thead>

<% @actions.each do |action| %>
<tr>
<td><%= action.id %></td>
<td><%= action.problem %></td>
<td><%= action.action %></td>
<td><%= action.channel %></td>
</tr>
<% end %>
</table>

1 change: 1 addition & 0 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<a class="nav-item nav-link" href="/messages">Replied messages </a>
<a class="nav-item nav-link" href="/users">Users</a>
<a class="nav-item nav-link" href="/answers">Answers</a>
<a class="nav-item nav-link" href="/actions">Actions</a>
</div>
</div>
</nav>
Expand Down
4 changes: 2 additions & 2 deletions bot/bot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
15 changes: 10 additions & 5 deletions bot/commands.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand All @@ -313,27 +313,26 @@ 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

# 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
print e
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')
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion config/initializers/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Whoisondutytoday
class Application
VERSION = "0.6.6"
VERSION = "0.6.7"
end
end
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 8 additions & 0 deletions db/migrate/20211008084226_create_actions.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class CreateActions < ActiveRecord::Migration[5.2]
def change
create_table :actions do |t|

t.timestamps
end
end
end
6 changes: 6 additions & 0 deletions db/migrate/20211008094835_add_problem_to_actions.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class AddProblemToActions < ActiveRecord::Migration[5.2]
def change
add_column :actions, :problem, :string
add_column :actions, :action, :string
end
end
5 changes: 5 additions & 0 deletions db/migrate/20211011083709_add_channel_to_actions.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddChannelToActions < ActiveRecord::Migration[5.2]
def change
add_column :actions, :channel, :string
end
end
14 changes: 10 additions & 4 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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

Expand All @@ -52,7 +58,7 @@
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "reply_counter"
t.integer "#<ActiveRecord::ConnectionAdapters::SQLite3::TableDefinition:0x0000563524093008>"
t.integer "#<ActiveRecord::ConnectionAdapters::SQLite3::TableDefinition:0x0000555cae7831a0>"
t.boolean "remind_needed"
t.string "channel_id"
end
Expand Down
7 changes: 7 additions & 0 deletions test/controllers/actions_controller_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'test_helper'

class ActionsControllerTest < ActionDispatch::IntegrationTest
# test "the truth" do
# assert true
# end
end
11 changes: 11 additions & 0 deletions test/fixtures/actions.yml
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions test/models/action_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'test_helper'

class ActionTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end

0 comments on commit 3498277

Please sign in to comment.