-
Notifications
You must be signed in to change notification settings - Fork 200
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
polymorphic change, subscription, slack integration models
- Loading branch information
Showing
45 changed files
with
772 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// Place all the behaviors and hooks related to the matching controller here. | ||
// All this logic will automatically be available in application.js. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// Place all the behaviors and hooks related to the matching controller here. | ||
// All this logic will automatically be available in application.js. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// Place all the styles related to the integrations controller here. | ||
// They will automatically be included in application.css. | ||
// You can use Sass (SCSS) here: http://sass-lang.com/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// Place all the styles related to the slack_integrations controller here. | ||
// They will automatically be included in application.css. | ||
// You can use Sass (SCSS) here: http://sass-lang.com/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
class IntegrationsController < ApplicationController | ||
def index | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
class SlackIntegrationsController < ApplicationController | ||
before_action :set_slack_integration, only: [:show, :edit, :update, :destroy] | ||
|
||
# GET /slack_integrations | ||
def index | ||
@slack_integrations = SlackIntegration.all | ||
end | ||
|
||
# GET /slack_integrations/1 | ||
def show | ||
end | ||
|
||
# GET /slack_integrations/new | ||
def new | ||
@slack_integration = SlackIntegration.new | ||
end | ||
|
||
# GET /slack_integrations/1/edit | ||
def edit | ||
end | ||
|
||
# POST /slack_integrations | ||
def create | ||
@slack_integration = SlackIntegration.new(slack_integration_params) | ||
|
||
if @slack_integration.save | ||
redirect_to @slack_integration, notice: 'Slack integration was successfully created.' | ||
else | ||
render :new | ||
end | ||
end | ||
|
||
# PATCH/PUT /slack_integrations/1 | ||
def update | ||
if @slack_integration.update(slack_integration_params) | ||
redirect_to @slack_integration, notice: 'Slack integration was successfully updated.' | ||
else | ||
render :edit | ||
end | ||
end | ||
|
||
# DELETE /slack_integrations/1 | ||
def destroy | ||
@slack_integration.destroy | ||
redirect_to slack_integrations_url, notice: 'Slack integration was successfully destroyed.' | ||
end | ||
|
||
private | ||
# Use callbacks to share common setup or constraints between actions. | ||
def set_slack_integration | ||
@slack_integration = SlackIntegration.find(params[:id]) | ||
end | ||
|
||
# Only allow a trusted parameter "white list" through. | ||
def slack_integration_params | ||
params.require(:slack_integration).permit(:channel, :webhook_url) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module IntegrationsHelper | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module SlackIntegrationsHelper | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
class Change < ActiveRecord::Base | ||
belongs_to :before, polymorphic: true | ||
belongs_to :after, polymorphic: true | ||
|
||
validate :correct_ordering | ||
def correct_ordering | ||
# delegate order checking to the attached models | ||
before.created_at < after.created_at | ||
end | ||
|
||
def notify! | ||
Subscriptions.where(watching: self.after).map do |subscription| | ||
subscription.notify!(change) | ||
end | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class PageSnapshot < ActiveRecord::Base | ||
belongs_to :page | ||
validates :page, presence: true | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
class SlackIntegration < ActiveRecord::Base | ||
|
||
def subscriptions | ||
Subscription.where(watcher: self) | ||
end | ||
|
||
def watching | ||
subscriptions.map(&:watching) | ||
end | ||
|
||
def subscribe(watchable) | ||
# TODO: extract this. also in User | ||
Subscription.where(watcher: self, watching: watchable).first_or_create do |subscription| | ||
puts "#{self} subscribed to #{watchable}" | ||
end | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class Subscription < ActiveRecord::Base | ||
belongs_to :watcher, polymorphic: true | ||
belongs_to :watching, polymorphic: true | ||
|
||
def notify!(change) | ||
Notification.send(subscription: self, change: change) | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<h1>Integrations#index</h1> | ||
<p>Find me in app/views/integrations/index.html.erb</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<%= simple_form_for(@slack_integration) do |f| %> | ||
<%= f.error_notification %> | ||
|
||
<div class="form-inputs"> | ||
<%= f.input :channel %> | ||
<%= f.input :webhook_url %> | ||
</div> | ||
|
||
<div class="form-actions"> | ||
<%= f.button :submit %> | ||
</div> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<h1>Editing Slack Integration</h1> | ||
|
||
<%= render 'form' %> | ||
|
||
<%= link_to 'Show', @slack_integration %> | | ||
<%= link_to 'Back', slack_integrations_path %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<p id="notice"><%= notice %></p> | ||
|
||
<h1>Listing Slack Integrations</h1> | ||
|
||
<table> | ||
<thead> | ||
<tr> | ||
<th>Channel</th> | ||
<th>Webhook url</th> | ||
<th colspan="3"></th> | ||
</tr> | ||
</thead> | ||
|
||
<tbody> | ||
<% @slack_integrations.each do |slack_integration| %> | ||
<tr> | ||
<td><%= slack_integration.channel %></td> | ||
<td><%= slack_integration.webhook_url %></td> | ||
<td><%= link_to 'Show', slack_integration %></td> | ||
<td><%= link_to 'Edit', edit_slack_integration_path(slack_integration) %></td> | ||
<td><%= link_to 'Destroy', slack_integration, method: :delete, data: { confirm: 'Are you sure?' } %></td> | ||
</tr> | ||
<% end %> | ||
</tbody> | ||
</table> | ||
|
||
<br> | ||
|
||
<%= link_to 'New Slack integration', new_slack_integration_path %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<h1>New Slack Integration</h1> | ||
|
||
<%= render 'form' %> | ||
|
||
<%= link_to 'Back', slack_integrations_path %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<p id="notice"><%= notice %></p> | ||
|
||
<p> | ||
<strong>Channel:</strong> | ||
<%= @slack_integration.channel %> | ||
</p> | ||
|
||
<p> | ||
<strong>Webhook url:</strong> | ||
<%= @slack_integration.webhook_url %> | ||
</p> | ||
|
||
<%= link_to 'Edit', edit_slack_integration_path(@slack_integration) %> | | ||
<%= link_to 'Back', slack_integrations_path %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
class CreateChanges < ActiveRecord::Migration | ||
def change | ||
create_table :changes do |t| | ||
t.integer :prev_id | ||
t.string :prev_type | ||
t.integer :next_id | ||
t.string :next_type | ||
t.text :summary | ||
|
||
t.timestamps null: false | ||
end | ||
add_index :changes, :prev_id | ||
add_index :changes, :prev_type | ||
add_index :changes, :next_id | ||
add_index :changes, :next_type | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
class CreateSlackIntegrations < ActiveRecord::Migration | ||
def change | ||
create_table :slack_integrations do |t| | ||
t.string :channel | ||
t.text :webhook_url | ||
|
||
t.timestamps null: false | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
class CreateSubscriptions < ActiveRecord::Migration | ||
def change | ||
create_table :subscriptions do |t| | ||
t.integer :watcher_id | ||
t.string :watcher_type | ||
t.integer :watching_id | ||
t.string :watching_type | ||
|
||
t.timestamps null: false | ||
end | ||
add_index :subscriptions, :watcher_id | ||
add_index :subscriptions, :watcher_type | ||
add_index :subscriptions, :watching_id | ||
add_index :subscriptions, :watching_type | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class CreatePageSnapshots < ActiveRecord::Migration | ||
def change | ||
create_table :page_snapshots do |t| | ||
t.integer :page_id | ||
t.text :s3_url | ||
|
||
t.timestamps null: false | ||
end | ||
add_index :page_snapshots, :page_id | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class RenameColsOnChanges < ActiveRecord::Migration | ||
def change | ||
rename_column :changes, :prev_id, :before_id | ||
rename_column :changes, :prev_type, :before_type | ||
|
||
rename_column :changes, :next_id, :after_id | ||
rename_column :changes, :next_type, :after_type | ||
end | ||
end |
Oops, something went wrong.