Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Project Forum
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
EIP
Project Forum
Project Forum
Merge requests
!14
Users controller
Code
Review changes
Check out branch
Open in Workspace
Download
Patches
Plain diff
Expand sidebar
Merged
Users controller
users_controller
into
development
Overview
18
Commits
12
Pipelines
0
Changes
14
Merged
Users controller
Otto Visser
requested to merge
users_controller
into
development
May 18, 2017
Overview
16
Commits
12
Pipelines
0
Changes
14
0
0
Merge request reports
Compare
development
development (base)
and
latest version
latest version
84cd5305
12 commits,
May 18, 2017
14 files
+
111
−
84
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
14
app/controllers/admin/users_controller.rb
+
80
−
36
View file @ 84cd5305
Edit in single-file editor
Open in Web IDE
Show full file
@@ -4,6 +4,8 @@ class Admin::UsersController < Admin::ApplicationController
add_breadcrumb
'Users'
,
:admin_users_path
redirected
=
false
# Only view needed
def
index
end
@@ -21,55 +23,97 @@ class Admin::UsersController < Admin::ApplicationController
end
def
create
if
params
u
=
User
.
create
user_params
redirect_to
admin_user_path
(
u
.
id
)
else
re
nder
'new'
@user
=
User
.
create
user_
params
if
@user
.
id
flash
[
:success
]
=
"Succesfully created user
#{
@user
.
full_name
}
"
re
direct_to
admin_user_path
(
@user
.
id
)
and
return
end
flash
[
:danger
]
=
"Failed to create user"
render
"new"
end
def
update
if
params
if
params
[
:user
].
has_key?
(
:type
)
case
params
[
:user
][
:type
]
when
"user"
@user
.
update
(
params
[
:change_password
]
?
user_params
:
user_params_no_pwd
)
end
elsif
params
.
has_key?
(
:type
)
case
params
[
:type
]
when
"group"
params
[
:user_id
]
=
@user
.
id
Membership
.
create
group_params
when
"course"
if
@user
.
human_role
==
"TUD Staff"
CourseConfiguration
.
all
.
each
do
|
cc
|
if
cc
.
configurable
.
name
==
params
[
:course
]
case
params
[
:role
]
when
"coordinator"
@user
.
add_role
:coordinator
,
cc
when
"counselor"
@user
.
add_role
:counselor
,
cc
end
end
end
elsif
@user
.
human_role
==
"TUD Student"
params
[
:user_id
]
=
@user
.
id
params
[
:course_edition_id
]
=
CourseEdition
.
find_by
(
name:
params
[
:course_edition
]).
id
CourseParticipation
.
create
course_student_params
end
end
if
params
.
has_key?
(
:user
)
and
params
[
:user
].
has_key?
(
:type
)
case
params
[
:user
][
:type
]
when
"user"
update_user
and
return
end
elsif
params
.
has_key?
(
:type
)
case
params
[
:type
]
when
"add-group-relation"
add_group_relation
and
return
when
"add-course-relation"
add_course_relation
and
return
when
"delete-group-relation"
delete_group_relation
and
return
when
"delete-course-relation"
delete_course_relation
and
return
end
end
flash
[
:danger
]
=
"Failed to perform action"
render
"edit"
end
def
update_user
if
@user
.
update
(
params
[
:change_password
]
?
user_params
:
user_params_no_pwd
)
flash
[
:success
]
=
"Succesfully updated user"
redirect_to
admin_user_path
(
@user
)
else
render
'edit'
flash
[
:danger
]
=
"Failed to update user"
render
"show"
end
end
def
add_group_relation
params
[
:user_id
]
=
@user
.
id
if
Membership
.
create
group_params
redirect_to
admin_user_path
(
@user
)
else
flash
[
:danger
]
=
"Failed to add group relation"
render
"show"
end
end
def
add_course_relation
if
@user
.
human_role
==
"TUD Staff"
CourseConfiguration
.
all
.
each
do
|
cc
|
if
cc
.
configurable
.
name
==
params
[
:course
]
case
params
[
:role
]
when
"coordinator"
@user
.
add_role
:coordinator
,
cc
redirect_to
admin_user_path
(
@user
)
when
"counselor"
@user
.
add_role
:counselor
,
cc
redirect_to
admin_user_path
(
@user
)
end
end
end
elsif
@user
.
human_role
==
"TUD Student"
params
[
:user_id
]
=
@user
.
id
params
[
:course_edition_id
]
=
CourseEdition
.
find_by
(
name:
params
[
:course_edition
]).
id
CourseParticipation
.
create
course_student_params
redirect_to
admin_user_path
(
@user
)
end
end
def
add_project_relation
def
delete_group_relation
m
=
@user
.
memberships
.
find_by
(
id:
params
[
:relation_id
])
m
.
destroy
redirect_to
admin_user_path
(
@user
)
end
def
delete_course_relation
if
@user
.
human_role
==
"TUD Staff"
r
=
@user
.
course_roles
.
find_by
(
id:
params
[
:relation_id
])
r
.
destroy
elsif
@user
.
human_role
==
"TUD Student"
cp
=
@user
.
course_participations
.
find_by
(
id:
params
[
:relation_id
])
cp
.
destroy
end
redirect_to
admin_user_path
(
@user
)
end
protected
Loading