This repository has been archived by the owner on Jan 23, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #125 from akiko-pusu/dev
Ready for release: v0.3.0
- Loading branch information
Showing
38 changed files
with
711 additions
and
751 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 |
---|---|---|
|
@@ -2,9 +2,6 @@ | |
# | ||
# Check https://circleci.com/docs/2.0/language-ruby/ for more details | ||
# | ||
orbs: | ||
aws-ecr: circleci/[email protected] | ||
|
||
version: 2.1 | ||
|
||
general: | ||
|
@@ -96,23 +93,6 @@ workflows: | |
branches: | ||
ignore: | ||
- /v0.1.x-support-Redmine3.*/ | ||
- aws-ecr/build-and-push-image: | ||
account-url: AWS_ECR_ACCOUNT_URL | ||
aws-access-key-id: AWS_ACCESS_KEY_ID | ||
aws-secret-access-key: AWS_SECRET_ACCESS_KEY | ||
create-repo: true | ||
dockerfile: Dockerfile | ||
path: . | ||
region: AWS_REGION | ||
repo: redmine_banner | ||
extra-build-args: '--build-arg COMMIT=$CIRCLE_SHA1 --build-arg=BRANCH=$CIRCLE_BRANCH' | ||
requires: | ||
- test | ||
tag: '$CIRCLE_BUILD_NUM' | ||
filters: | ||
branches: | ||
only: | ||
- master | ||
- deploy_heroku: | ||
requires: | ||
- build | ||
|
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,4 +1,5 @@ | ||
inherit_from: .rubocop_todo.yml | ||
|
||
AllCops: | ||
TargetRubyVersion: 2.3 | ||
|
||
|
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 |
---|---|---|
@@ -0,0 +1,83 @@ | ||
# frozen_string_literal: true | ||
|
||
class GlobalBannerController < ApplicationController | ||
before_action :require_login, :require_banner_admin | ||
|
||
def show | ||
global_banner = GlobalBanner.find_or_default | ||
render layout: !request.xhr?, locals: setting_values(global_banner) | ||
end | ||
|
||
def update | ||
global_banner = GlobalBanner.find_or_default | ||
|
||
begin | ||
global_banner_params = build_params | ||
rescue ActionController::ParameterMissing, ActionController::UnpermittedParameters => e | ||
response_bad_request(e.message) && (return) | ||
end | ||
|
||
global_banner.merge_value(global_banner_params.stringify_keys) | ||
|
||
unless global_banner.valid_date_range? && global_banner.save | ||
flash[:error] = l(:error_banner_date_range) | ||
redirect_to action: 'show' | ||
return | ||
end | ||
|
||
flash[:notice] = l(:notice_successful_update) | ||
redirect_to action: 'show' | ||
nil | ||
end | ||
|
||
private | ||
|
||
def require_banner_admin | ||
return if User.current.admin? || GlobalBanner.banner_admin?(User.current) | ||
|
||
render_403 | ||
false | ||
end | ||
|
||
def build_params | ||
keys = GlobalBanner::GLOBAL_BANNER_DEFAULT_SETTING.stringify_keys.keys | ||
|
||
unless User.current.admin? | ||
keys.delete('banner_admin') | ||
end | ||
|
||
params.require(:setting).permit(keys) | ||
end | ||
|
||
def setting_values(instance) | ||
setting = instance.value | ||
|
||
current_time = Time.zone.now | ||
use_timer = instance.use_timer? | ||
|
||
begin | ||
# date range check | ||
start_datetime = instance.start_time | ||
end_datetime = instance.end_time | ||
rescue ArgumentError | ||
# Ref. https://github.com/akiko-pusu/redmine_banner/issues/11 | ||
start_datetime = current_time | ||
end_datetime = current_time | ||
use_timer = false | ||
end | ||
|
||
banner_description = setting[:banner_description] | ||
|
||
if banner_description.respond_to?(:force_encoding) | ||
setting[:banner_description] = banner_description.force_encoding('UTF-8') | ||
end | ||
|
||
{ | ||
setting: setting.stringify_keys, | ||
start_datetime: start_datetime, | ||
end_datetime: end_datetime, | ||
use_timer: use_timer, | ||
banner_updated_on: instance&.updated_on&.localtime | ||
} | ||
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
Oops, something went wrong.