-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
110 changed files
with
2,347 additions
and
1,235 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
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,44 @@ | ||
# frozen_string_literal: true | ||
|
||
class Api::V1::SnsSubscriptionsController < ApplicationController | ||
skip_before_action :authenticate_user! | ||
skip_after_action :verify_authorized | ||
skip_before_action :verify_authenticity_token | ||
|
||
def create | ||
sns_message = JSON.parse(request.body.read) | ||
|
||
if sns_message["Type"] == "SubscriptionConfirmation" | ||
response = HTTParty.get(sns_message["SubscribeURL"]) | ||
render json: { message: "Subscription confirmed successfully" }, status: :ok | ||
else | ||
message = JSON.parse(sns_message["Message"]) | ||
|
||
if message["eventType"] == "Bounce" | ||
handle_bounced_email(message) | ||
elsif message["eventType"] == "Complaint" | ||
handle_compliant_email(message) | ||
end | ||
|
||
render json: { message: "success" }, status: :ok | ||
end | ||
end | ||
|
||
private | ||
|
||
def handle_bounced_email(message) | ||
bounce_recipients = message.dig("bounce", "bouncedRecipients") | ||
bounce_recipients.each do |recipient| | ||
next if recipient["action"] != "failed" | ||
|
||
SesInvalidEmail.find_or_create_by(email: recipient["emailAddress"], bounce: true) | ||
end | ||
end | ||
|
||
def handle_compliant_email(message) | ||
compliant_recipients = message.dig("complaint", "complainedRecipients") | ||
compliant_recipients.each do |recipient| | ||
SesInvalidEmail.find_or_create_by(email: recipient["emailAddress"], compliant: true) | ||
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
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
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
46 changes: 46 additions & 0 deletions
46
app/controllers/internal_api/v1/timeoff_entries_controller.rb
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,46 @@ | ||
# frozen_string_literal: true | ||
|
||
class InternalApi::V1::TimeoffEntriesController < InternalApi::V1::ApplicationController | ||
before_action :load_user!, only: [:create, :update] | ||
before_action :load_leave_type!, only: [:create, :update] | ||
before_action :load_timeoff_entry!, only: [:update, :destroy] | ||
|
||
def create | ||
authorize TimeoffEntry | ||
|
||
timeoff_entry = @user.timeoff_entries.create!(timeoff_params) | ||
render json: { notice: "Added time off successfully", timeoff_entry: }, status: :ok | ||
end | ||
|
||
def update | ||
authorize @timeoff_entry | ||
|
||
@timeoff_entry.update!(timeoff_params) | ||
render json: { notice: "Updated time off successfully", timeoff_entry: @timeoff_entry }, status: :ok | ||
end | ||
|
||
def destroy | ||
authorize @timeoff_entry | ||
|
||
@timeoff_entry.discard! | ||
render json: { notice: "Deleted time off successfully", timeoff_entry: @timeoff_entry }, status: :ok | ||
end | ||
|
||
private | ||
|
||
def timeoff_params | ||
params.require(:timeoff_entry).permit(policy(TimeoffEntry).permitted_attributes) | ||
end | ||
|
||
def load_user! | ||
@user ||= current_company.users.find(params[:timeoff_entry][:user_id]) | ||
end | ||
|
||
def load_leave_type! | ||
@leave_type ||= current_company.leave_types.find(params[:timeoff_entry][:leave_type_id]) | ||
end | ||
|
||
def load_timeoff_entry! | ||
@timeoff_entry ||= current_company.timeoff_entries.find(params[: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
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
Oops, something went wrong.