common_engine 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +24 -0
- data/Rakefile +6 -0
- data/app/assets/config/manifest.js +3 -0
- data/app/assets/javascripts/application.js +16 -0
- data/app/assets/javascripts/cable.js +13 -0
- data/app/assets/javascripts/init_fullcalendar.js +40 -0
- data/app/assets/stylesheets/application.css +15 -0
- data/app/channels/application_cable/channel.rb +4 -0
- data/app/channels/application_cable/connection.rb +4 -0
- data/app/controllers/application_base_controller.rb +61 -0
- data/app/controllers/concerns/fullcalendar_utility.rb +47 -0
- data/app/controllers/concerns/zoom_utility.rb +110 -0
- data/app/helpers/application_helper.rb +2 -0
- data/app/jobs/application_job.rb +2 -0
- data/app/mailers/application_mailer.rb +4 -0
- data/app/models/application_base_record.rb +48 -0
- data/app/models/common_engine/admin.rb +13 -0
- data/app/models/common_engine/admin_login_history.rb +5 -0
- data/app/models/common_engine/chapter.rb +25 -0
- data/app/models/common_engine/commodity.rb +6 -0
- data/app/models/common_engine/course.rb +8 -0
- data/app/models/common_engine/event.rb +5 -0
- data/app/models/common_engine/favorite.rb +8 -0
- data/app/models/common_engine/group.rb +9 -0
- data/app/models/common_engine/idle.rb +35 -0
- data/app/models/common_engine/idle_login_history.rb +7 -0
- data/app/models/common_engine/notice.rb +8 -0
- data/app/models/common_engine/schedule.rb +32 -0
- data/app/models/common_engine/settlement_history.rb +8 -0
- data/app/models/common_engine/user.rb +15 -0
- data/app/models/common_engine/user_login_history.rb +7 -0
- data/app/models/concerns/image_uploader.rb +49 -0
- data/app/models/concerns/login_module.rb +14 -0
- data/app/views/_prepare_fullcalendar.slim +20 -0
- data/app/views/errors/error_404.html.slim +1 -0
- data/app/views/errors/error_500.html.slim +1 -0
- data/app/views/layouts/application_base.html.erb +29 -0
- data/config/application.rb +19 -0
- data/config/boot.rb +4 -0
- data/config/cable.yml +10 -0
- data/config/credentials.yml.enc +1 -0
- data/config/database.yml +93 -0
- data/config/environment.rb +5 -0
- data/config/environments/development.rb +61 -0
- data/config/environments/production.rb +94 -0
- data/config/environments/test.rb +46 -0
- data/config/initializers/application_controller_renderer.rb +10 -0
- data/config/initializers/assets.rb +14 -0
- data/config/initializers/backtrace_silencers.rb +7 -0
- data/config/initializers/content_security_policy.rb +25 -0
- data/config/initializers/cookies_serializer.rb +5 -0
- data/config/initializers/filter_parameter_logging.rb +4 -0
- data/config/initializers/inflections.rb +16 -0
- data/config/initializers/mime_types.rb +4 -0
- data/config/initializers/wrap_parameters.rb +14 -0
- data/config/locales/en.yml +251 -0
- data/config/locales/ja.yml +255 -0
- data/config/locales/vi.yml +249 -0
- data/config/puma.rb +34 -0
- data/config/routes.rb +3 -0
- data/config/spring.rb +6 -0
- data/config/storage.yml +34 -0
- data/db/schema.rb +18 -0
- data/db/seeds.rb +7 -0
- data/lib/common_engine.rb +9 -0
- data/lib/common_engine/engine.rb +5 -0
- data/lib/common_engine/version.rb +3 -0
- metadata +125 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 60cd7fe237812c298ece8806d4e4bd4b39a0aec154a20d743811be9ecbc910df
|
4
|
+
data.tar.gz: 7c65186781fd5b34e6e22af2306c92d01a00f3a96beb21597648bdeca282bab5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8cf3a899d4012a852c9c16d718e8fbda55e2fa6a955523b6fa52829eee1d4f22cea7b1780c57709422e912dd2b02e19dedadcf843651a3f6b62ff2d9d7b45cee
|
7
|
+
data.tar.gz: c4808ef62422cbd377657595b8f1a1d2bcba13ef7fe2d18d12d4bf48472e5c35f5505fad25e03428d712af109d17f7639e77da1bd0ce600fb0c00324c5ffcd9d
|
data/README.md
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# README
|
2
|
+
|
3
|
+
This README would normally document whatever steps are necessary to get the
|
4
|
+
application up and running.
|
5
|
+
|
6
|
+
Things you may want to cover:
|
7
|
+
|
8
|
+
* Ruby version
|
9
|
+
|
10
|
+
* System dependencies
|
11
|
+
|
12
|
+
* Configuration
|
13
|
+
|
14
|
+
* Database creation
|
15
|
+
|
16
|
+
* Database initialization
|
17
|
+
|
18
|
+
* How to run the test suite
|
19
|
+
|
20
|
+
* Services (job queues, cache servers, search engines, etc.)
|
21
|
+
|
22
|
+
* Deployment instructions
|
23
|
+
|
24
|
+
* ...
|
data/Rakefile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
+
// listed below.
|
3
|
+
//
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, or any plugin's
|
5
|
+
// vendor/assets/javascripts directory can be referenced here using a relative path.
|
6
|
+
//
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
+
// compiled file. JavaScript code in this file should be added after the last require_* statement.
|
9
|
+
//
|
10
|
+
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
|
11
|
+
// about supported directives.
|
12
|
+
//
|
13
|
+
//= require rails-ujs
|
14
|
+
//= require activestorage
|
15
|
+
//= require turbolinks
|
16
|
+
//= require_tree .
|
@@ -0,0 +1,13 @@
|
|
1
|
+
// Action Cable provides the framework to deal with WebSockets in Rails.
|
2
|
+
// You can generate new channels where WebSocket features live using the `rails generate channel` command.
|
3
|
+
//
|
4
|
+
//= require action_cable
|
5
|
+
//= require_self
|
6
|
+
//= require_tree ./channels
|
7
|
+
|
8
|
+
(function() {
|
9
|
+
this.App || (this.App = {});
|
10
|
+
|
11
|
+
App.cable = ActionCable.createConsumer();
|
12
|
+
|
13
|
+
}).call(this);
|
@@ -0,0 +1,40 @@
|
|
1
|
+
function initFullCallendar() {
|
2
|
+
$('#calendar').empty();
|
3
|
+
$('#calendar').fullCalendar({
|
4
|
+
header: {
|
5
|
+
left: 'prev,next today',
|
6
|
+
center: 'title',
|
7
|
+
right: 'month agendaWeek agendaDay'
|
8
|
+
},
|
9
|
+
defaultView: 'agendaWeek',
|
10
|
+
weekends: true,
|
11
|
+
firstHour: 9,
|
12
|
+
minTime: '09:00:00',
|
13
|
+
maxTime: '20:00:00',
|
14
|
+
height: 'auto',
|
15
|
+
allDaySlot: false,
|
16
|
+
views: {
|
17
|
+
month: {
|
18
|
+
titleFormat: titleFormatMonth
|
19
|
+
},
|
20
|
+
week: {
|
21
|
+
titleFormat: titleFormatWeek
|
22
|
+
},
|
23
|
+
day: {
|
24
|
+
titleFormat: titleFormatDay
|
25
|
+
}
|
26
|
+
},
|
27
|
+
buttonText: {
|
28
|
+
prev: '<',
|
29
|
+
next: '>',
|
30
|
+
month: monthText,
|
31
|
+
week: weekText,
|
32
|
+
day: dayText,
|
33
|
+
today: todayText
|
34
|
+
},
|
35
|
+
dayNames: weekdayNames,
|
36
|
+
dayNamesShort: weekdayShortNames,
|
37
|
+
eventClick: eventClickFunc,
|
38
|
+
events: allEvents
|
39
|
+
})
|
40
|
+
}
|
@@ -0,0 +1,15 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
+
* listed below.
|
4
|
+
*
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, or any plugin's
|
6
|
+
* vendor/assets/stylesheets directory can be referenced here using a relative path.
|
7
|
+
*
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
9
|
+
* compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
|
10
|
+
* files in this directory. Styles in this file should be added after the last require_* statement.
|
11
|
+
* It is generally better to create a new file per style scope.
|
12
|
+
*
|
13
|
+
*= require_tree .
|
14
|
+
*= require_self
|
15
|
+
*/
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require_relative 'concerns/fullcalendar_utility.rb'
|
2
|
+
require_relative 'concerns/zoom_utility.rb'
|
3
|
+
require_relative '../models/concerns/login_module.rb'
|
4
|
+
|
5
|
+
class ApplicationBaseController < ActionController::Base
|
6
|
+
include CommonEngine::FullcalendarUtility
|
7
|
+
include CommonEngine::ZoomUtility
|
8
|
+
|
9
|
+
protect_from_forgery with: :exception
|
10
|
+
|
11
|
+
SELECT_LANGUAGE_MESSAGE = 'Select Language'.freeze
|
12
|
+
|
13
|
+
if !Rails.env.development?
|
14
|
+
rescue_from Exception, with: :handle_500_fatal
|
15
|
+
rescue_from StandardError, with: :handle_500
|
16
|
+
rescue_from ActiveRecord::RecordNotFound, AbstractController::ActionNotFound, with: :handle_404
|
17
|
+
end
|
18
|
+
|
19
|
+
def handle_500_fatal(exception = nil)
|
20
|
+
logger.fatal exception.message if exception
|
21
|
+
render_error 500
|
22
|
+
end
|
23
|
+
def handle_500(exception = nil)
|
24
|
+
logger.error exception.message if exception
|
25
|
+
render_error 500
|
26
|
+
end
|
27
|
+
def handle_404(exception = nil)
|
28
|
+
logger.warn exception.message if exception
|
29
|
+
render_error 404
|
30
|
+
end
|
31
|
+
# called from config/initializers/application_controller_renderer.rb
|
32
|
+
def handle_uncatchable
|
33
|
+
logger.error "Requested: #{request.env['action_dispatch.original_path']}"
|
34
|
+
logger.error request.env['action_dispatch.exception']
|
35
|
+
status = request.path[1..-1].to_i
|
36
|
+
render_error 500
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
def render_error(status)
|
41
|
+
if request.xhr? || params[:format] == :json
|
42
|
+
render :json, status: status
|
43
|
+
else
|
44
|
+
set_locale
|
45
|
+
render template: "errors/error_#{status}", formats: :html, status: status, layout: 'application_base', content_type: 'text/html'
|
46
|
+
end
|
47
|
+
end
|
48
|
+
def set_locale
|
49
|
+
I18n.locale = locale
|
50
|
+
@locale_map = {}
|
51
|
+
I18n.available_locales.each do |available_locale|
|
52
|
+
@locale_map[available_locale.to_s] = t('common.language', locale: available_locale)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
def locale
|
56
|
+
@locale ||= params[:locale] || I18n.default_locale
|
57
|
+
end
|
58
|
+
def default_url_options(options={})
|
59
|
+
options.merge(locale: locale)
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'net/https'
|
3
|
+
require 'uri'
|
4
|
+
require 'jwt'
|
5
|
+
|
6
|
+
module CommonEngine
|
7
|
+
module FullcalendarUtility
|
8
|
+
extend ActiveSupport::Concern
|
9
|
+
|
10
|
+
def prepare_fullcalendar
|
11
|
+
@weekday_names = get_weekday_names().to_json.html_safe
|
12
|
+
@weekday_short_names = get_weekday_short_names().to_json.html_safe
|
13
|
+
@empty_event_title = t('common.empty_event_title')
|
14
|
+
@title_format_month = t('format.fullcalendar.title.month')
|
15
|
+
@title_format_week = t('format.fullcalendar.title.week').html_safe
|
16
|
+
@title_format_day = t('format.fullcalendar.title.day').html_safe
|
17
|
+
@month_text = t('format.fullcalendar.button_text.month')
|
18
|
+
@week_text = t('format.fullcalendar.button_text.week')
|
19
|
+
@day_text = t('format.fullcalendar.button_text.day')
|
20
|
+
@today_text = t('format.fullcalendar.button_text.today')
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
def get_weekday_names
|
25
|
+
return [
|
26
|
+
t('common.weekday_names.Sunday'),
|
27
|
+
t('common.weekday_names.Monday'),
|
28
|
+
t('common.weekday_names.Tuesday'),
|
29
|
+
t('common.weekday_names.Wednesday'),
|
30
|
+
t('common.weekday_names.Thursday'),
|
31
|
+
t('common.weekday_names.Friday'),
|
32
|
+
t('common.weekday_names.Saturday')
|
33
|
+
]
|
34
|
+
end
|
35
|
+
def get_weekday_short_names
|
36
|
+
return [
|
37
|
+
t('common.weekday_names.short.Sunday'),
|
38
|
+
t('common.weekday_names.short.Monday'),
|
39
|
+
t('common.weekday_names.short.Tuesday'),
|
40
|
+
t('common.weekday_names.short.Wednesday'),
|
41
|
+
t('common.weekday_names.short.Thursday'),
|
42
|
+
t('common.weekday_names.short.Friday'),
|
43
|
+
t('common.weekday_names.short.Saturday')
|
44
|
+
]
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,110 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'net/https'
|
3
|
+
require 'uri'
|
4
|
+
require 'jwt'
|
5
|
+
|
6
|
+
module CommonEngine
|
7
|
+
module ZoomUtility
|
8
|
+
extend ActiveSupport::Concern
|
9
|
+
|
10
|
+
ZOOM_PASSWORD = 'asp123'.freeze
|
11
|
+
ZOOM_USER_LAST_NAME = 'AfterSchool-Project'.freeze
|
12
|
+
ZOOM_DATETIME_FORMAT = "%Y-%m-%d'T'%H:%M:%S'Z'".freeze
|
13
|
+
ZOOM_DURATION = 90.freeze
|
14
|
+
|
15
|
+
# see https://zoom.github.io/api/?shell#create-a-user for more information
|
16
|
+
def create_zoom_user(email)
|
17
|
+
url = 'https://api.zoom.us/v2/users'
|
18
|
+
data = {
|
19
|
+
action: 'create',
|
20
|
+
user_info: {
|
21
|
+
email: email,
|
22
|
+
password: ZOOM_PASSWORD,
|
23
|
+
type: 1
|
24
|
+
}
|
25
|
+
}
|
26
|
+
return ActiveSupport::JSON.decode(send_ssl_post(url, data).body)
|
27
|
+
end
|
28
|
+
|
29
|
+
def delete_zoom_user(email)
|
30
|
+
url = 'https://api.zoom.us/v2/users/' + email
|
31
|
+
data = {
|
32
|
+
action: 'delete'
|
33
|
+
}
|
34
|
+
send_ssl_delete(url, data).body
|
35
|
+
end
|
36
|
+
|
37
|
+
# see https://zoom.github.io/api/?shell#create-a-meeting for more information
|
38
|
+
def create_meeting(zoom_user_id, chapter_id, start_datetime)
|
39
|
+
url = 'https://api.zoom.us/v2/users/' + zoom_user_id + '/meetings'
|
40
|
+
chapter = CommonEngine::Chapter.joins(:course).includes(:course).find(chapter_id)
|
41
|
+
data = {
|
42
|
+
topic: chapter.course.name + ' ' + chapter.name,
|
43
|
+
type: 2,
|
44
|
+
start_time: start_datetime.strftime(ZOOM_DATETIME_FORMAT),
|
45
|
+
duration: ZOOM_DURATION,
|
46
|
+
timezone: t('common.time_zone'),
|
47
|
+
password: ZOOM_PASSWORD,
|
48
|
+
settings: {
|
49
|
+
host_video: false,
|
50
|
+
participant_video: false,
|
51
|
+
join_before_host: true,
|
52
|
+
watermark: true,
|
53
|
+
approval_type: 2,
|
54
|
+
audio: 'both',
|
55
|
+
auto_recording: 'none',
|
56
|
+
enforce_login: false
|
57
|
+
}
|
58
|
+
}
|
59
|
+
return ActiveSupport::JSON.decode(send_ssl_post(url, data).body)
|
60
|
+
end
|
61
|
+
|
62
|
+
private
|
63
|
+
def send_ssl_post(url, data={})
|
64
|
+
return send_ssl(url, data, 'POST')
|
65
|
+
end
|
66
|
+
|
67
|
+
def send_ssl_put(url, data={})
|
68
|
+
return send_ssl(url, data, 'PUT')
|
69
|
+
end
|
70
|
+
|
71
|
+
def send_ssl_delete(url, data={})
|
72
|
+
return send_ssl(url, data, 'DELETE')
|
73
|
+
end
|
74
|
+
|
75
|
+
def send_ssl(url, data, method)
|
76
|
+
uri = URI.parse(url)
|
77
|
+
https = Net::HTTP.new(uri.host, uri.port)
|
78
|
+
https.use_ssl = true
|
79
|
+
req = Net::HTTP::Post.new(uri.request_uri) if method == 'POST'
|
80
|
+
req = Net::HTTP::PUT.new(uri.request_uri) if method == 'PUT'
|
81
|
+
req = Net::HTTP::Delete.new(uri.request_uri) if method == 'DELETE'
|
82
|
+
|
83
|
+
# set header
|
84
|
+
req['Content-Type'] = 'application/json'
|
85
|
+
req['Authorization'] = 'Bearer ' + get_token
|
86
|
+
|
87
|
+
# set body
|
88
|
+
req.body = data.to_json
|
89
|
+
return https.request(req)
|
90
|
+
end
|
91
|
+
|
92
|
+
def send_get(url, req_param_hash={})
|
93
|
+
param_string = '?'
|
94
|
+
req_param_hash.each {|key, value| param_string += key.to_s + '=' + value.to_s}
|
95
|
+
param_string += 'access_token=' + get_token
|
96
|
+
uri = URI.parse(url + req_params)
|
97
|
+
return Net::HTTP.get(uri)
|
98
|
+
end
|
99
|
+
|
100
|
+
def get_token
|
101
|
+
api_key = Rails.application.credentials.zoom[:api_key]
|
102
|
+
api_secret = Rails.application.credentials.zoom[:api_secret]
|
103
|
+
payload = {
|
104
|
+
iss: api_key,
|
105
|
+
exp: Time.now.utc.to_i + 60
|
106
|
+
}
|
107
|
+
return JWT.encode payload, api_secret, 'HS256'
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
class ApplicationBaseRecord < ActiveRecord::Base
|
2
|
+
self.abstract_class = true
|
3
|
+
|
4
|
+
def update_opt(*args)
|
5
|
+
set_updated_user_args(*args)
|
6
|
+
set_updated_at
|
7
|
+
begin
|
8
|
+
update(*args)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def save_opt!
|
13
|
+
set_created_user
|
14
|
+
set_updated_user
|
15
|
+
set_updated_at
|
16
|
+
begin
|
17
|
+
self.save!
|
18
|
+
rescue ActiveRecord::RecordNotUnique
|
19
|
+
errors.add :base, 'Could not save because of primary key restriction.'
|
20
|
+
false
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def destroy_opt!
|
25
|
+
set_valid_flg
|
26
|
+
set_updated_user
|
27
|
+
set_updated_at
|
28
|
+
begin
|
29
|
+
self.save
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def set_created_user
|
34
|
+
raise 'Extend this method'
|
35
|
+
end
|
36
|
+
def set_updated_user
|
37
|
+
raise 'Extend this method'
|
38
|
+
end
|
39
|
+
def set_updated_user_args(*args)
|
40
|
+
raise 'Extend this method'
|
41
|
+
end
|
42
|
+
def set_updated_at
|
43
|
+
self.updated_at = Time.now.utc
|
44
|
+
end
|
45
|
+
def set_valid_flg
|
46
|
+
self.valid_flg = true
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require_relative '../concerns/login_module.rb'
|
2
|
+
|
3
|
+
module CommonEngine
|
4
|
+
class Admin < ApplicationRecord
|
5
|
+
include CommonEngine::LoginModule
|
6
|
+
|
7
|
+
default_scope -> {where(valid_flg: false)}
|
8
|
+
has_secure_password validations: true
|
9
|
+
validates :login_id, presence: true, uniqueness: true
|
10
|
+
|
11
|
+
has_many :admin_login_history
|
12
|
+
end
|
13
|
+
end
|