Skip to content
This repository has been archived by the owner on Jan 23, 2021. It is now read-only.

Commit

Permalink
Merge pull request #109 from akiko-pusu/dev
Browse files Browse the repository at this point in the history
Update version to 0.2.1.
  • Loading branch information
akiko-pusu authored Aug 21, 2019
2 parents f3dfde7 + eb945a6 commit 56b8ea6
Show file tree
Hide file tree
Showing 15 changed files with 575 additions and 93 deletions.
60 changes: 56 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
#
# Check https://circleci.com/docs/2.0/language-ruby/ for more details
#
version: 2
orbs:
aws-ecr: circleci/[email protected]

version: 2.1

general:
artifacts:
Expand Down Expand Up @@ -55,17 +58,66 @@ jobs:
cp -r coverage/${CIRCLE_PROJECT_REPONAME}_test /tmp/coverage/
- store_artifacts:
path: /tmp/coverage
deploy_heroku:
machine:
image: circleci/classic:edge
steps:
- checkout
- run:
name: 'Install Heroku CLI, if necessary'
command: |
curl https://cli-assets.heroku.com/install.sh | sh
- run:
name: 'Build Docker Image'
command: |
heroku -v
docker build --build-arg=COMMIT=${CIRCLE_SHA1} \
--build-arg=BRANCH=${CIRCLE_BRANCH} -t registry.heroku.com/${HEROKU_APP_NAME}/web .
- run:
name: 'Release Docker Image'
command: |
docker login --username=_ --password=$HEROKU_AUTH_TOKEN registry.heroku.com
docker push registry.heroku.com/${HEROKU_APP_NAME}/web
#heroku container:push web --app ${HEROKU_APP_NAME}
heroku container:release web --app ${HEROKU_APP_NAME}
workflows:
version: 2
build_and_test:
build_test_push:
jobs:
- build
- build:
filters:
branches:
ignore:
- /ignore-build-.*/
- test:
requires:
- build
filters:
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
filters:
branches:
only:
- master
- deploy_heroku:
requires:
- build
filters:
branches:
ignore:
- master


3 changes: 1 addition & 2 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
inherit_from: .rubocop_todo.yml
AllCops:
# TODO: Change TargetRubyVersion to 2.0 or higher, when Redmine cloded to support ruby 1.9x.
TargetRubyVersion: 2.2
TargetRubyVersion: 2.3

Style/IfUnlessModifier:
Enabled: false
Expand Down
52 changes: 35 additions & 17 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,41 +1,59 @@
#
# docker build --build-arg=COMMIT=$(git rev-parse --short HEAD) \
# --build-arg=BRANCH=$(git name-rev --name-only HEAD) -t akiko/redmine_banner:latest .
#
#
FROM ruby:2.5
LABEL maintainer="AKIKO TAKANO / (Twitter: @akiko_pusu)" \
description="Image to run Redmine simply with sqlite to try/review plugin."

ARG BRANCH="master"
ARG COMMIT="commit_sha"

ENV COMMIT_SHA=${COMMIT}
ENV COMMIT_BRANCH=${BRANCH}

RUN mkdir /app

### get Redmine source
### Replace shell with bash so we can source files ###
RUN rm /bin/sh && ln -s /bin/bash /bin/sh

### install default sys packeges ###

RUN apt-get update
RUN apt-get install -qq -y \
RUN apt-get install -qq -y --no-install-recommends \
git vim subversion \
sqlite3 default-libmysqlclient-dev
RUN apt-get install -qq -y build-essential libc6-dev
sqlite3 && rm -rf /var/lib/apt/lists/*

RUN cd /tmp && svn co http://svn.redmine.org/redmine/branches/4.0-stable/ redmine
WORKDIR /tmp/redmine
RUN cd /app && svn co http://svn.redmine.org/redmine/branches/4.0-stable/ redmine
WORKDIR /app/redmine

COPY . /app/redmine/plugins/redmine_banner/

# add database.yml (for development, development with mysql, test)
RUN echo $'test:\n\
adapter: sqlite3\n\
database: /tmp/data/redmine_test.sqlite3\n\
database: /app/data/redmine_test.sqlite3\n\
encoding: utf8mb4\n\
development:\n\
adapter: sqlite3\n\
database: /tmp/data/redmine_development.sqlite3\n\
encoding: utf8mb4\n\
development_mysql:\n\
adapter: mysql2\n\
host: mysql\n\
password: pasword\n\
database: redemine_development\n\
username: root\n'\
database: /app/data/redmine_development.sqlite3\n\
encoding: utf8mb4\n'\
>> config/database.yml

RUN gem update bundler
RUN bundle install --without postgresql rmagick
RUN bundle exec rake db:migrate

RUN bundle install --without postgresql rmagick mysql
RUN bundle exec rake db:migrate && bundle exec rake redmine:plugins:migrate \
&& bundle exec rake generate_secret_token
RUN bundle exec rails runner \
"Setting.send('plugin_redmine_banner=', {enable: 'true', type: 'info', display_part: 'both', banner_description: 'This is a test message for Global Banner. (${COMMIT_BRANCH}:${COMMIT_SHA})'}.stringify_keys)"

# Change Admin's password to 'redmine_banner_${COMMIT_SHA}'
# Default is 'redmine_banner_commit_sha'
RUN bundle exec rails runner \
"User.find_by_login('admin').update!(password: 'redmine_banner_${COMMIT_SHA}', must_change_passwd: false)"

EXPOSE 3000
RUN ls /app/redmine
CMD ["rails", "server", "-b", "0.0.0.0"]
51 changes: 51 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,19 @@ Please use ver **0.1.x** or ``v0.1.x-support-Redmine3`` branch in case using Red

## Changelog

### 0.2.1

* Fix: Prevent conflict with CKEditor. (GitHub: #111)
* Code refactoring.
* Add feature to update Global Banner via API. (Alpha / Related: #86 #113)
* Not only Redmine admin but also user who assigned group named **GlobalBanner_Admin** can also update Global banner via API.
* Even prptotype version.
* Please see [swagger.yml](script/swagger.yml) to try update global banner via API.
* Update CI Setting
* Add step to build and push image to AWS ECR.
* Add steps to build and deploy to Heroku Container registry as release container service.
* Add how to try banner via Docker in README.

### 0.2.0

* Support Redmine 4.x.
Expand Down Expand Up @@ -129,6 +142,44 @@ NOTE: Mainly, maintenance, bugfix and refactoring only. There is no additional f

* First release

### Quick try with using Docker

You can try quickly this plugin with Docker environment.
Please try:

```bash
# Admin password is 'redmine_banner_commit_sha'
$ https://github.com/akiko-pusu/redmine_banner
$ docker-compose up web -d

# or
#
# Admin password is 'redmine_banner_{COMMIT}'
$ docker build --build-arg=COMMIT=$(git rev-parse --short HEAD) \
--build-arg=BRANCH=$(git name-rev --name-only HEAD) -t akiko/redmine_banner:latest .

$ docker run -p 3000:3000 akiko/redmine_banner:latest
```

### Run test

Please see wercker.yml for more details.

```bash
% cd REDMINE_ROOT_DIR
% cp plugins/redmine_banner/Gemfile.local plugins/redmine_banner/Gemfile
% bundle install --with test
% export RAILS_ENV=test
% bundle exec ruby -I"lib:test" -I plugins/redmine_banner/test plugins/ \
redmine_banner/test/controller/global_banner_controller_test.rb
```

or

```bash
% bundle exec rails redmine_banner:test
```

### Repository

* <https://github.com/akiko-pusu/redmine_banner>
Expand Down
1 change: 0 additions & 1 deletion _config.yml

This file was deleted.

61 changes: 0 additions & 61 deletions _layouts/default.html

This file was deleted.

94 changes: 94 additions & 0 deletions app/controllers/banners/api/global_banner_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# frozen_string_literal: true

module Banners
module Api
class GlobalBannerController < ApplicationController
# TODO: This group should be customize.
GLOBAL_BANNER_ADMIN_GROUP = 'GlobalBanner_Admin'

before_action :require_login, :require_banner_admin
accept_api_auth :show, :register_banner

def show
render json: global_banner_json
end

def register_banner
begin
global_banner_params = build_params
rescue ActionController::ParameterMissing, ActionController::UnpermittedParameters => e
response_bad_request(e.message) && (return)
end

retval = Setting.send('plugin_redmine_banner=', global_banner_params.stringify_keys)

if retval
render status: 200, json: { status: 'OK', message: 'updating the global banner' }
else
response_bad_request("Can't save data to settings table.")
end
rescue StandardError => e
response_internal_server_error(e.message)
end

private

# TODO: Private methods should be refactoring.
# TODO: Validation is required
def build_params
valid_params(params)
end

def global_banner_json
{ global_banner: Setting['plugin_redmine_banner'] }
end

# 400 Bad Request
def response_bad_request(error_message = nil)
json_data = { status: 400, message: 'Bad Request' }
json_data.merge!(reason: error_message) if error_message.present?
logger.warn("Global Banner Update failed. Caused: #{json_data}")
render status: 400, json: json_data
end

# 401 Unauthorized
def response_unauthorized
render status: 401, json: { status: 401, message: 'Unauthorized' }
end

# 500 Internal Server Error
def response_internal_server_error(error_message = nil)
json_data = { status: 500, message: 'Internal Server Error' }
json_data.merge!(reason: error_message) if error_message.present?
logger.warn("Global Banner Update failed. Caused: #{json_data}")
render status: 500, json: json_data
end

def require_banner_admin
return if User.current.admin? || banner_admin?(User.current)

response_unauthorized
end

def banner_admin?(user)
banner_admin_group = Group.find_by_lastname(GLOBAL_BANNER_ADMIN_GROUP)
return false if banner_admin_group.blank?

banner_admin_group.users.include?(user)
end

def valid_params(params)
params.require(:global_banner).permit(
:banner_description,
:display_part,
:enable,
:end_hour, :end_min, :end_ymd,
:related_link,
:start_hour, :start_min, :start_ymd,
:type,
:use_timer
)
end
end
end
end
Loading

0 comments on commit 56b8ea6

Please sign in to comment.