sis_core 1.0.1 → 1.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/sis/core/application_controller.rb +10 -2
- data/app/controllers/sis/core/menus_controller.rb +22 -0
- data/app/controllers/sis/core/users_controller.rb +71 -0
- data/app/models/sis/core/academic_programme.rb +9 -0
- data/app/models/sis/core/academic_year.rb +7 -0
- data/app/models/sis/core/applicant.rb +4 -1
- data/app/models/sis/core/application.rb +47 -0
- data/app/models/sis/core/application_document.rb +10 -0
- data/app/models/sis/core/application_module.rb +8 -0
- data/app/models/sis/core/application_setup.rb +15 -0
- data/app/models/sis/core/course.rb +10 -0
- data/app/models/sis/core/course_registration.rb +9 -0
- data/app/models/sis/core/document_requirement.rb +10 -0
- data/app/models/sis/core/{program_type.rb → document_type.rb} +1 -1
- data/app/models/sis/core/exam.rb +15 -0
- data/app/models/sis/core/exam_result.rb +25 -0
- data/app/models/sis/core/exam_setup.rb +9 -0
- data/app/models/sis/core/instructor.rb +6 -0
- data/app/models/sis/core/instructor_course.rb +8 -0
- data/app/models/sis/core/menu.rb +11 -0
- data/app/models/sis/core/programme.rb +7 -0
- data/app/models/sis/core/programme_level.rb +6 -0
- data/app/models/sis/core/programme_type.rb +6 -0
- data/app/models/sis/core/semester.rb +9 -0
- data/app/models/sis/core/student.rb +7 -0
- data/app/models/sis/core/user.rb +13 -0
- data/app/models/sis/core/user_role.rb +10 -0
- data/app/services/sis/core/user_service.rb +25 -0
- data/app/uploaders/sis/core/application_document_uploader.rb +51 -0
- data/app/uploaders/sis/core/photo_uploader.rb +51 -0
- data/config/routes.rb +6 -0
- data/db/migrate/20200105072142_create_sis_core_academic_years.rb +10 -0
- data/db/migrate/20200106072246_create_sis_core_semesters.rb +14 -0
- data/db/migrate/20200106130428_create_sis_core_programmes.rb +10 -0
- data/db/migrate/20200106132035_create_sis_core_academic_programmes.rb +21 -0
- data/db/migrate/20200106132521_create_sis_core_application_setups.rb +19 -0
- data/db/migrate/20200106133034_create_sis_core_document_requirements.rb +19 -0
- data/db/migrate/20200106133937_create_sis_core_applicants.rb +14 -2
- data/db/migrate/20200107094449_create_sis_core_applications.rb +24 -0
- data/db/migrate/20200107101638_create_sis_core_application_documents.rb +16 -0
- data/db/migrate/20200107302251_create_sis_core_exam_setups.rb +15 -0
- data/db/migrate/20200107333411_create_sis_core_exams.rb +17 -0
- data/db/migrate/20200107434658_create_sis_core_exam_results.rb +18 -0
- data/db/migrate/20200307033100_create_sis_core_courses.rb +19 -0
- data/db/migrate/20200307071511_create_sis_core_instructors.rb +10 -0
- data/db/migrate/20200307071736_create_sis_core_instructor_courses.rb +16 -0
- data/db/migrate/20200307072006_create_sis_core_students.rb +16 -0
- data/db/migrate/20200307072317_create_sis_core_course_registrations.rb +20 -0
- data/db/migrate/20200507114003_create_sis_core_users.rb +17 -0
- data/db/migrate/20200511165121_create_sis_core_application_modules.rb +15 -0
- data/db/migrate/20200511165241_create_sis_core_user_roles.rb +15 -0
- data/db/migrate/20200511165450_create_sis_core_menus.rb +18 -0
- data/lib/authorize_request.rb +18 -0
- data/lib/json_web_token.rb +12 -0
- data/lib/sis/core/engine.rb +2 -0
- data/lib/sis/core/version.rb +1 -1
- data/lib/sis_core.rb +5 -0
- data/spec/factories/sis/core/academic_programmes.rb +8 -0
- data/spec/factories/sis/core/academic_years.rb +6 -0
- data/spec/factories/sis/core/applicants.rb +9 -2
- data/spec/factories/sis/core/application_documents.rb +7 -0
- data/spec/factories/sis/core/application_modules.rb +6 -0
- data/spec/factories/sis/core/application_setups.rb +9 -0
- data/spec/factories/sis/core/applications.rb +11 -0
- data/spec/factories/sis/core/course_registrations.rb +7 -0
- data/spec/factories/sis/core/courses.rb +12 -0
- data/spec/factories/sis/core/document_requirements.rb +9 -0
- data/spec/factories/sis/core/document_types.rb +5 -0
- data/spec/factories/sis/core/exam_results.rb +8 -0
- data/spec/factories/sis/core/exam_setups.rb +8 -0
- data/spec/factories/sis/core/exams.rb +10 -0
- data/spec/factories/sis/core/instructor_courses.rb +6 -0
- data/spec/factories/sis/core/instructors.rb +6 -0
- data/spec/factories/sis/core/menus.rb +9 -0
- data/spec/factories/sis/core/programme_levels.rb +5 -0
- data/spec/factories/sis/core/programme_types.rb +5 -0
- data/spec/factories/sis/core/programmes.rb +6 -0
- data/spec/factories/sis/core/semesters.rb +7 -0
- data/spec/factories/sis/core/students.rb +9 -0
- data/spec/factories/sis/core/user_roles.rb +6 -0
- data/spec/factories/sis/core/users.rb +9 -0
- metadata +169 -22
- data/app/models/sis/core/attached_document.rb +0 -8
- data/app/models/sis/core/enrollment_application.rb +0 -9
- data/app/models/sis/core/program.rb +0 -9
- data/app/models/user.rb +0 -9
- data/config/initializers/devise_token_auth.rb +0 -55
- data/db/migrate/20200106001016_create_sis_core_field_of_studies.rb +0 -9
- data/db/migrate/20200106130428_create_sis_core_programs.rb +0 -10
- data/db/migrate/20200108092202_devise_token_auth_create_users.rb +0 -53
- data/db/migrate/20200108094449_create_sis_core_enrollment_applications.rb +0 -10
- data/db/migrate/20200108101638_create_sis_core_attached_documents.rb +0 -11
- data/spec/factories/sis/core/attached_documents.rb +0 -7
- data/spec/factories/sis/core/enrollment_applications.rb +0 -7
- data/spec/factories/sis/core/field_of_studies.rb +0 -6
- data/spec/factories/sis/core/program_types.rb +0 -5
- data/spec/factories/sis/core/programs.rb +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7c2e069bab5a79b5ea0e86bc34f9445920cdc3bbf883938f5e2aae454ae38763
|
4
|
+
data.tar.gz: d27da2f1dab2dbaceb1d08ac11486f325e9793f9dfdadd8a18bb9aaa4199e33f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e5d24cf81adef27efce96ad29dc9b1bfe5e71adb557d9a1f30d255e78a0979d1c7039e518b4658b1602be5ccb4da9d3d649c33c5bc9f39c052ed4ed032277ad5
|
7
|
+
data.tar.gz: 78c398a895cfb1bcb55fddfe7a6bb097d82dd524e9cbeb8ce1e13f1e9ece68f7660c49753ff86c0d5623fa701a51fe157f76d05912aa3eec40cc62a994d0c474
|
@@ -1,7 +1,15 @@
|
|
1
1
|
module Sis
|
2
2
|
module Core
|
3
|
-
class ApplicationController < ActionController::
|
4
|
-
|
3
|
+
class ApplicationController < ActionController::API
|
4
|
+
before_action :authenticate_request
|
5
|
+
attr_reader :current_user
|
6
|
+
|
7
|
+
private
|
8
|
+
|
9
|
+
def authenticate_request
|
10
|
+
@current_user = AuthorizeRequest.user(request.headers)
|
11
|
+
render json: { error: 'Not Authorized' }, status: 401 unless @current_user
|
12
|
+
end
|
5
13
|
end
|
6
14
|
end
|
7
15
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Sis
|
2
|
+
module Core
|
3
|
+
class MenusController < ApplicationController
|
4
|
+
skip_before_action :authenticate_request, only: [:menu]
|
5
|
+
def menu
|
6
|
+
app_module_id = ApplicationModule.find_by_code(params[:app_module]).id
|
7
|
+
user_roles = User.find(params[:user_id]).user_roles.where(application_module_id: app_module_id)
|
8
|
+
menus = []
|
9
|
+
user_roles.each do |role|
|
10
|
+
user_menus = role.menus.where(parent_id: nil, application_module_id: app_module_id)
|
11
|
+
user_menus.each do |user_menu|
|
12
|
+
children = user_menu.children.where(parent_id: user_menu.id, application_module_id: app_module_id)
|
13
|
+
children = children.map { |c| { label: c.text, icon: c.icon_cls, routerLink: [c.location] } }
|
14
|
+
menus.push({ label: user_menu.text, icon: user_menu.icon_cls, location: user_menu.location,
|
15
|
+
items: children })
|
16
|
+
end
|
17
|
+
end
|
18
|
+
render json: { success: true, data: menus }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
module Sis
|
2
|
+
module Core
|
3
|
+
class UsersController < ApplicationController
|
4
|
+
skip_before_action :authenticate_request, only: %i[login sign_in generate_recovery_token reset_password]
|
5
|
+
before_action :set_user_service, only: %i[generate_recovery_token reset_password]
|
6
|
+
def sign_in
|
7
|
+
applicant = Applicant&.find_by_email(params[:email])
|
8
|
+
if Applicant&.find_by_email(params[:email]) && applicant.authenticate(params[:password])
|
9
|
+
token = JsonWebToken.encode({ id: applicant.id, first_name: applicant.first_name,
|
10
|
+
middle_name: applicant.middle_name, last_name: applicant.last_name,
|
11
|
+
email: applicant.email })
|
12
|
+
render json: { success: true, jwt: token }
|
13
|
+
else
|
14
|
+
render json: { success: false, errors: ['Invalid username or password !'] }
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def create
|
19
|
+
user = User.new(user_params)
|
20
|
+
if user.save
|
21
|
+
render json: { success: true, data: user }
|
22
|
+
else
|
23
|
+
render json: { success: false, errors: user.errors }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def login
|
28
|
+
user = User.find_by_email(params[:email])
|
29
|
+
if User&.find_by_email(params[:email]) && user.authenticate(params[:password])
|
30
|
+
token = JsonWebToken.encode({ id: user.id, first_name: user.first_name, last_name: user.last_name })
|
31
|
+
render json: { success: true, jwt: token }
|
32
|
+
else
|
33
|
+
render json: { success: false, errors: ['Invalid username or password !'] }
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def generate_recovery_token
|
38
|
+
user = User.where(email: params[:email], secret_question_answer: params[:secret_question_answer])
|
39
|
+
if user.count.positive?
|
40
|
+
user = user[0]
|
41
|
+
@service.generate_password_token(user)
|
42
|
+
render json: { success: true, token: user.reset_password_token, email: user.email }
|
43
|
+
else
|
44
|
+
render json: { success: false, errors: ['User not found !'] }
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def reset_password
|
49
|
+
token = params[:token].to_s
|
50
|
+
user = User.find_by_reset_password_token(token)
|
51
|
+
if user && @service.password_token_valid?(user.id)
|
52
|
+
@service.reset_password(user.id, params[:password])
|
53
|
+
render json: { success: true }
|
54
|
+
else
|
55
|
+
render json: { success: false, errors: ['Link not valid or expired. Try generating a new link !'] }
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
def user_params
|
62
|
+
params.require('user').permit(:id, :first_name, :last_name, :email, :password, :reset_password_token,
|
63
|
+
:reset_password_sent_at, :secret_question, :secret_question_answer)
|
64
|
+
end
|
65
|
+
|
66
|
+
def set_user_service
|
67
|
+
@service = UserService.new
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -1,8 +1,11 @@
|
|
1
1
|
module Sis
|
2
2
|
module Core
|
3
3
|
class Applicant < ApplicationRecord
|
4
|
-
|
4
|
+
mount_base64_uploader :photo, PhotoUploader
|
5
|
+
validates :first_name, :middle_name, :last_name, :email, presence: true
|
5
6
|
validates :email, uniqueness: true
|
7
|
+
|
8
|
+
has_secure_password
|
6
9
|
end
|
7
10
|
end
|
8
11
|
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module Sis
|
2
|
+
module Core
|
3
|
+
class Application < ApplicationRecord
|
4
|
+
include AASM
|
5
|
+
|
6
|
+
# Gender types
|
7
|
+
MALE = 'Male'.freeze
|
8
|
+
FEMALE = 'Female'.freeze
|
9
|
+
|
10
|
+
aasm column: :status do
|
11
|
+
state :draft, initial: true
|
12
|
+
state :submitted, :under_review, :accepted, :rejected, :selected_for_exam, :selected_for_admission
|
13
|
+
|
14
|
+
event :submit do
|
15
|
+
transitions from: :draft, to: :submitted
|
16
|
+
end
|
17
|
+
|
18
|
+
event :review do
|
19
|
+
transitions from: %i[submitted rejected accepted], to: :under_review
|
20
|
+
end
|
21
|
+
|
22
|
+
event :accept do
|
23
|
+
transitions from: :under_review, to: :accepted
|
24
|
+
end
|
25
|
+
|
26
|
+
event :reject do
|
27
|
+
transitions from: :under_review, to: :rejected
|
28
|
+
end
|
29
|
+
|
30
|
+
event :select_for_exam do
|
31
|
+
transitions from: :accepted, to: :selected_for_exam
|
32
|
+
end
|
33
|
+
|
34
|
+
event :select_for_admission do
|
35
|
+
transitions from: :selected_for_exam, to: :selected_for_admission
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
validates :status, presence: true
|
40
|
+
validates :payment_information, presence: true, if: :payment_made
|
41
|
+
|
42
|
+
belongs_to :applicant
|
43
|
+
belongs_to :academic_programme
|
44
|
+
belongs_to :application_setup
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Sis
|
2
|
+
module Core
|
3
|
+
class ApplicationSetup < ApplicationRecord
|
4
|
+
OPEN = 'Open'.freeze
|
5
|
+
CLOSED = 'Closed'.freeze
|
6
|
+
|
7
|
+
belongs_to :academic_programme
|
8
|
+
belongs_to :target_semester, class_name: 'Sis::Core::Semester'
|
9
|
+
has_many :document_requirements
|
10
|
+
|
11
|
+
validates :start_date, :end_date, :status, presence: true
|
12
|
+
validates :status, inclusion: [OPEN, CLOSED]
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Sis
|
2
|
+
module Core
|
3
|
+
class Exam < ApplicationRecord
|
4
|
+
belongs_to :exam_setup
|
5
|
+
|
6
|
+
validates :title, :start, :finish, :pass_point, :points, presence: true
|
7
|
+
|
8
|
+
before_validation :set_pass_point
|
9
|
+
|
10
|
+
def set_pass_point
|
11
|
+
self.pass_point = points / 2 unless pass_point || !points
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Sis
|
2
|
+
module Core
|
3
|
+
class ExamResult < ApplicationRecord
|
4
|
+
PASS = 'Pass'.freeze
|
5
|
+
FAIL = 'Fail'.freeze
|
6
|
+
|
7
|
+
belongs_to :exam
|
8
|
+
belongs_to :application
|
9
|
+
|
10
|
+
validates :points, presence: true
|
11
|
+
validates_uniqueness_of :application_id, scope: %i[exam_id]
|
12
|
+
|
13
|
+
|
14
|
+
before_validation :set_status
|
15
|
+
|
16
|
+
def set_status
|
17
|
+
self.status = if exam && exam.pass_point >= points
|
18
|
+
PASS
|
19
|
+
else
|
20
|
+
FAIL
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module Sis
|
2
|
+
module Core
|
3
|
+
class Menu < ApplicationRecord
|
4
|
+
has_and_belongs_to_many :user_roles
|
5
|
+
belongs_to :application_module
|
6
|
+
belongs_to :parent, class_name: 'Sis::Core::Menu', optional: true
|
7
|
+
has_many :children, class_name: 'Sis::Core::Menu', foreign_key: 'parent_id'
|
8
|
+
validates :text, presence: true
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Sis
|
2
|
+
module Core
|
3
|
+
class User < ApplicationRecord
|
4
|
+
validates :first_name, :last_name, :email, presence: true
|
5
|
+
validates :password, presence: true, on: :create
|
6
|
+
validates :email, uniqueness: true
|
7
|
+
has_and_belongs_to_many :application_modules
|
8
|
+
has_and_belongs_to_many :user_roles
|
9
|
+
|
10
|
+
has_secure_password
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|