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

Commit

Permalink
Merge pull request #512 from omu/develop
Browse files Browse the repository at this point in the history
Merge develop into master
  • Loading branch information
msdundar authored Nov 9, 2018
2 parents 9c14321 + 7ffbe1a commit 96c0f35
Show file tree
Hide file tree
Showing 62 changed files with 799 additions and 123 deletions.
29 changes: 24 additions & 5 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ jobs:
key: nokul-yarn-{{ checksum "yarn.lock" }}
paths:
- node_modules/
rake_test:
test_suite:
<<: *ruby_2_5_1
steps:
- restore_cache:
Expand All @@ -108,8 +108,20 @@ jobs:
- run: bundle install
- run: bin/yarn install
- run: bundle exec rake quality:rails
- run: bundle exec rake security:all
- run: bin/yarn run lint
security:
<<: *ruby_2_5_1
steps:
- restore_cache:
<<: *repository
- restore_cache:
<<: *restore_bundle
- restore_cache:
<<: *restore_yarn
- run: bundle --path vendor/bundle --without development
- run: bundle install
- run: bin/yarn install
- run: bundle exec rake security:all
deploy_develop:
machine:
enabled: true
Expand All @@ -120,7 +132,7 @@ jobs:
command: |
git remote add develop [email protected]:nokul-develop &&
git push develop develop:master
deploy:
deploy_master:
machine:
enabled: true
steps:
Expand All @@ -143,21 +155,28 @@ workflows:
- bundle_assets:
requires:
- bundle_dependencies
- rake_test:
- test_suite:
requires:
- bundle_assets
- karma:
requires:
- bundle_assets
- security:
requires:
- bundle_assets
- deploy_develop:
requires:
- test_suite
- karma
- security
filters:
branches:
only: develop
- deploy:
- deploy_master:
requires:
- test_suite
- karma
- security
filters:
branches:
only: master
14 changes: 7 additions & 7 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ GEM
tzinfo (~> 1.1)
addressable (2.5.2)
public_suffix (>= 2.0.2, < 4.0)
ancestry (3.0.4)
ancestry (3.0.5)
activerecord (>= 3.2.0)
archive-zip (0.11.0)
io-like (~> 0.3.0)
arel (9.0.0)
ast (2.4.0)
aws-eventstream (1.0.1)
aws-partitions (1.107.0)
aws-sdk-core (3.36.0)
aws-partitions (1.110.0)
aws-sdk-core (3.37.0)
aws-eventstream (~> 1.0)
aws-partitions (~> 1.0)
aws-sigv4 (~> 1.0)
Expand Down Expand Up @@ -96,7 +96,7 @@ GEM
codacy-coverage (2.1.0)
simplecov
coderay (1.1.2)
concurrent-ruby (1.1.1)
concurrent-ruby (1.1.3)
connection_pool (2.2.2)
crack (0.4.3)
safe_yaml (~> 1.0.0)
Expand Down Expand Up @@ -169,7 +169,7 @@ GEM
nokogiri (1.8.5)
mini_portile2 (~> 2.3.0)
orm_adapter (0.5.0)
pagy (0.21.0)
pagy (0.22.0)
parallel (1.12.1)
parser (2.5.3.0)
ast (~> 2.4.0)
Expand All @@ -182,7 +182,7 @@ GEM
pry (0.12.0)
coderay (~> 1.1.0)
method_source (~> 0.9.0)
pry-rails (0.3.6)
pry-rails (0.3.7)
pry (>= 0.10.4)
public_suffix (3.0.3)
puma (3.12.0)
Expand Down Expand Up @@ -253,7 +253,7 @@ GEM
selenium-webdriver (3.141.0)
childprocess (~> 0.5)
rubyzip (~> 1.2, >= 1.2.2)
sidekiq (5.2.2)
sidekiq (5.2.3)
connection_pool (~> 2.2, >= 2.2.2)
rack-protection (>= 1.5.0)
redis (>= 3.3.5, < 5)
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/calendar/academic_terms_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class AcademicTermsController < ApplicationController
before_action :set_academic_term, only: %i[edit update destroy]

def index
@academic_terms = pagy_by_search(AcademicTerm.order(:year))
@academic_terms = pagy_by_search(AcademicTerm.order(:year, :term))
end

def new
Expand Down Expand Up @@ -40,7 +40,7 @@ def set_academic_term
end

def academic_term_params
params.require(:academic_term).permit(:year, :term)
params.require(:academic_term).permit(:year, :term, :start_of_term, :end_of_term, :active)
end
end
end
2 changes: 1 addition & 1 deletion app/controllers/calendar/calendar_titles_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def set_calendar_title
end

def calendar_title_params
params.require(:calendar_title).permit(:name)
params.require(:calendar_title).permit(:name, type_ids: [])
end
end
end
3 changes: 1 addition & 2 deletions app/controllers/calendar/calendar_types_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ def set_calendar_type
end

def calendar_type_params
params.require(:calendar_type)
.permit(:name, calendar_title_types_attributes: %i[id type_id title_id status _destroy])
params.require(:calendar_type).permit(:name)
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# frozen_string_literal: true

module CourseManagement
class CurriculumSemesterCoursesController < ApplicationController
before_action :set_semester, only: %i[new create edit update destroy]
before_action :set_semester_course, only: %i[edit update destroy]

def new
@semester_course = @semester.curriculum_semester_courses.new
end

def edit; end

def create
@semester_course = @semester.curriculum_semester_courses.new(semester_course_params)
@semester_course.save ? redirect_with('success') : render(:new)
end

def update
@semester_course.update(semester_course_params) ? redirect_with('success') : render(:edit)
end

def destroy
message = @semester_course.destroy ? 'success' : 'error'
redirect_with(message)
end

private

def redirect_with(message)
redirect_to curriculum_path(@semester.curriculum), flash: { notice: t(".#{message}") }
end

def set_semester_course
@semester_course = @semester.curriculum_semester_courses.find(params[:id])
end

def set_semester
@semester = CurriculumSemester.find(params[:curriculum_semester_id])
end

def semester_course_params
params.require(:curriculum_semester_course).permit(:course_id, :ects)
end
end
end
11 changes: 9 additions & 2 deletions app/controllers/course_management/curriculums_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ def index
@pagy, @curriculums = pagy(curriculums)
end

def show; end
def show
@semesters = @curriculum.semesters.includes(
curriculum_semester_courses: :course
)
end

def new
@curriculum = Curriculum.new
Expand Down Expand Up @@ -46,7 +50,10 @@ def set_curriculum
end

def curriculum_params
params.require(:curriculum).permit(:name, :unit_id, :number_of_semesters, :status, program_ids: [])
params.require(:curriculum).permit(
:name, :unit_id, :status, program_ids: [],
semesters_attributes: %i[id name sequence _destroy]
)
end
end
end
3 changes: 3 additions & 0 deletions app/models/academic_calendar.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,7 @@ class AcademicCalendar < ApplicationRecord

# delegates
delegate :name, to: :calendar_type, prefix: :type

# scopes
scope :active, -> { joins(:academic_term).merge(AcademicTerm.where(active: true)) }
end
3 changes: 3 additions & 0 deletions app/models/academic_term.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
class AcademicTerm < ApplicationRecord
# relations
has_many :academic_calendars, dependent: :nullify
has_many :calendar_events, through: :academic_calendars

# validations
validates :term, presence: true
validates :year, presence: true, uniqueness: { scope: :term }
validates :start_of_term, presence: true
validates :end_of_term, presence: true

# enums
enum term: { fall: 0, spring: 1, summer: 2 }
Expand Down
1 change: 1 addition & 0 deletions app/models/calendar_event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class CalendarEvent < ApplicationRecord
# relations
belongs_to :academic_calendar
belongs_to :calendar_title
has_one :term, through: :academic_calendar, source: :academic_term

# validations
validates :start_date, presence: true
Expand Down
1 change: 0 additions & 1 deletion app/models/calendar_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ class CalendarType < ApplicationRecord
has_many :calendar_title_types, foreign_key: :type_id, inverse_of: :type, dependent: :destroy
has_many :titles, through: :calendar_title_types
has_many :academic_calendars, dependent: :destroy
accepts_nested_attributes_for :calendar_title_types, reject_if: :all_blank, allow_destroy: true

# validations
validates :name, presence: true, uniqueness: true
Expand Down
12 changes: 7 additions & 5 deletions app/models/curriculum.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ class Curriculum < ApplicationRecord
include PgSearch
include DynamicSearch

MAX_NUMBER_OF_SEMESTERS = 12

pg_search_scope(
:search,
against: %i[name],
Expand All @@ -20,12 +18,16 @@ class Curriculum < ApplicationRecord
belongs_to :unit
has_many :unit_curriculums, dependent: :destroy
has_many :programs, through: :unit_curriculums, source: :unit
has_many :semesters, class_name: 'CurriculumSemester',
inverse_of: :curriculum, dependent: :destroy
has_many :courses, through: :semesters

# nested models
accepts_nested_attributes_for :semesters, reject_if: :all_blank, allow_destroy: true

# validations
validates :name, presence: true, uniqueness: { scope: :unit_id }
validates :number_of_semesters, numericality: {
greater_than: 0, less_than_or_equal_to: MAX_NUMBER_OF_SEMESTERS
}
validates :semesters_count, numericality: { greater_than_or_equal_to: 0 }
validates :status, presence: true

# enumerations
Expand Down
19 changes: 19 additions & 0 deletions app/models/curriculum_semester.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# frozen_string_literal: true

class CurriculumSemester < ApplicationRecord
# relations
has_many :curriculum_semester_courses, dependent: :destroy
has_many :courses, through: :curriculum_semester_courses
belongs_to :curriculum, counter_cache: :semesters_count, inverse_of: :semesters

# validations
validates :name, presence: true, uniqueness: { scope: :curriculum_id }
validates :sequence, numericality: { greater_than: 0 }, uniqueness: { scope: :curriculum_id }

# custom methods
def available_courses(add_courses: [])
courses = curriculum.unit.courses.active.where.not(id: curriculum.courses.ids)
add_courses.compact!
add_courses.present? ? (courses.to_a + add_courses) : courses
end
end
13 changes: 13 additions & 0 deletions app/models/curriculum_semester_course.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

class CurriculumSemesterCourse < ApplicationRecord
# relations
belongs_to :course
belongs_to :curriculum_semester

# validations
validates :ects, presence: true, numericality: { greater_than: 0 }

# delegates
delegate :code, :credit, :name, to: :course
end
11 changes: 7 additions & 4 deletions app/services/xokul/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,19 @@ module Connection
private_constant :BASE_URL, :BEARER_TOKEN

# rubocop:disable Metrics/MethodLength
def self.request(path, params: {})
def self.request(path, params: {}, **http_options)
http_options[:open_timeout] ||= http_options[:read_timeout] ||= 5 if Rails.env.test?

response = RestClient.get(
URI.join(BASE_URL, path).to_s,
headers: {
Authorization: "Bearer #{BEARER_TOKEN}",
'Content-Type': 'application/json'
'Authorization' => "Bearer #{BEARER_TOKEN}",
'Content-Type' => 'application/json'
},
payload: params.to_json,
use_ssl: true,
verify_mode: OpenSSL::SSL::VERIFY_PEER
verify_mode: OpenSSL::SSL::VERIFY_PEER,
**http_options
)

response.error!
Expand Down
5 changes: 4 additions & 1 deletion app/services/xokul/yoksis/staff.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ def nationalities
end

def pages(page:)
Connection.request '/yoksis/staff/pages', params: { page: page }
Connection.request(
'/yoksis/staff/pages',
params: { page: page }, read_timeout: 15
)
end

def total_pages
Expand Down
3 changes: 2 additions & 1 deletion app/services/xokul/yoksis/units.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ module Units

def changes(day:, month:, year:)
Connection.request(
'/yoksis/units/changes', params: { day: day, month: month, year: year }
'/yoksis/units/changes',
params: { day: day, month: month, year: year }, read_timeout: 10
)
end

Expand Down
2 changes: 1 addition & 1 deletion app/views/account/employees/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
label_method: lambda { |title| title.name + ' - ' + title.branch } %>
</div>
<div class='form-group col-sm-12'>
<%= f.input :active %>
<%= f.input :active, label: t('active') %>
</div>
<div class='form-group col-sm-12'>
<%= f.button :submit, class: 'btn btn-outline-success btn-sm' %>
Expand Down
Loading

0 comments on commit 96c0f35

Please sign in to comment.