From 81992917555cef165acefaf8b68cee9bb59303a2 Mon Sep 17 00:00:00 2001 From: Connor Turland Date: Fri, 18 Mar 2016 12:05:58 +1100 Subject: [PATCH 1/5] everything but final wording/formatting --- Gemfile | 4 ++ Gemfile.lock | 12 ++++++ app/controllers/buckets_controller.rb | 2 + app/models/concerns/routing.rb | 10 +++++ app/models/event.rb | 27 ++++++++++++ app/models/events/bucket_created.rb | 10 +++++ app/models/events/bucket_funded.rb | 11 +++++ app/models/events/bucket_moved_to_funding.rb | 11 +++++ app/models/group.rb | 1 + app/models/webhook.rb | 13 ++++++ app/models/webhooks/slack/base.rb | 42 +++++++++++++++++++ app/models/webhooks/slack/bucket_created.rb | 26 ++++++++++++ app/models/webhooks/slack/bucket_funded.rb | 26 ++++++++++++ .../webhooks/slack/bucket_moved_to_funding.rb | 26 ++++++++++++ app/serializers/webhook_serializer.rb | 3 ++ app/services/webhook_service.rb | 18 ++++++++ db/migrate/20160317235420_create_webhooks.rb | 10 +++++ db/migrate/20160317235436_create_events.rb | 13 ++++++ db/schema.rb | 29 ++++++++++++- 19 files changed, 293 insertions(+), 1 deletion(-) create mode 100644 app/models/concerns/routing.rb create mode 100644 app/models/event.rb create mode 100644 app/models/events/bucket_created.rb create mode 100644 app/models/events/bucket_funded.rb create mode 100644 app/models/events/bucket_moved_to_funding.rb create mode 100644 app/models/webhook.rb create mode 100644 app/models/webhooks/slack/base.rb create mode 100644 app/models/webhooks/slack/bucket_created.rb create mode 100644 app/models/webhooks/slack/bucket_funded.rb create mode 100644 app/models/webhooks/slack/bucket_moved_to_funding.rb create mode 100644 app/serializers/webhook_serializer.rb create mode 100644 app/services/webhook_service.rb create mode 100644 db/migrate/20160317235420_create_webhooks.rb create mode 100644 db/migrate/20160317235436_create_events.rb diff --git a/Gemfile b/Gemfile index 1fb414c..0e8ec67 100644 --- a/Gemfile +++ b/Gemfile @@ -30,6 +30,10 @@ gem 'delayed_job_active_record' gem 'daemons' gem 'sinatra', :require => nil +#webhooks +gem 'httparty' +gem 'sequenced', '~> 2.0.0' + # error tracking gem 'airbrake' diff --git a/Gemfile.lock b/Gemfile.lock index dfa25cf..bc3fcc3 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -97,6 +97,9 @@ GEM activesupport (>= 4.1.0) hashie (3.4.2) highline (1.7.2) + httparty (0.13.7) + json (~> 1.8) + multi_xml (>= 0.5.2) i18n (0.7.0) json (1.8.3) loofah (2.0.2) @@ -117,6 +120,7 @@ GEM money (~> 6.5.0) railties (>= 3.0) multi_json (1.11.2) + multi_xml (0.5.5) net-scp (1.2.1) net-ssh (>= 2.6.5) net-sftp (2.1.2) @@ -208,6 +212,9 @@ GEM rspec-support (~> 3.3.0) rspec-support (3.3.0) ruby-graphviz (1.2.2) + sequenced (2.0.0) + activerecord (>= 3.0) + activesupport (>= 3.0) simplecov (0.10.0) docile (~> 1.1.0) json (~> 1.8) @@ -253,6 +260,7 @@ DEPENDENCIES factory_girl_rails faker foreigner + httparty money-rails omniauth pg @@ -268,7 +276,11 @@ DEPENDENCIES redcarpet responders (~> 2.0) rspec-rails (~> 3.0) + sequenced (~> 2.0.0) simplecov sinatra spring timecop + +BUNDLED WITH + 1.11.2 diff --git a/app/controllers/buckets_controller.rb b/app/controllers/buckets_controller.rb index db49467..7742910 100644 --- a/app/controllers/buckets_controller.rb +++ b/app/controllers/buckets_controller.rb @@ -17,6 +17,7 @@ def create if bucket.save # BucketService.send_bucket_created_emails(bucket: bucket) render json: [bucket] + Events::BucketCreated.publish!(bucket, current_user) else render json: { errors: bucket.errors.full_messages @@ -44,6 +45,7 @@ def open_for_funding bucket.open_for_funding(target: params[:target], funding_closes_at: params[:funding_closes_at]) # BucketService.send_bucket_live_emails(bucket: bucket) render json: [bucket] + Events::BucketMovedToFunding.publish!(bucket, current_user) end private diff --git a/app/models/concerns/routing.rb b/app/models/concerns/routing.rb new file mode 100644 index 0000000..2f8467b --- /dev/null +++ b/app/models/concerns/routing.rb @@ -0,0 +1,10 @@ +module Routing + extend ActiveSupport::Concern + include Rails.application.routes.url_helpers + + included do + def default_url_options + ActionMailer::Base.default_url_options + end + end +end diff --git a/app/models/event.rb b/app/models/event.rb new file mode 100644 index 0000000..7f34ced --- /dev/null +++ b/app/models/event.rb @@ -0,0 +1,27 @@ +class Event < ActiveRecord::Base + KINDS = %w[bucket_created bucket_moved_to_funding bucket_funded] + + belongs_to :eventable, polymorphic: true + belongs_to :group + belongs_to :user + + scope :sequenced, -> { where('sequence_id is not null').order('sequence_id asc') } + scope :chronologically, -> { order('created_at asc') } + + after_create :notify_webhooks!, if: :group + + validates_inclusion_of :kind, :in => KINDS + validates_presence_of :eventable + + acts_as_sequenced scope: :group_id, column: :sequence_id, skip: lambda {|e| e.group.nil? || e.group_id.nil? } + + def belongs_to?(this_user) + self.user_id == this_user.id + end + + def notify_webhooks! + self.group.webhooks.each { |webhook| WebhookService.publish! webhook: webhook, event: self } + end + handle_asynchronously :notify_webhooks! + +end diff --git a/app/models/events/bucket_created.rb b/app/models/events/bucket_created.rb new file mode 100644 index 0000000..8a46b12 --- /dev/null +++ b/app/models/events/bucket_created.rb @@ -0,0 +1,10 @@ +class Events::BucketCreated < Event + + def self.publish!(bucket, user) + create!(kind: 'bucket_created', + eventable: bucket, + group: bucket.group, + user: user) + end + +end diff --git a/app/models/events/bucket_funded.rb b/app/models/events/bucket_funded.rb new file mode 100644 index 0000000..c302703 --- /dev/null +++ b/app/models/events/bucket_funded.rb @@ -0,0 +1,11 @@ +class Events::BucketFunded < Event + + def self.publish!(bucket, user) + create!(kind: 'bucket_funded', + eventable: bucket, + group: bucket.group, + user: user) + end + +end + diff --git a/app/models/events/bucket_moved_to_funding.rb b/app/models/events/bucket_moved_to_funding.rb new file mode 100644 index 0000000..977feb4 --- /dev/null +++ b/app/models/events/bucket_moved_to_funding.rb @@ -0,0 +1,11 @@ +class Events::BucketMovedToFunding < Event + + def self.publish!(bucket, user) + create!(kind: 'bucket_moved_to_funding', + eventable: bucket, + group: bucket.group, + user: user) + end + +end + diff --git a/app/models/group.rb b/app/models/group.rb index 1585728..30cba4d 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -3,6 +3,7 @@ class Group < ActiveRecord::Base has_many :allocations, dependent: :destroy has_many :memberships has_many :members, through: :memberships, source: :member + has_many :webhooks, as: :hookable validates_presence_of :name diff --git a/app/models/webhook.rb b/app/models/webhook.rb new file mode 100644 index 0000000..4e20272 --- /dev/null +++ b/app/models/webhook.rb @@ -0,0 +1,13 @@ +class Webhook < ActiveRecord::Base + belongs_to :hookable, polymorphic: true + + validates :uri, presence: true + validates :hookable, presence: true + validates_inclusion_of :kind, in: %w[slack] + validates :event_types, length: { minimum: 1 } + + def headers + {} + end + +end diff --git a/app/models/webhooks/slack/base.rb b/app/models/webhooks/slack/base.rb new file mode 100644 index 0000000..b0700ee --- /dev/null +++ b/app/models/webhooks/slack/base.rb @@ -0,0 +1,42 @@ +Webhooks::Slack::Base = Struct.new(:event) do + include Routing + + def username + "Cobudget Bot" + end + + def icon_url + "https://pbs.twimg.com/profile_images/535182261553876992/MV2TWTgd.png" + end + + def text + "" + end + + def attachments + [{ + title: attachment_title, + text: attachment_text, + fields: attachment_fields, + fallback: attachment_fallback + }] + end + + alias :read_attribute_for_serialization :send + + private + + def view_group_on_cobudget(text = nil) + "<#{group_url(eventable.group)}|#{text || eventable.group.name}>" + end + + def eventable + @eventable ||= event.eventable + end + + def author + @author ||= eventable.author + end + +end + diff --git a/app/models/webhooks/slack/bucket_created.rb b/app/models/webhooks/slack/bucket_created.rb new file mode 100644 index 0000000..8477dd2 --- /dev/null +++ b/app/models/webhooks/slack/bucket_created.rb @@ -0,0 +1,26 @@ +class Webhooks::Slack::BucketCreated < Webhooks::Slack::Base + + def text + "#{eventable.user.name} created a new bucket: #{eventable.name}" + end + + def attachment_fallback + "" #{}"*#{eventable.name}*\n#{eventable.description}\n" + end + + def attachment_title + "" #proposal_link(eventable) + end + + def attachment_text + "" # "#{eventable.description}\n" + end + + def attachment_fields + [{ + title: "nothing", + value: "nothing" + }] #[motion_vote_field] + end + +end diff --git a/app/models/webhooks/slack/bucket_funded.rb b/app/models/webhooks/slack/bucket_funded.rb new file mode 100644 index 0000000..b9b35a7 --- /dev/null +++ b/app/models/webhooks/slack/bucket_funded.rb @@ -0,0 +1,26 @@ +class Webhooks::Slack::BucketFunded < Webhooks::Slack::Base + + def text + "#{eventable.name} got funded" + end + + def attachment_fallback + "" #{}"*#{eventable.name}*\n#{eventable.description}\n" + end + + def attachment_title + "" #proposal_link(eventable) + end + + def attachment_text + "" # "#{eventable.description}\n" + end + + def attachment_fields + [{ + title: "nothing", + value: "nothing" + }] #[motion_vote_field] + end + +end diff --git a/app/models/webhooks/slack/bucket_moved_to_funding.rb b/app/models/webhooks/slack/bucket_moved_to_funding.rb new file mode 100644 index 0000000..8733699 --- /dev/null +++ b/app/models/webhooks/slack/bucket_moved_to_funding.rb @@ -0,0 +1,26 @@ +class Webhooks::Slack::BucketMovedToFunding < Webhooks::Slack::Base + + def text + "#{eventable.name} moved to funding" + end + + def attachment_fallback + "" #{}"*#{eventable.name}*\n#{eventable.description}\n" + end + + def attachment_title + "" #proposal_link(eventable) + end + + def attachment_text + "" # "#{eventable.description}\n" + end + + def attachment_fields + [{ + title: "nothing", + value: "nothing" + }] #[motion_vote_field] + end + +end diff --git a/app/serializers/webhook_serializer.rb b/app/serializers/webhook_serializer.rb new file mode 100644 index 0000000..ed013ca --- /dev/null +++ b/app/serializers/webhook_serializer.rb @@ -0,0 +1,3 @@ +class WebhookSerializer < ActiveModel::Serializer + attributes :text, :username, :icon_url #, :attachments +end diff --git a/app/services/webhook_service.rb b/app/services/webhook_service.rb new file mode 100644 index 0000000..7a4361b --- /dev/null +++ b/app/services/webhook_service.rb @@ -0,0 +1,18 @@ +class WebhookService + + def self.publish!(webhook:, event:) + return false unless webhook.event_types.include? event.kind + HTTParty.post webhook.uri, body: payload_for(webhook, event), headers: webhook.headers + end + + private + + def self.payload_for(webhook, event) + WebhookSerializer.new(webhook_object_for(webhook, event), root: false).to_json + end + + def self.webhook_object_for(webhook, event) + "Webhooks::#{webhook.kind.classify}::#{event.kind.classify}".constantize.new(event) + end + +end diff --git a/db/migrate/20160317235420_create_webhooks.rb b/db/migrate/20160317235420_create_webhooks.rb new file mode 100644 index 0000000..0d1cf89 --- /dev/null +++ b/db/migrate/20160317235420_create_webhooks.rb @@ -0,0 +1,10 @@ +class CreateWebhooks < ActiveRecord::Migration + def change + create_table :webhooks do |t| + t.references :hookable, polymorphic: true, index: true + t.string :kind, null: false + t.string :uri, null: false + t.text :event_types, array: true, default: [] + end + end +end diff --git a/db/migrate/20160317235436_create_events.rb b/db/migrate/20160317235436_create_events.rb new file mode 100644 index 0000000..13d3282 --- /dev/null +++ b/db/migrate/20160317235436_create_events.rb @@ -0,0 +1,13 @@ +class CreateEvents < ActiveRecord::Migration + def change + create_table :events do |t| + t.string :kind, limit: 255 + t.references :eventable, polymorphic: true, index: true + t.references :user, index: true + t.references :group, index: true + t.integer :sequence_id, index: true, default: nil, null: true + t.timestamps + end + add_index :events, [:group_id, :sequence_id], unique: true + end +end diff --git a/db/schema.rb b/db/schema.rb index 87be69b..c31e32e 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20160311035750) do +ActiveRecord::Schema.define(version: 20160317235436) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -82,6 +82,23 @@ add_index "delayed_jobs", ["priority", "run_at"], name: "delayed_jobs_priority", using: :btree + create_table "events", force: :cascade do |t| + t.string "kind", limit: 255 + t.integer "eventable_id" + t.string "eventable_type" + t.integer "user_id" + t.integer "group_id" + t.integer "sequence_id" + t.datetime "created_at" + t.datetime "updated_at" + end + + add_index "events", ["eventable_type", "eventable_id"], name: "index_events_on_eventable_type_and_eventable_id", using: :btree + add_index "events", ["group_id", "sequence_id"], name: "index_events_on_group_id_and_sequence_id", unique: true, using: :btree + add_index "events", ["group_id"], name: "index_events_on_group_id", using: :btree + add_index "events", ["sequence_id"], name: "index_events_on_sequence_id", using: :btree + add_index "events", ["user_id"], name: "index_events_on_user_id", using: :btree + create_table "groups", force: :cascade do |t| t.string "name" t.datetime "created_at" @@ -131,4 +148,14 @@ add_index "users", ["email"], name: "index_users_on_email", unique: true, using: :btree add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true, using: :btree + create_table "webhooks", force: :cascade do |t| + t.integer "hookable_id" + t.string "hookable_type" + t.string "kind", null: false + t.string "uri", null: false + t.text "event_types", default: [], array: true + end + + add_index "webhooks", ["hookable_type", "hookable_id"], name: "index_webhooks_on_hookable_type_and_hookable_id", using: :btree + end From 66a1f18dbc05bde2a1452be8933bf31d508cbc32 Mon Sep 17 00:00:00 2001 From: Connor Turland Date: Fri, 18 Mar 2016 21:41:20 +1100 Subject: [PATCH 2/5] finish up styling and architecture --- app/controllers/buckets_controller.rb | 6 ++---- app/controllers/contributions_controller.rb | 1 + app/models/webhooks/slack/base.rb | 11 ++++++++++- app/models/webhooks/slack/bucket_created.rb | 13 +++++-------- app/models/webhooks/slack/bucket_funded.rb | 13 +++++-------- .../webhooks/slack/bucket_moved_to_funding.rb | 13 +++++-------- app/serializers/webhook_serializer.rb | 2 +- app/services/bucket_service.rb | 14 ++++++++++++++ 8 files changed, 43 insertions(+), 30 deletions(-) diff --git a/app/controllers/buckets_controller.rb b/app/controllers/buckets_controller.rb index 7742910..fac6576 100644 --- a/app/controllers/buckets_controller.rb +++ b/app/controllers/buckets_controller.rb @@ -15,9 +15,8 @@ def show def create bucket = Bucket.new(bucket_params_create) if bucket.save - # BucketService.send_bucket_created_emails(bucket: bucket) + BucketService.bucket_created(bucket: bucket, current_user: current_user) render json: [bucket] - Events::BucketCreated.publish!(bucket, current_user) else render json: { errors: bucket.errors.full_messages @@ -43,9 +42,8 @@ def update def open_for_funding bucket = Bucket.find(params[:id]) bucket.open_for_funding(target: params[:target], funding_closes_at: params[:funding_closes_at]) - # BucketService.send_bucket_live_emails(bucket: bucket) + BucketService.bucket_moved_to_funding(bucket: bucket, current_user: current_user) render json: [bucket] - Events::BucketMovedToFunding.publish!(bucket, current_user) end private diff --git a/app/controllers/contributions_controller.rb b/app/controllers/contributions_controller.rb index c84e736..9d5d6d9 100644 --- a/app/controllers/contributions_controller.rb +++ b/app/controllers/contributions_controller.rb @@ -20,6 +20,7 @@ def index def create contribution = Contribution.create(contribution_params) if contribution.valid? + BucketService.bucket_received_contribution(bucket: contribution.bucket, current_user: current_user) ContributionService.send_bucket_received_contribution_emails(contribution: contribution) render json: [contribution] else diff --git a/app/models/webhooks/slack/base.rb b/app/models/webhooks/slack/base.rb index b0700ee..0cb37c5 100644 --- a/app/models/webhooks/slack/base.rb +++ b/app/models/webhooks/slack/base.rb @@ -16,6 +16,7 @@ def text def attachments [{ title: attachment_title, + color: '#00B8D4', text: attachment_text, fields: attachment_fields, fallback: attachment_fallback @@ -27,7 +28,15 @@ def attachments private def view_group_on_cobudget(text = nil) - "<#{group_url(eventable.group)}|#{text || eventable.group.name}>" + "<#{url_root}groups/#{eventable.group.id}|#{text || eventable.group.name}>" + end + + def bucket_link(text = nil) + "<#{url_root}buckets/#{eventable.id}|#{text || eventable.name}>" + end + + def url_root + "http://localhost:9000/#/" end def eventable diff --git a/app/models/webhooks/slack/bucket_created.rb b/app/models/webhooks/slack/bucket_created.rb index 8477dd2..a1d8068 100644 --- a/app/models/webhooks/slack/bucket_created.rb +++ b/app/models/webhooks/slack/bucket_created.rb @@ -1,26 +1,23 @@ class Webhooks::Slack::BucketCreated < Webhooks::Slack::Base def text - "#{eventable.user.name} created a new bucket: #{eventable.name}" + "*#{eventable.user.name}* created a new idea in *#{view_group_on_cobudget}*" end def attachment_fallback - "" #{}"*#{eventable.name}*\n#{eventable.description}\n" + "*#{eventable.name}*\n#{eventable.description}\n" end def attachment_title - "" #proposal_link(eventable) + bucket_link end def attachment_text - "" # "#{eventable.description}\n" + "#{eventable.description}\n#{bucket_link('Discuss it on Cobudget')}" end def attachment_fields - [{ - title: "nothing", - value: "nothing" - }] #[motion_vote_field] + [] end end diff --git a/app/models/webhooks/slack/bucket_funded.rb b/app/models/webhooks/slack/bucket_funded.rb index b9b35a7..9d45ce1 100644 --- a/app/models/webhooks/slack/bucket_funded.rb +++ b/app/models/webhooks/slack/bucket_funded.rb @@ -1,26 +1,23 @@ class Webhooks::Slack::BucketFunded < Webhooks::Slack::Base def text - "#{eventable.name} got funded" + "#{eventable.group.currency_symbol}*#{eventable.target}* #{eventable.group.currency_code} bucket just got fully funded!" end def attachment_fallback - "" #{}"*#{eventable.name}*\n#{eventable.description}\n" + "*#{eventable.name}*\n#{eventable.description}\n" end def attachment_title - "" #proposal_link(eventable) + bucket_link end def attachment_text - "" # "#{eventable.description}\n" + "#{eventable.description}\n#{bucket_link('View it on Cobudget')}" end def attachment_fields - [{ - title: "nothing", - value: "nothing" - }] #[motion_vote_field] + [] end end diff --git a/app/models/webhooks/slack/bucket_moved_to_funding.rb b/app/models/webhooks/slack/bucket_moved_to_funding.rb index 8733699..4f7b93e 100644 --- a/app/models/webhooks/slack/bucket_moved_to_funding.rb +++ b/app/models/webhooks/slack/bucket_moved_to_funding.rb @@ -1,26 +1,23 @@ class Webhooks::Slack::BucketMovedToFunding < Webhooks::Slack::Base def text - "#{eventable.name} moved to funding" + "Bucket with #{eventable.group.currency_symbol}#{eventable.target} #{eventable.group.currency_code} target is now open for funding" end def attachment_fallback - "" #{}"*#{eventable.name}*\n#{eventable.description}\n" + "*#{eventable.name}*\n#{eventable.description}\n" end def attachment_title - "" #proposal_link(eventable) + bucket_link end def attachment_text - "" # "#{eventable.description}\n" + "#{eventable.description}\n#{bucket_link('Comment or Fund it on Cobudget')}" end def attachment_fields - [{ - title: "nothing", - value: "nothing" - }] #[motion_vote_field] + [] end end diff --git a/app/serializers/webhook_serializer.rb b/app/serializers/webhook_serializer.rb index ed013ca..f132a59 100644 --- a/app/serializers/webhook_serializer.rb +++ b/app/serializers/webhook_serializer.rb @@ -1,3 +1,3 @@ class WebhookSerializer < ActiveModel::Serializer - attributes :text, :username, :icon_url #, :attachments + attributes :text, :username, :icon_url, :attachments end diff --git a/app/services/bucket_service.rb b/app/services/bucket_service.rb index bf69eb4..6e8687b 100644 --- a/app/services/bucket_service.rb +++ b/app/services/bucket_service.rb @@ -1,4 +1,18 @@ class BucketService + def self.bucket_created(bucket: ,current_user: ) + Events::BucketCreated.publish!(bucket, current_user) + end + + def self.bucket_moved_to_funding(bucket: , current_user: ) + Events::BucketMovedToFunding.publish!(bucket, current_user) + end + + def self.bucket_received_contribution(bucket: , current_user: ) + if bucket.funded? + Events::BucketFunded.publish!(bucket, current_user) + end + end + # given the current email settings, its likely that this will never be called def self.send_bucket_created_emails(bucket: ) memberships = bucket.group.memberships.active.where.not(member_id: bucket.user_id) From e67df826bed8a06c5bfa8db1de6b9cc096dab2c1 Mon Sep 17 00:00:00 2001 From: Connor Turland Date: Fri, 18 Mar 2016 21:45:20 +1100 Subject: [PATCH 3/5] remove routing, unneeded --- app/models/concerns/routing.rb | 10 ---------- app/models/webhooks/slack/base.rb | 1 - 2 files changed, 11 deletions(-) delete mode 100644 app/models/concerns/routing.rb diff --git a/app/models/concerns/routing.rb b/app/models/concerns/routing.rb deleted file mode 100644 index 2f8467b..0000000 --- a/app/models/concerns/routing.rb +++ /dev/null @@ -1,10 +0,0 @@ -module Routing - extend ActiveSupport::Concern - include Rails.application.routes.url_helpers - - included do - def default_url_options - ActionMailer::Base.default_url_options - end - end -end diff --git a/app/models/webhooks/slack/base.rb b/app/models/webhooks/slack/base.rb index 0cb37c5..799fe29 100644 --- a/app/models/webhooks/slack/base.rb +++ b/app/models/webhooks/slack/base.rb @@ -1,5 +1,4 @@ Webhooks::Slack::Base = Struct.new(:event) do - include Routing def username "Cobudget Bot" From d0be6e9944062488b117f9b8100f15e749a625f9 Mon Sep 17 00:00:00 2001 From: Connor Turland Date: Sun, 27 Mar 2016 12:41:37 -0700 Subject: [PATCH 4/5] remove sequenced --- Gemfile | 1 - app/models/event.rb | 3 --- db/migrate/20160317235436_create_events.rb | 2 -- 3 files changed, 6 deletions(-) diff --git a/Gemfile b/Gemfile index 0e8ec67..429b827 100644 --- a/Gemfile +++ b/Gemfile @@ -32,7 +32,6 @@ gem 'sinatra', :require => nil #webhooks gem 'httparty' -gem 'sequenced', '~> 2.0.0' # error tracking gem 'airbrake' diff --git a/app/models/event.rb b/app/models/event.rb index 7f34ced..88d87fc 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -5,7 +5,6 @@ class Event < ActiveRecord::Base belongs_to :group belongs_to :user - scope :sequenced, -> { where('sequence_id is not null').order('sequence_id asc') } scope :chronologically, -> { order('created_at asc') } after_create :notify_webhooks!, if: :group @@ -13,8 +12,6 @@ class Event < ActiveRecord::Base validates_inclusion_of :kind, :in => KINDS validates_presence_of :eventable - acts_as_sequenced scope: :group_id, column: :sequence_id, skip: lambda {|e| e.group.nil? || e.group_id.nil? } - def belongs_to?(this_user) self.user_id == this_user.id end diff --git a/db/migrate/20160317235436_create_events.rb b/db/migrate/20160317235436_create_events.rb index 13d3282..82b8e71 100644 --- a/db/migrate/20160317235436_create_events.rb +++ b/db/migrate/20160317235436_create_events.rb @@ -5,9 +5,7 @@ def change t.references :eventable, polymorphic: true, index: true t.references :user, index: true t.references :group, index: true - t.integer :sequence_id, index: true, default: nil, null: true t.timestamps end - add_index :events, [:group_id, :sequence_id], unique: true end end From 55a1ab0f92cb2ea1d24936086226f53f120ed6be Mon Sep 17 00:00:00 2001 From: Connor Turland Date: Sun, 27 Mar 2016 13:02:18 -0700 Subject: [PATCH 5/5] move appropriate things to env vars --- Gemfile.lock | 4 ---- app/models/webhooks/slack/base.rb | 4 ++-- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index bc3fcc3..80618c7 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -212,9 +212,6 @@ GEM rspec-support (~> 3.3.0) rspec-support (3.3.0) ruby-graphviz (1.2.2) - sequenced (2.0.0) - activerecord (>= 3.0) - activesupport (>= 3.0) simplecov (0.10.0) docile (~> 1.1.0) json (~> 1.8) @@ -276,7 +273,6 @@ DEPENDENCIES redcarpet responders (~> 2.0) rspec-rails (~> 3.0) - sequenced (~> 2.0.0) simplecov sinatra spring diff --git a/app/models/webhooks/slack/base.rb b/app/models/webhooks/slack/base.rb index 799fe29..64c4e2f 100644 --- a/app/models/webhooks/slack/base.rb +++ b/app/models/webhooks/slack/base.rb @@ -5,7 +5,7 @@ def username end def icon_url - "https://pbs.twimg.com/profile_images/535182261553876992/MV2TWTgd.png" + ENV["SLACK_ICON_URL"] end def text @@ -35,7 +35,7 @@ def bucket_link(text = nil) end def url_root - "http://localhost:9000/#/" + ENV["ROOT_URL"] + "/#/" end def eventable