This repository has been archived by the owner on Jul 22, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[refactor] extract common logic from chat integration controllers
- Loading branch information
Showing
4 changed files
with
38 additions
and
50 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,24 @@ | ||
class ChatIntegrationsController < AbstractSecurityController | ||
def create | ||
@chat_integration = chat_klass.new(chat_integration_params) | ||
@chat_integration.project = @project | ||
if @chat_integration.save | ||
flash[:notice] = "Settings saved" | ||
redirect_to edit_project_path(@project) | ||
else | ||
flash[:error] = "Settings could not be saved" | ||
redirect_to edit_project_path(@project) | ||
end | ||
end | ||
|
||
def update | ||
@chat_integration = @project.send(chat_klass.name.underscore) | ||
if @chat_integration.update_attributes(chat_integration_params) | ||
flash[:notice] = "Settings updated" | ||
redirect_to edit_project_path(@project) | ||
else | ||
flash[:error] = "Settings could not be updated" | ||
redirect_to edit_project_path(@project) | ||
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 |
---|---|---|
@@ -1,30 +1,12 @@ | ||
class HipChatIntegrationsController < AbstractSecurityController | ||
def create | ||
@hip_chat_integration = HipChatIntegration.new(hip_chat_integration_params) | ||
@hip_chat_integration.project = @project | ||
if @hip_chat_integration.save | ||
flash[:notice] = "HipChat settings saved" | ||
redirect_to edit_project_path(@project) | ||
else | ||
flash[:error] = "HipChat settings could not be saved" | ||
redirect_to edit_project_path(@project) | ||
end | ||
end | ||
|
||
def update | ||
@hip_chat_integration = @project.hip_chat_integration | ||
if @hip_chat_integration.update_attributes(hip_chat_integration_params) | ||
flash[:notice] = "HipChat settings updated" | ||
redirect_to edit_project_path(@project) | ||
else | ||
flash[:error] = "HipChat settings could not be updated" | ||
redirect_to edit_project_path(@project) | ||
end | ||
end | ||
class HipChatIntegrationsController < ChatIntegrationsController | ||
|
||
private | ||
|
||
def hip_chat_integration_params | ||
def chat_klass | ||
HipChatIntegration | ||
end | ||
|
||
def chat_integration_params | ||
params[:hip_chat_integration].permit(:token, :room, :notify) | ||
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 |
---|---|---|
@@ -1,30 +1,12 @@ | ||
class SlackIntegrationsController < AbstractSecurityController | ||
def create | ||
@slack_integration = SlackIntegration.new(slack_integration_params) | ||
@slack_integration.project = @project | ||
if @slack_integration.save | ||
flash[:notice] = "Slack settings saved" | ||
redirect_to edit_project_path(@project) | ||
else | ||
flash[:error] = "Slack settings could not be saved" | ||
redirect_to edit_project_path(@project) | ||
end | ||
end | ||
|
||
def update | ||
@slack_integration = @project.slack_integration | ||
if @slack_integration.update_attributes(slack_integration_params) | ||
flash[:notice] = "Slack settings updated" | ||
redirect_to edit_project_path(@project) | ||
else | ||
flash[:error] = "Slack settings could not be updated" | ||
redirect_to edit_project_path(@project) | ||
end | ||
end | ||
class SlackIntegrationsController < ChatIntegrationsController | ||
|
||
private | ||
|
||
def slack_integration_params | ||
def chat_klass | ||
SlackIntegration | ||
end | ||
|
||
def chat_integration_params | ||
params[:slack_integration].permit(:team, :token, :channel) | ||
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