Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat integrations #102

Merged
merged 24 commits into from
Jul 13, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
d3118ed
initial structure for integrations code
Chocksy Feb 24, 2016
b6d475e
add integrations table and write the base for intercom integration wi…
Chocksy Apr 13, 2016
f8d7c41
add integration model
Chocksy Apr 15, 2016
93bd2de
add integrations base code
Chocksy Apr 15, 2016
124d813
code specs for base_driver and integration delegation
Chocksy Apr 15, 2016
0b88973
add the integrations yml file for storing app keys and secrets
Chocksy Apr 15, 2016
048b0a6
add configuration for omniauth to the integrations
Chocksy Apr 16, 2016
2ea5cb6
remove unneded helpers and clen auth controllers
Chocksy Apr 18, 2016
018e224
add the new auth_controller for creating integrations
Chocksy Apr 18, 2016
68067b4
add integration configuration setting
Chocksy Apr 19, 2016
1314590
add authentication and connect base methods
Chocksy Apr 19, 2016
84bfb24
add the connect method config assignment
Chocksy Jun 2, 2016
bedf7ce
create account with github and save integrations to db
hyperionel Jun 9, 2016
962f1d2
use env variable in the integrations.yml
hyperionel Jun 9, 2016
6fd523c
made changes to allow for integration configuration to be saved
Chocksy Jun 10, 2016
a655582
add rest-client for api calls
Chocksy Jun 10, 2016
7ba1edc
added omniauth-intercom gem
hyperionel Jun 13, 2016
f8a1ecf
some progress on the github integration
hyperionel Jun 14, 2016
f3d7a56
some specs for the auth_controller
hyperionel Jun 14, 2016
a4ac1ff
functionality for adding applications from the provider
hyperionel Jun 16, 2016
2aac817
use hstore as the datatype for the configuration column
hyperionel Jun 18, 2016
5af2abf
some changes to the methods we use to get the applications from the p…
hyperionel Jun 18, 2016
6dd8810
functionality for creating a github issue
hyperionel Jun 20, 2016
40bebc4
changed the name for the environment variables
hyperionel Jun 20, 2016
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ gem 'kaminari'
gem 'rails_warden'
gem 'warden_omniauth'
gem 'omniauth-github'
gem 'omniauth-intercom'
gem 'cancancan', '~> 1.10'
# Add sidekiq for background jobs
gem 'sidekiq'
Expand All @@ -80,14 +81,16 @@ gem 'groupdate'
#gem for charts
gem 'chartkick'

# add a rest client to call apis
gem 'rest-client'

group :development do
gem 'better_errors'
gem 'binding_of_caller'
# gem 'spring'
# gem 'spring-commands-rspec'
end

group :test do
gem 'webmock'
gem 'database_cleaner'
gem 'capybara'
gem 'timecop'
Expand Down
34 changes: 27 additions & 7 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,16 @@ GEM
coffee-script-source (1.10.0)
concurrent-ruby (1.0.2)
connection_pool (2.2.0)
crack (0.4.3)
safe_yaml (~> 1.0.0)
daemons (1.2.3)
dalli (2.7.6)
database_cleaner (1.5.3)
debug_inspector (0.0.2)
diff-lcs (1.2.5)
docile (1.1.5)
domain_name (0.5.20160615)
unf (>= 0.0.5, < 1.0.0)
enumerize (1.1.1)
activesupport (>= 3.2)
erubis (2.7.0)
Expand Down Expand Up @@ -143,6 +147,7 @@ GEM
has_scope (0.6.0)
actionpack (>= 3.2, < 5)
activesupport (>= 3.2, < 5)
hashdiff (0.3.0)
hashie (3.4.3)
heroku-deflater (0.6.2)
rack (>= 1.4.5)
Expand All @@ -151,6 +156,8 @@ GEM
haml (~> 4.0.0)
nokogiri (~> 1.6.0)
ruby_parser (~> 3.5)
http-cookie (1.0.2)
domain_name (~> 0.5)
i18n (0.7.0)
inherited_resources (1.6.0)
actionpack (>= 3.2, < 5)
Expand Down Expand Up @@ -188,9 +195,7 @@ GEM
mail (2.6.4)
mime-types (>= 1.16, < 4)
method_source (0.8.2)
mime-types (3.1)
mime-types-data (~> 3.2015)
mime-types-data (3.2016.0521)
mime-types (2.99.2)
mini_portile2 (2.1.0)
minitest (5.9.0)
modware (0.1.3)
Expand All @@ -200,6 +205,7 @@ GEM
multi_json (1.12.1)
multi_xml (0.5.5)
multipart-post (2.0.0)
netrc (0.11.0)
nokogiri (1.6.8)
mini_portile2 (~> 2.1.0)
pkg-config (~> 1.1.7)
Expand All @@ -216,6 +222,8 @@ GEM
omniauth-github (1.1.2)
omniauth (~> 1.0)
omniauth-oauth2 (~> 1.1)
omniauth-intercom (0.1.1)
omniauth-oauth2 (~> 1.2)
omniauth-oauth2 (1.4.0)
oauth2 (~> 1.0)
omniauth (~> 1.2)
Expand Down Expand Up @@ -281,7 +289,11 @@ GEM
request_store (1.3.1)
responders (2.2.0)
railties (>= 4.2.0, < 5.1)
rspec-core (3.5.0)
rest-client (1.8.0)
http-cookie (>= 1.0.2, < 2.0)
mime-types (>= 1.16, < 3.0)
netrc (~> 0.7)
rspec-core (3.5.1)
rspec-support (~> 3.5.0)
rspec-expectations (3.5.0)
diff-lcs (>= 1.2.0, < 2.0)
Expand All @@ -300,6 +312,7 @@ GEM
rspec-support (3.5.0)
ruby_parser (3.8.2)
sexp_processor (~> 4.1)
safe_yaml (1.0.4)
sass (3.4.22)
sass-rails (5.0.5)
railties (>= 4.0.0, < 6)
Expand Down Expand Up @@ -374,6 +387,9 @@ GEM
thread_safe (~> 0.1)
uglifier (3.0.0)
execjs (>= 0.3.0, < 3)
unf (0.1.4)
unf_ext
unf_ext (0.0.7.2)
url (0.3.2)
useragent (0.16.7)
valuable (0.9.12)
Expand All @@ -382,6 +398,10 @@ GEM
warden_omniauth (0.1.0)
omniauth
warden (>= 0.9)
webmock (2.1.0)
addressable (>= 2.3.6)
crack (>= 0.3.2)
hashdiff
wicked (1.3.0)
railties (>= 3.0.7)
xpath (2.0.0)
Expand Down Expand Up @@ -423,13 +443,15 @@ DEPENDENCIES
momentjs-rails
nprogress-rails
omniauth-github
omniauth-intercom
passenger
pg
pry
rack-host-redirect
rails (= 4.2.6)
rails_12factor
rails_warden
rest-client
rspec-rails (~> 3.5)
sass-rails (~> 5.0.1)
schema_plus_foreign_keys
Expand All @@ -446,7 +468,5 @@ DEPENDENCIES
uglifier (>= 1.3.0)
useragent
warden_omniauth
webmock
wicked

BUNDLED WITH
1.12.5
Binary file added app/assets/images/icon_intercom.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions app/assets/stylesheets/pages/_error.scss
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,31 @@
}
}

.provider-button {
background: white;
border: 1px solid #cccccc;
color: #3b3f43;
padding: 0px 5px;
line-height:38px;
span {
display: block;
float: left;
width: 38px;
height: 38px;
margin-right:5px;
border-right: 1px solid #cccccc;
}
.github-button{
background: asset-url("icon_github.png") no-repeat center;
}
.intercom-button{
background: asset-url("icon_intercom.png") no-repeat center;
}
&:hover {
background: #eeeeee;
}
}

#error-details {
word-wrap: break-word;
.header {
Expand Down
15 changes: 15 additions & 0 deletions app/assets/stylesheets/pages/_integrations.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
.remove-button{
display: inline-block;
font-size: 12px;
padding: 3px 6px;
}

.integrations{
.panel-heading{
min-height: 45px;
.button_to{
display: inline-block;
float: right;
}
}
}
65 changes: 65 additions & 0 deletions app/controllers/auth_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
class AuthController < ApplicationController
skip_before_filter :verify_authenticity_token, only: [:success]
skip_before_action :authenticate!, only: [:success]

def create
unless Integrations.supports?(integration_params[:provider])
redirect_to settings_path(main_tab: 'integrations'), notice: 'Invalid Integration'
return
end

@integration = Integration.new(integration_params)
if @integration.valid?
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's better to do if @integration.save than to do save and then valid?.

@integration.website = current_website
session['integration'] = integration_params
redirect_to "/auth/#{@integration.provider}"
else
redirect_to settings_path(main_tab: 'integrations'), notice: 'Integration parameters are invalid!'
end
end

def success
unless authenticated?
user = User.find_by_provider_and_uid(provider, auth_hash['uid']) || User.create_with_omniauth(auth_hash)
if user
authenticate!(provider.to_sym)
set_website(current_user.websites.first) unless current_user.websites.empty?
end
end
if integration_session
# create integration
begin
Integration.transaction do
@integration = current_website.integrations.build(integration_session)
@integration.assign_configuration(auth_hash)
@integration.save!
redirect_to settings_path(main_tab: 'integrations', integration_tab: provider ), notice: 'Integration created'
end
rescue
redirect_to settings_path(main_tab: 'integrations'), flash: { error: 'Error creating integration' }
ensure
session['integration'] = nil
end
else
after_login_redirect
end
end

private

def auth_hash
request.env['omniauth.auth']
end

def provider
auth_hash['provider']
end

def integration_session
session['integration']
end

def integration_params
@params ||= params.require(:integration).permit(:integration_type, :name, :provider)
end
end
16 changes: 13 additions & 3 deletions app/controllers/errors_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,19 @@ def update

def notify_subscribers
unless params[:message].blank?
@message = Message.create( content: params[:message], issue_id: @error.issues.last.id )
@error.website.subscribers.each do |subscriber|
GroupedIssueMailer.notify_subscriber(@error, subscriber, current_user, @message).deliver_later
if params[:intercom]
begin
current_website.intercom_integration.driver.send_message(params[:users], params[:message])
redirect_to error_path(@error), flash: { success: 'Message successfully sent!' }
rescue => e
redirect_to error_path(@error), flash: { error: 'Operation failed!' }
end
else
@message = Message.create( content: params[:message], issue_id: @error.issues.last.id )
@error.subscribers.each do |subscriber|
GroupedIssueMailer.notify_subscriber(@error, subscriber, current_user, @message).deliver_later
end
redirect_to error_path(@error), flash: { success: 'Message successfully sent!' }
end
end
end
Expand Down
28 changes: 28 additions & 0 deletions app/controllers/integrations_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
class IntegrationsController < ApplicationController
load_and_authorize_resource

def update
if @integration.update_attributes(integration_params)
redirect_to settings_path(main_tab: 'integrations', integration_tab: @integration.provider), notice: 'Integration updated!'
end
end

def destroy
if @integration.destroy
redirect_to settings_path(main_tab: 'integrations', integration_tab: @integration.provider), notice: 'Integration deleted!'
end
end

def create_task
begin
task = @integration.driver.create_task(params[:title])
redirect_to error_path(params[:error_id], task: task)
rescue
redirect_to error_path(params[:error_id], task: task), flash: { error: "Operation failed!" }
end
end

def integration_params
@integration_params ||= params.require(:integration).permit(:application)
end
end
12 changes: 0 additions & 12 deletions app/controllers/omniauth_controller.rb

This file was deleted.

1 change: 1 addition & 0 deletions app/controllers/settings_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ def index

@details_tab = params[:details_tab] || "settings"
@configuration_tab = params[:configuration_tab] || "all_platforms"
@integration_tab = params[:integration_tab] || "github"
@platform_tab = params[:platform_tab] || @configuration_tab

@options = ["Javascript", "Python", "Django", "Flask", "Tornado", "Php", "Ruby", "Rails 3", "Rails 4", "Sinatra", "Sidekiq", "Node js", "Express", "Connect", "Java", "Java util logging", "Log4j", "Log4j2", "Logback", "Ios"]
Expand Down
2 changes: 0 additions & 2 deletions app/helpers/accounts_helper.rb

This file was deleted.

2 changes: 0 additions & 2 deletions app/helpers/api/home_helper.rb

This file was deleted.

2 changes: 0 additions & 2 deletions app/helpers/home_helper.rb

This file was deleted.

2 changes: 0 additions & 2 deletions app/helpers/omniauth_helper.rb

This file was deleted.

2 changes: 0 additions & 2 deletions app/helpers/sessions_helper.rb

This file was deleted.

2 changes: 0 additions & 2 deletions app/helpers/settings_helper.rb

This file was deleted.

3 changes: 3 additions & 0 deletions app/models/ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ def initialize(user)
can [:change_current, :read], Website do |website|
user.is_member_of?(website)
end
can :manage, Integration do |integration|
user.is_owner_of?(integration.website)
end
can :create, Website
can :manage, WebsiteMember do |website_member|
user.is_owner_of?(website_member.website)
Expand Down
Loading