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
56 changed files
with
427 additions
and
406 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
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 |
---|---|---|
@@ -1,56 +1,58 @@ | ||
# frozen_string_literal: true | ||
|
||
class Api::ApplicationController < ActionController::Base | ||
respond_to :json | ||
rescue_from ActiveRecord::RecordNotFound, with: :handle_not_found | ||
rescue_from ActionController::ParameterMissing, with: :handle_unprocessable_entity | ||
module Api | ||
class ApplicationController < ActionController::Base | ||
respond_to :json | ||
rescue_from ActiveRecord::RecordNotFound, with: :handle_not_found | ||
rescue_from ActionController::ParameterMissing, with: :handle_unprocessable_entity | ||
|
||
before_action :verify_api_key | ||
before_action :set_default_response_format | ||
before_action :verify_api_key | ||
before_action :set_default_response_format | ||
|
||
def verify_api_key | ||
api_user | ||
end | ||
def verify_api_key | ||
api_user | ||
end | ||
|
||
def api_user | ||
@api_user ||= authenticate_params || authenticate_token || unauthorized | ||
end | ||
def api_user | ||
@api_user ||= authenticate_params || authenticate_token || unauthorized | ||
end | ||
|
||
def uid_user | ||
@uid_user ||= User.find_by_uid(params[:steam_uid]) | ||
end | ||
def uid_user | ||
@uid_user ||= User.find_by_uid(params[:steam_uid]) | ||
end | ||
|
||
def current_user | ||
@current_user ||= (api_user&.admin? && uid_user) || api_user | ||
end | ||
def current_user | ||
@current_user ||= (api_user&.admin? && uid_user) || api_user | ||
end | ||
|
||
def handle_not_found | ||
head :not_found | ||
end | ||
def handle_not_found | ||
head :not_found | ||
end | ||
|
||
def handle_unprocessable_entity | ||
Rails.logger.warn "UNPROCESSABLE ENTITY: #{request.body.read}" | ||
head :unprocessable_entity | ||
end | ||
def handle_unprocessable_entity | ||
Rails.logger.warn "UNPROCESSABLE ENTITY: #{request.body.read}" | ||
head :unprocessable_entity | ||
end | ||
|
||
private | ||
private | ||
|
||
def authenticate_params | ||
User.find_by(api_key: params[:api_key]) if params[:api_key] | ||
end | ||
def authenticate_params | ||
User.find_by(api_key: params[:api_key]) if params[:api_key] | ||
end | ||
|
||
def authenticate_token | ||
authenticate_with_http_token do |token, _options| | ||
User.find_by(api_key: token) | ||
def authenticate_token | ||
authenticate_with_http_token do |token, _options| | ||
User.find_by(api_key: token) | ||
end | ||
end | ||
end | ||
|
||
def unauthorized | ||
head :unauthorized | ||
nil | ||
end | ||
def unauthorized | ||
head :unauthorized | ||
nil | ||
end | ||
|
||
def set_default_response_format | ||
request.format = :json | ||
def set_default_response_format | ||
request.format = :json | ||
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,51 +1,53 @@ | ||
# frozen_string_literal: true | ||
|
||
class Api::DonatorsController < Api::ApplicationController | ||
before_action :require_admin | ||
|
||
def show | ||
@user = Group.donator_group.users.find_by(uid: params[:id]) | ||
if @user && (@donator = @user.group_users.find_by(group_id: Group.donator_group.id)) | ||
render :show | ||
else | ||
head :not_found | ||
module Api | ||
class DonatorsController < Api::ApplicationController | ||
before_action :require_admin | ||
|
||
def show | ||
@user = Group.donator_group.users.find_by(uid: params[:id]) | ||
if @user && (@donator = @user.group_users.find_by(group_id: Group.donator_group.id)) | ||
render :show | ||
else | ||
head :not_found | ||
end | ||
end | ||
end | ||
|
||
def new | ||
@user = GroupUser.new | ||
render :new | ||
end | ||
def new | ||
@user = GroupUser.new | ||
render :new | ||
end | ||
|
||
def create | ||
@user = User.find_by_uid(donator_params[:steam_uid]) | ||
if @user | ||
@donator = Group.donator_group.group_users.find_or_initialize_by(user_id: @user.id) | ||
@donator.expires_at = donator_params[:expires_at] | ||
@donator.save | ||
render :show | ||
else | ||
head :not_found | ||
def create | ||
@user = User.find_by_uid(donator_params[:steam_uid]) | ||
if @user | ||
@donator = Group.donator_group.group_users.find_or_initialize_by(user_id: @user.id) | ||
@donator.expires_at = donator_params[:expires_at] | ||
@donator.save | ||
render :show | ||
else | ||
head :not_found | ||
end | ||
end | ||
end | ||
|
||
def destroy | ||
group_users = Group.donator_group.group_users.joins(:user).where(users: { uid: params[:id] }) | ||
if group_users.any? | ||
group_users.update_all(expires_at: 1.second.ago) | ||
head :no_content | ||
else | ||
head :not_found | ||
def destroy | ||
group_users = Group.donator_group.group_users.joins(:user).where(users: { uid: params[:id] }) | ||
if group_users.any? | ||
group_users.update_all(expires_at: 1.second.ago) | ||
head :no_content | ||
else | ||
head :not_found | ||
end | ||
end | ||
end | ||
|
||
def donator_params | ||
params.require(:donator).permit(:steam_uid, :expires_at) | ||
end | ||
def donator_params | ||
params.require(:donator).permit(:steam_uid, :expires_at) | ||
end | ||
|
||
private | ||
private | ||
|
||
def require_admin | ||
api_user&.admin? || unauthorized | ||
def require_admin | ||
api_user&.admin? || unauthorized | ||
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,8 +1,10 @@ | ||
# frozen_string_literal: true | ||
|
||
class Api::MapsController < Api::ApplicationController | ||
def index | ||
@maps = MapUpload.available_maps | ||
@cloud_maps = MapUpload.available_cloud_maps | ||
module Api | ||
class MapsController < Api::ApplicationController | ||
def index | ||
@maps = MapUpload.available_maps | ||
@cloud_maps = MapUpload.available_cloud_maps | ||
end | ||
end | ||
end |
Oops, something went wrong.