Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
EIP
Project Forum
Project Forum
Commits
64fabc9a
Commit
64fabc9a
authored
Jul 27, 2022
by
Taico Aerts
Browse files
Merge branch 'development' into 'master'
Project Forum Release 2.8.1 See merge request
!776
parents
22696700
eede4776
Changes
170
Hide whitespace changes
Inline
Side-by-side
app/models/concerns/user_concerns/roleable.rb
View file @
64fabc9a
...
...
@@ -12,6 +12,8 @@ module UserConcerns
enum
role:
{
role_company:
0
,
role_student:
1
,
role_staff:
2
,
role_admin:
3
}
enum
student_type:
{
regular:
0
,
tnw_double_bachelor:
1
,
tnw_1_bridging:
2
,
tnw_2_bridging:
3
}
has_many
:users_roles
,
dependent: :delete_all
before_validation
:assign_dynamic_attributes
after_initialize
:assign_dynamic_attributes
...
...
app/models/experiment_project.rb
View file @
64fabc9a
...
...
@@ -13,6 +13,12 @@ class ExperimentProject < ApplicationRecord
has_many
:images
,
as: :imageable
,
dependent: :destroy
accepts_nested_attributes_for
:images
,
allow_destroy:
true
belongs_to
:original_experiment_project
,
optional:
true
,
inverse_of: :copies
has_many
:copies
,
inverse_of: :original_experiment_project
,
class_name:
'ExperimentProject'
,
foreign_key:
'original_experiment_project_id'
,
dependent: :nullify
scope
:sort_by_priority
,
(
lambda
{
|
user
,
course_edition
|
subquery
=
ExperimentPreference
.
where
(
user:
user
)
# TODO: The ExperimentPreference should be linked to the course edition, and this query should be updated accordingly as well
...
...
app/models/project.rb
View file @
64fabc9a
...
...
@@ -23,7 +23,11 @@ class Project < ApplicationRecord
has_many
:images
,
as: :imageable
,
dependent: :destroy
accepts_nested_attributes_for
:images
,
allow_destroy:
true
belongs_to
:original_project
,
optional:
true
,
class_name:
'Project'
belongs_to
:original_project
,
optional:
true
,
class_name:
'Project'
,
inverse_of: :copies
has_many
:copies
,
inverse_of: :original_project
,
class_name:
'Project'
,
foreign_key: :original_project_id
,
dependent: :nullify
# ===== Groups and members =====
...
...
app/models/role.rb
View file @
64fabc9a
class
Role
<
ApplicationRecord
scopify
# This is a fake relation which is emulated by the rolify gem. Adding a dependent breaks deletion.
# rubocop:disable Rails/HasManyOrHasOneDependent
has_many
:users_roles
# rubocop:enable Rails/HasManyOrHasOneDependent
# The users_roles table does not have ids, which prevents normal cascading deletion with dependent destroy.
# Instead, we use delete_all, which will drop all the associated records directly from the database.
# This relies on users_role not having any callbacks.
has_many
:users_roles
,
dependent: :delete_all
has_many
:users
,
through: :users_roles
belongs_to
:resource
,
...
...
app/models/user.rb
View file @
64fabc9a
...
...
@@ -62,7 +62,7 @@ class User < ApplicationRecord
has_many
:courses
,
through: :course_editions
has_many
:memberships
,
dependent: :
nullif
y
has_many
:memberships
,
dependent: :
destro
y
has_many
:groups
,
through: :memberships
has_many
:participating_projects
,
through: :groups
,
...
...
app/models/user_course_specific_role.rb
View file @
64fabc9a
...
...
@@ -11,9 +11,10 @@ class UserCourseSpecificRole < ApplicationRecord
after_destroy
:remove_coach_role
after_save
:add_coach_role
#
Handle roles assigned to unregistered users
#
Rename the belongs_to :user to real_user to make it accessible.
alias
real_user
user
# Handle roles assigned to unregistered users
def
user
return
real_user
if
real_user
...
...
app/models/users_role.rb
View file @
64fabc9a
...
...
@@ -3,4 +3,8 @@ class UsersRole < ApplicationRecord
belongs_to
:role
validates
:role
,
uniqueness:
{
scope: :user
}
# IMPORTANT: users_role does not have a primary key (id). Deletion of a role does a destroy_all
# on the associated users_roles, which skips running callbacks. Therefore, do not
# define any callbacks here which should trigger after deletion.
end
db/migrate/20170504122931_devise_create_users.rb
deleted
100644 → 0
View file @
22696700
##
# Creates the user table.
class
DeviseCreateUsers
<
ActiveRecord
::
Migration
[
5.1
]
def
change
create_table
:users
do
|
t
|
## Database authenticatable
t
.
string
:email
,
null:
false
,
default:
''
t
.
string
:encrypted_password
,
null:
false
,
default:
''
## Recoverable
t
.
string
:reset_password_token
t
.
datetime
:reset_password_sent_at
## Rememberable
t
.
datetime
:remember_created_at
## Trackable
t
.
integer
:sign_in_count
,
default:
0
,
null:
false
t
.
datetime
:current_sign_in_at
t
.
datetime
:last_sign_in_at
t
.
string
:current_sign_in_ip
t
.
string
:last_sign_in_ip
## Confirmable
t
.
string
:confirmation_token
t
.
datetime
:confirmed_at
t
.
datetime
:confirmation_sent_at
t
.
string
:unconfirmed_email
## Lockable
t
.
integer
:failed_attempts
,
default:
0
,
null:
false
t
.
string
:unlock_token
t
.
datetime
:locked_at
t
.
timestamps
null:
false
end
add_index
:users
,
:email
,
unique:
true
add_index
:users
,
:reset_password_token
,
unique:
true
add_index
:users
,
:confirmation_token
,
unique:
true
add_index
:users
,
:unlock_token
,
unique:
true
end
end
db/migrate/20170509110911_rolify_create_roles.rb
deleted
100644 → 0
View file @
22696700
##
# Creates Rolify roles.
class
RolifyCreateRoles
<
ActiveRecord
::
Migration
[
5.1
]
def
change
create_table
(
:roles
)
do
|
t
|
t
.
string
:name
t
.
references
:resource
,
polymorphic:
true
t
.
timestamps
end
create_table
(
:users_roles
,
id:
false
)
do
|
t
|
t
.
references
:user
t
.
references
:role
end
add_index
(
:roles
,
:name
)
add_index
(
:roles
,
%i[name resource_type resource_id]
)
add_index
(
:users_roles
,
%i[user_id role_id]
)
end
end
db/migrate/20170509135523_add_personal_information_to_user.rb
deleted
100644 → 0
View file @
22696700
##
# Add column +first_name+ +last_name+ and +authorization_level+ to User table.
class
AddPersonalInformationToUser
<
ActiveRecord
::
Migration
[
5.1
]
def
change
add_column
:users
,
:first_name
,
:string
add_column
:users
,
:last_name
,
:string
add_column
:users
,
:authorization_level
,
:integer
end
end
db/migrate/20170509140941_create_course_configurations.rb
deleted
100644 → 0
View file @
22696700
##
# Creates CourseConfiguration table.
class
CreateCourseConfigurations
<
ActiveRecord
::
Migration
[
5.1
]
def
change
create_table
:course_configurations
do
|
t
|
t
.
integer
:course_configurable_id
t
.
string
:course_configurable_type
t
.
integer
:min_group_size
,
null:
false
,
default:
1
t
.
integer
:max_group_size
,
null:
false
,
default:
1
t
.
integer
:min_number_of_groups
,
null:
false
,
default:
1
t
.
integer
:max_number_of_groups
,
null:
false
,
default:
1
t
.
timestamps
end
add_index
:course_configurations
,
%i[course_configurable_id course_configurable_type]
,
name:
'index_course_configurations_on_course_configurable'
,
unique:
true
end
end
db/migrate/20170509141130_create_courses.rb
deleted
100644 → 0
View file @
22696700
##
# Creates Course table.
class
CreateCourses
<
ActiveRecord
::
Migration
[
5.1
]
def
change
create_table
:courses
do
|
t
|
t
.
string
:name
,
null:
false
t
.
timestamps
end
end
end
db/migrate/20170509142534_create_course_editions.rb
deleted
100644 → 0
View file @
22696700
##
# Creates CourseEdition table.
class
CreateCourseEditions
<
ActiveRecord
::
Migration
[
5.1
]
def
change
create_table
:course_editions
do
|
t
|
t
.
string
:name
t
.
references
:course
,
index:
true
t
.
integer
:status
t
.
date
:starts_at
t
.
date
:ends_at
t
.
timestamps
t
.
text
:description
end
end
end
db/migrate/20170509142650_create_course_participations.rb
deleted
100644 → 0
View file @
22696700
##
# Creates CourseParticipation table.
class
CreateCourseParticipations
<
ActiveRecord
::
Migration
[
5.1
]
def
change
create_table
:course_participations
do
|
t
|
t
.
references
:user
,
index:
true
t
.
references
:course_edition
,
index:
true
t
.
integer
:status
t
.
timestamps
end
add_index
:course_participations
,
%i[user_id course_edition_id]
end
end
db/migrate/20170509195643_create_course_participation_requests.rb
deleted
100644 → 0
View file @
22696700
##
# Creates CrouseParticipationRequest table
class
CreateCourseParticipationRequests
<
ActiveRecord
::
Migration
[
5.1
]
def
change
create_table
:course_participation_requests
do
|
t
|
t
.
references
:course_participation
,
index:
{
unique:
true
}
t
.
text
:description
t
.
text
:circumstances
t
.
text
:planning
t
.
timestamps
end
end
end
db/migrate/20170511083255_create_companies.rb
deleted
100644 → 0
View file @
22696700
##
# Creates Company table.
class
CreateCompanies
<
ActiveRecord
::
Migration
[
5.1
]
def
change
create_table
:companies
do
|
t
|
t
.
string
:name
t
.
text
:description
t
.
string
:email
t
.
string
:phone
t
.
string
:city
t
.
string
:street
t
.
string
:house_number
t
.
string
:postal_code
t
.
string
:country
t
.
string
:website_url
t
.
string
:linkedin_url
t
.
timestamps
end
end
end
db/migrate/20170511083730_create_projects.rb
deleted
100644 → 0
View file @
22696700
##
# Creates Project table.
class
CreateProjects
<
ActiveRecord
::
Migration
[
5.1
]
def
change
create_table
:projects
do
|
t
|
t
.
string
:name
t
.
text
:description
t
.
integer
:status
t
.
references
:company
,
index:
true
t
.
references
:course_edition
,
index:
true
t
.
string
:presentation_location
t
.
datetime
:presented_at
t
.
timestamps
end
end
end
db/migrate/20170511092641_create_groups.rb
deleted
100644 → 0
View file @
22696700
##
# Creates Group table.
class
CreateGroups
<
ActiveRecord
::
Migration
[
5.1
]
def
change
create_table
:groups
do
|
t
|
t
.
integer
:status
t
.
references
:project_edition
,
index:
true
t
.
references
:project
,
index:
true
t
.
timestamps
end
end
end
db/migrate/20170511092957_create_memberships.rb
deleted
100644 → 0
View file @
22696700
##
# Creates Membership table.
class
CreateMemberships
<
ActiveRecord
::
Migration
[
5.1
]
def
change
create_table
:memberships
do
|
t
|
t
.
references
:user
,
index:
true
t
.
references
:group
,
index:
true
t
.
integer
:role
t
.
integer
:status
t
.
timestamps
end
end
end
db/migrate/20170511213022_fix_enum_defaults.rb
deleted
100644 → 0
View file @
22696700
##
# Changes values to have a default.
class
FixEnumDefaults
<
ActiveRecord
::
Migration
[
5.1
]
def
up
change_column_default
:users
,
:authorization_level
,
0
change_column_default
:course_editions
,
:status
,
0
change_column_default
:course_participations
,
:status
,
0
change_column_default
:groups
,
:status
,
0
change_column_default
:memberships
,
:role
,
0
change_column_default
:projects
,
:status
,
0
end
def
down
change_column_default
:users
,
:authorization_level
,
nil
change_column_default
:course_editions
,
:status
,
nil
change_column_default
:course_participations
,
:status
,
nil
change_column_default
:groups
,
:status
,
nil
change_column_default
:memberships
,
:role
,
nil
change_column_default
:projects
,
:status
,
nil
end
end
Prev
1
2
3
4
5
…
9
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment