-
Notifications
You must be signed in to change notification settings - Fork 172
Adding date_format_pref field for new user #247
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,12 +5,12 @@ class Role < ApplicationRecord | |
| belongs_to :parent, class_name: 'Role', optional: true | ||
| has_many :users, dependent: :nullify | ||
|
|
||
| # Role IDs | ||
| STUDENT_ID = 1 | ||
| TEACHING_ASSISTANT_ID = 2 | ||
| # Role IDs (must match db/seeds.rb) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should there be a db table with these correspondences? |
||
| SUPER_ADMINISTRATOR_ID = 1 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could this just be SUPER_ADMINISTRATOR, etc.? All files would need to be refactored to effect this change, but it would enhance readability. But, would it lead to namespace conflicts? If it doesn't cause name conflicts, it would be worth doing. |
||
| ADMINISTRATOR_ID = 2 | ||
| INSTRUCTOR_ID = 3 | ||
| ADMINISTRATOR_ID = 4 | ||
| SUPER_ADMINISTRATOR_ID = 5 | ||
| TEACHING_ASSISTANT_ID = 4 | ||
| STUDENT_ID = 5 | ||
|
|
||
| def super_administrator? | ||
| name['Super Administrator'] | ||
|
|
@@ -67,4 +67,4 @@ def as_json(options = nil) | |
| options = options || {} # Ensure options is a hash | ||
| super(options.merge({ only: %i[id name parent_id] })) | ||
| end | ||
| end | ||
| end | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add an EOL |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,11 +21,11 @@ class User < ApplicationRecord | |
| has_many :teams, through: :teams_users | ||
| has_many :participants | ||
|
|
||
| scope :students, -> { where role_id: Role::STUDENT } | ||
| scope :tas, -> { where role_id: Role::TEACHING_ASSISTANT } | ||
| scope :instructors, -> { where role_id: Role::INSTRUCTOR } | ||
| scope :administrators, -> { where role_id: Role::ADMINISTRATOR } | ||
| scope :superadministrators, -> { where role_id: Role::SUPER_ADMINISTRATOR } | ||
| scope :students, -> { where role_id: Role::STUDENT_ID } | ||
| scope :tas, -> { where role_id: Role::TEACHING_ASSISTANT_ID } | ||
| scope :instructors, -> { where role_id: Role::INSTRUCTOR_ID } | ||
| scope :administrators, -> { where role_id: Role::ADMINISTRATOR_ID } | ||
| scope :superadministrators, -> { where role_id: Role::SUPER_ADMINISTRATOR_ID } | ||
|
|
||
| delegate :student?, to: :role | ||
| delegate :ta?, to: :role | ||
|
|
@@ -34,17 +34,17 @@ class User < ApplicationRecord | |
| delegate :super_administrator?, to: :role | ||
|
|
||
| def self.instantiate(record) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please refactor, according to the recommendations in https://chatgpt.com/share/694abed0-f590-800d-ac2a-4d87911c5de3. |
||
| case record.role | ||
| when Role::TEACHING_ASSISTANT | ||
| case record.role_id | ||
| when Role::TEACHING_ASSISTANT_ID | ||
| record.becomes(Ta) | ||
| when Role::INSTRUCTOR | ||
| when Role::INSTRUCTOR_ID | ||
| record.becomes(Instructor) | ||
| when Role::ADMINISTRATOR | ||
| when Role::ADMINISTRATOR_ID | ||
| record.becomes(Administrator) | ||
| when Role::SUPER_ADMINISTRATOR | ||
| when Role::SUPER_ADMINISTRATOR_ID | ||
| record.becomes(SuperAdministrator) | ||
| else | ||
| super | ||
| record | ||
| end | ||
| end | ||
|
|
||
|
|
@@ -72,10 +72,10 @@ def reset_password | |
| # Get instructor_id of the user, if the user is TA, | ||
| # return the id of the instructor else return the id of the user for superior roles | ||
| def instructor_id | ||
| case role | ||
| when Role::INSTRUCTOR, Role::ADMINISTRATOR, Role::SUPER_ADMINISTRATOR | ||
| case role_id | ||
| when Role::INSTRUCTOR_ID, Role::ADMINISTRATOR_ID, Role::SUPER_ADMINISTRATOR_ID | ||
| id | ||
| when Role::TEACHING_ASSISTANT | ||
| when Role::TEACHING_ASSISTANT_ID | ||
| my_instructor | ||
| else | ||
| raise NotImplementedError, "Unknown role: #{role.name}" | ||
|
|
@@ -153,4 +153,4 @@ def generate_jwt | |
| JWT.encode({ id: id, exp: 60.days.from_now.to_i }, Rails.application.credentials.secret_key_base) | ||
| end | ||
|
|
||
| end | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| class AddDateFormatPrefToUsers < ActiveRecord::Migration[8.0] | ||
| def change | ||
| add_column :users, :date_format_pref, :string, default: "mm/dd/yyyy" | ||
| end | ||
| end |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of using the disjunction in a lot of action_allowed methods, I believe there is a has_instructor_privileges? method that implements the disjunction.