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.
Files changed (98) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/sis/core/application_controller.rb +10 -2
  3. data/app/controllers/sis/core/menus_controller.rb +22 -0
  4. data/app/controllers/sis/core/users_controller.rb +71 -0
  5. data/app/models/sis/core/academic_programme.rb +9 -0
  6. data/app/models/sis/core/academic_year.rb +7 -0
  7. data/app/models/sis/core/applicant.rb +4 -1
  8. data/app/models/sis/core/application.rb +47 -0
  9. data/app/models/sis/core/application_document.rb +10 -0
  10. data/app/models/sis/core/application_module.rb +8 -0
  11. data/app/models/sis/core/application_setup.rb +15 -0
  12. data/app/models/sis/core/course.rb +10 -0
  13. data/app/models/sis/core/course_registration.rb +9 -0
  14. data/app/models/sis/core/document_requirement.rb +10 -0
  15. data/app/models/sis/core/{program_type.rb → document_type.rb} +1 -1
  16. data/app/models/sis/core/exam.rb +15 -0
  17. data/app/models/sis/core/exam_result.rb +25 -0
  18. data/app/models/sis/core/exam_setup.rb +9 -0
  19. data/app/models/sis/core/instructor.rb +6 -0
  20. data/app/models/sis/core/instructor_course.rb +8 -0
  21. data/app/models/sis/core/menu.rb +11 -0
  22. data/app/models/sis/core/programme.rb +7 -0
  23. data/app/models/sis/core/programme_level.rb +6 -0
  24. data/app/models/sis/core/programme_type.rb +6 -0
  25. data/app/models/sis/core/semester.rb +9 -0
  26. data/app/models/sis/core/student.rb +7 -0
  27. data/app/models/sis/core/user.rb +13 -0
  28. data/app/models/sis/core/user_role.rb +10 -0
  29. data/app/services/sis/core/user_service.rb +25 -0
  30. data/app/uploaders/sis/core/application_document_uploader.rb +51 -0
  31. data/app/uploaders/sis/core/photo_uploader.rb +51 -0
  32. data/config/routes.rb +6 -0
  33. data/db/migrate/20200105072142_create_sis_core_academic_years.rb +10 -0
  34. data/db/migrate/20200106072246_create_sis_core_semesters.rb +14 -0
  35. data/db/migrate/20200106130428_create_sis_core_programmes.rb +10 -0
  36. data/db/migrate/20200106132035_create_sis_core_academic_programmes.rb +21 -0
  37. data/db/migrate/20200106132521_create_sis_core_application_setups.rb +19 -0
  38. data/db/migrate/20200106133034_create_sis_core_document_requirements.rb +19 -0
  39. data/db/migrate/20200106133937_create_sis_core_applicants.rb +14 -2
  40. data/db/migrate/20200107094449_create_sis_core_applications.rb +24 -0
  41. data/db/migrate/20200107101638_create_sis_core_application_documents.rb +16 -0
  42. data/db/migrate/20200107302251_create_sis_core_exam_setups.rb +15 -0
  43. data/db/migrate/20200107333411_create_sis_core_exams.rb +17 -0
  44. data/db/migrate/20200107434658_create_sis_core_exam_results.rb +18 -0
  45. data/db/migrate/20200307033100_create_sis_core_courses.rb +19 -0
  46. data/db/migrate/20200307071511_create_sis_core_instructors.rb +10 -0
  47. data/db/migrate/20200307071736_create_sis_core_instructor_courses.rb +16 -0
  48. data/db/migrate/20200307072006_create_sis_core_students.rb +16 -0
  49. data/db/migrate/20200307072317_create_sis_core_course_registrations.rb +20 -0
  50. data/db/migrate/20200507114003_create_sis_core_users.rb +17 -0
  51. data/db/migrate/20200511165121_create_sis_core_application_modules.rb +15 -0
  52. data/db/migrate/20200511165241_create_sis_core_user_roles.rb +15 -0
  53. data/db/migrate/20200511165450_create_sis_core_menus.rb +18 -0
  54. data/lib/authorize_request.rb +18 -0
  55. data/lib/json_web_token.rb +12 -0
  56. data/lib/sis/core/engine.rb +2 -0
  57. data/lib/sis/core/version.rb +1 -1
  58. data/lib/sis_core.rb +5 -0
  59. data/spec/factories/sis/core/academic_programmes.rb +8 -0
  60. data/spec/factories/sis/core/academic_years.rb +6 -0
  61. data/spec/factories/sis/core/applicants.rb +9 -2
  62. data/spec/factories/sis/core/application_documents.rb +7 -0
  63. data/spec/factories/sis/core/application_modules.rb +6 -0
  64. data/spec/factories/sis/core/application_setups.rb +9 -0
  65. data/spec/factories/sis/core/applications.rb +11 -0
  66. data/spec/factories/sis/core/course_registrations.rb +7 -0
  67. data/spec/factories/sis/core/courses.rb +12 -0
  68. data/spec/factories/sis/core/document_requirements.rb +9 -0
  69. data/spec/factories/sis/core/document_types.rb +5 -0
  70. data/spec/factories/sis/core/exam_results.rb +8 -0
  71. data/spec/factories/sis/core/exam_setups.rb +8 -0
  72. data/spec/factories/sis/core/exams.rb +10 -0
  73. data/spec/factories/sis/core/instructor_courses.rb +6 -0
  74. data/spec/factories/sis/core/instructors.rb +6 -0
  75. data/spec/factories/sis/core/menus.rb +9 -0
  76. data/spec/factories/sis/core/programme_levels.rb +5 -0
  77. data/spec/factories/sis/core/programme_types.rb +5 -0
  78. data/spec/factories/sis/core/programmes.rb +6 -0
  79. data/spec/factories/sis/core/semesters.rb +7 -0
  80. data/spec/factories/sis/core/students.rb +9 -0
  81. data/spec/factories/sis/core/user_roles.rb +6 -0
  82. data/spec/factories/sis/core/users.rb +9 -0
  83. metadata +169 -22
  84. data/app/models/sis/core/attached_document.rb +0 -8
  85. data/app/models/sis/core/enrollment_application.rb +0 -9
  86. data/app/models/sis/core/program.rb +0 -9
  87. data/app/models/user.rb +0 -9
  88. data/config/initializers/devise_token_auth.rb +0 -55
  89. data/db/migrate/20200106001016_create_sis_core_field_of_studies.rb +0 -9
  90. data/db/migrate/20200106130428_create_sis_core_programs.rb +0 -10
  91. data/db/migrate/20200108092202_devise_token_auth_create_users.rb +0 -53
  92. data/db/migrate/20200108094449_create_sis_core_enrollment_applications.rb +0 -10
  93. data/db/migrate/20200108101638_create_sis_core_attached_documents.rb +0 -11
  94. data/spec/factories/sis/core/attached_documents.rb +0 -7
  95. data/spec/factories/sis/core/enrollment_applications.rb +0 -7
  96. data/spec/factories/sis/core/field_of_studies.rb +0 -6
  97. data/spec/factories/sis/core/program_types.rb +0 -5
  98. data/spec/factories/sis/core/programs.rb +0 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 860b5c3703e7f2635f2b306b12260ee127ddf01e1811ece50a3498238b1dc1ea
4
- data.tar.gz: 55bfff749f394b9f4b2bd42bd8aba8d66e51fceb55e739927e15aa95101df2c3
3
+ metadata.gz: 7c2e069bab5a79b5ea0e86bc34f9445920cdc3bbf883938f5e2aae454ae38763
4
+ data.tar.gz: d27da2f1dab2dbaceb1d08ac11486f325e9793f9dfdadd8a18bb9aaa4199e33f
5
5
  SHA512:
6
- metadata.gz: e0f255e4d9d7832030d0e7fa4090e184f7118d0675a31d46d81e1e304fc380d8f17efea5d7cf974a6d1ae24516696d23938be5085a09c68a27c133e7a5973b8c
7
- data.tar.gz: 83bdcf9690271a1089381f23b8e78599f609c6ad13e5329efcacbe0c011cbd2d0c49f73298446e7e8bb59e43d99efb5dc94ccbf6d0d88661ff952bdaae4ea56b
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::Base
4
- protect_from_forgery with: :exception
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
@@ -0,0 +1,9 @@
1
+ module Sis
2
+ module Core
3
+ class AcademicProgramme < ApplicationRecord
4
+ belongs_to :programme
5
+ belongs_to :programme_type
6
+ belongs_to :programme_level
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,7 @@
1
+ module Sis
2
+ module Core
3
+ class AcademicYear < ApplicationRecord
4
+ validates :year, presence: true, uniqueness: { case_sensitive: false }
5
+ end
6
+ end
7
+ end
@@ -1,8 +1,11 @@
1
1
  module Sis
2
2
  module Core
3
3
  class Applicant < ApplicationRecord
4
- validates :first_name, :middle_name, :last_name, :email, :phone_number, presence: true
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,10 @@
1
+ module Sis
2
+ module Core
3
+ class ApplicationDocument < ApplicationRecord
4
+ mount_base64_uploader :document, ApplicationDocumentUploader
5
+
6
+ belongs_to :application
7
+ belongs_to :document_requirement
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,8 @@
1
+ module Sis
2
+ module Core
3
+ class ApplicationModule < ApplicationRecord
4
+ has_and_belongs_to_many :users
5
+ validates :code, :name, presence: true
6
+ end
7
+ end
8
+ 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,10 @@
1
+ module Sis
2
+ module Core
3
+ class Course < ApplicationRecord
4
+ belongs_to :program
5
+
6
+ validates :code, :title, :description, :credit_hours, :ects, :lecture_hours, :lab_hours, presence: true
7
+ validates :code, uniqueness: true
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,9 @@
1
+ module Sis
2
+ module Core
3
+ class CourseRegistration < ApplicationRecord
4
+ belongs_to :course
5
+ belongs_to :student
6
+ belongs_to :semester
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,10 @@
1
+ module Sis
2
+ module Core
3
+ class DocumentRequirement < ApplicationRecord
4
+ belongs_to :document_type
5
+ belongs_to :application_setup
6
+
7
+ validates :original, :copy, presence: true
8
+ end
9
+ end
10
+ end
@@ -1,6 +1,6 @@
1
1
  module Sis
2
2
  module Core
3
- class ProgramType < Lookup
3
+ class DocumentType < Lookup
4
4
  end
5
5
  end
6
6
  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,9 @@
1
+ module Sis
2
+ module Core
3
+ class ExamSetup < ApplicationRecord
4
+ belongs_to :application_setup
5
+
6
+ validates :date, :hours, :venue, presence: true
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,6 @@
1
+ module Sis
2
+ module Core
3
+ class Instructor < ApplicationRecord
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,8 @@
1
+ module Sis
2
+ module Core
3
+ class InstructorCourse < ApplicationRecord
4
+ belongs_to :instructor
5
+ belongs_to :course
6
+ end
7
+ end
8
+ 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,7 @@
1
+ module Sis
2
+ module Core
3
+ class Programme < ApplicationRecord
4
+ validates :code, :name, presence: true, uniqueness: true
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,6 @@
1
+ module Sis
2
+ module Core
3
+ class ProgrammeLevel < Lookup
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ module Sis
2
+ module Core
3
+ class ProgrammeType < Lookup
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,9 @@
1
+ module Sis
2
+ module Core
3
+ class Semester < ApplicationRecord
4
+ belongs_to :academic_year
5
+
6
+ validates :name, presence: true
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,7 @@
1
+ module Sis
2
+ module Core
3
+ class Student < ApplicationRecord
4
+ belongs_to :program
5
+ end
6
+ end
7
+ 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
@@ -0,0 +1,10 @@
1
+ module Sis
2
+ module Core
3
+ class UserRole < ApplicationRecord
4
+ validates :name, presence: true
5
+ has_and_belongs_to_many :users
6
+ has_and_belongs_to_many :menus
7
+ belongs_to :application_module
8
+ end
9
+ end
10
+ end