Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Jérome Perrin
gitlab-ce
Commits
1c14805f
Commit
1c14805f
authored
Jun 14, 2017
by
James Lopez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor profiles controller and update service
parent
01378ab4
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
11 deletions
+12
-11
app/controllers/profiles_controller.rb
app/controllers/profiles_controller.rb
+11
-10
app/services/users/update_service.rb
app/services/users/update_service.rb
+1
-1
No files found.
app/controllers/profiles_controller.rb
View file @
1c14805f
...
@@ -12,16 +12,16 @@ class ProfilesController < Profiles::ApplicationController
...
@@ -12,16 +12,16 @@ class ProfilesController < Profiles::ApplicationController
user_params
.
except!
(
:email
)
if
@user
.
external_email?
user_params
.
except!
(
:email
)
if
@user
.
external_email?
respond_to
do
|
format
|
respond_to
do
|
format
|
status
=
Users
::
UpdateService
.
new
(
current_user
,
@user
,
user_params
).
execute
result
=
Users
::
UpdateService
.
new
(
current_user
,
@user
,
user_params
).
execute
if
status
[
:success
]
if
result
[
:success
]
message
=
"Profile was successfully updated"
message
=
"Profile was successfully updated"
format
.
html
{
redirect_back_or_default
(
default:
{
action:
'show'
},
options:
{
notice:
message
})
}
format
.
html
{
redirect_back_or_default
(
default:
{
action:
'show'
},
options:
{
notice:
message
})
}
format
.
json
{
render
json:
{
message:
message
}
}
format
.
json
{
render
json:
{
message:
message
}
}
else
else
format
.
html
{
redirect_back_or_default
(
default:
{
action:
'show'
},
options:
{
alert:
status
[
:message
]
})
}
format
.
html
{
redirect_back_or_default
(
default:
{
action:
'show'
},
options:
{
alert:
result
[
:message
]
})
}
format
.
json
{
render
json:
status
}
format
.
json
{
render
json:
result
}
end
end
end
end
end
end
...
@@ -63,11 +63,12 @@ class ProfilesController < Profiles::ApplicationController
...
@@ -63,11 +63,12 @@ class ProfilesController < Profiles::ApplicationController
end
end
def
update_username
def
update_username
if
@user
.
update_attributes
(
username:
user_params
[
:username
])
result
=
Users
::
UpdateService
.
new
(
current_user
,
@user
,
username:
user_params
[
:username
]).
execute
options
=
{
notice:
"Username successfully changed"
}
options
=
if
result
[
:success
]
{
notice:
"Username successfully changed"
}
else
else
message
=
@user
.
errors
.
full_messages
.
uniq
.
join
(
'. '
)
{
alert:
"Username change failed -
#{
result
[
:message
]
}
"
}
options
=
{
alert:
"Username change failed -
#{
message
}
"
}
end
end
redirect_back_or_default
(
default:
{
action:
'show'
},
options:
options
)
redirect_back_or_default
(
default:
{
action:
'show'
},
options:
options
)
...
...
app/services/users/update_service.rb
View file @
1c14805f
...
@@ -13,7 +13,7 @@ module Users
...
@@ -13,7 +13,7 @@ module Users
if
@user
.
save
||
!
@user
.
changed?
if
@user
.
save
||
!
@user
.
changed?
success
success
else
else
error
(
"User could not be updated
#{
@user
.
errors
.
full_messages
.
uniq
.
join
(
'. '
)
}
"
)
error
(
@user
.
errors
.
full_messages
.
uniq
.
join
(
'. '
)
)
end
end
end
end
...
...
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