Commit 46bf3a09 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Refactored profile to resource. Added missing flash notice on successfull...

Refactored profile to resource. Added missing flash notice on successfull updated. Update username via ajax
parent 2be5e6d4
...@@ -8,3 +8,13 @@ $ -> ...@@ -8,3 +8,13 @@ $ ->
# Go up the hierarchy and show the corresponding submission feedback element # Go up the hierarchy and show the corresponding submission feedback element
$(@).closest('fieldset').find('.update-feedback').show('highlight', {color: '#DFF0D8'}, 500) $(@).closest('fieldset').find('.update-feedback').show('highlight', {color: '#DFF0D8'}, 500)
$('.update-username form').on 'ajax:before', ->
$('.loading-gif').show()
$(this).find('.update-success').hide()
$(this).find('.update-failed').hide()
$('.update-username form').on 'ajax:complete', ->
$(this).find('.save-btn').removeAttr('disabled')
$(this).find('.save-btn').removeClass('disabled')
$(this).find('.loading-gif').hide()
class ProfileController < ApplicationController class ProfilesController < ApplicationController
before_filter :user before_filter :user
layout 'profile'
def show def show
end end
...@@ -7,8 +8,15 @@ class ProfileController < ApplicationController ...@@ -7,8 +8,15 @@ class ProfileController < ApplicationController
def design def design
end end
def account
end
def update def update
@user.update_attributes(params[:user]) if @user.update_attributes(params[:user])
flash[:notice] = "Profile was successfully updated"
else
flash[:alert] = "Failed to update profile"
end
respond_to do |format| respond_to do |format|
format.html { redirect_to :back } format.html { redirect_to :back }
...@@ -19,7 +27,7 @@ class ProfileController < ApplicationController ...@@ -19,7 +27,7 @@ class ProfileController < ApplicationController
def token def token
end end
def password_update def update_password
params[:user].reject!{ |k, v| k != "password" && k != "password_confirmation"} params[:user].reject!{ |k, v| k != "password" && k != "password_confirmation"}
if @user.update_attributes(params[:user]) if @user.update_attributes(params[:user])
...@@ -31,14 +39,25 @@ class ProfileController < ApplicationController ...@@ -31,14 +39,25 @@ class ProfileController < ApplicationController
end end
def reset_private_token def reset_private_token
current_user.reset_authentication_token! if current_user.reset_authentication_token!
redirect_to profile_account_path flash[:notice] = "Token was successfully updated"
end
redirect_to account_profile_path
end end
def history def history
@events = current_user.recent_events.page(params[:page]).per(20) @events = current_user.recent_events.page(params[:page]).per(20)
end end
def update_username
@user.update_attributes(username: params[:user][:username])
respond_to do |format|
format.js
end
end
private private
def user def user
......
...@@ -6,17 +6,17 @@ ...@@ -6,17 +6,17 @@
= render "layouts/head_panel", title: "Profile" = render "layouts/head_panel", title: "Profile"
.container .container
%ul.main_menu %ul.main_menu
= nav_link(path: 'profile#show', html_options: {class: 'home'}) do = nav_link(path: 'profiles#show', html_options: {class: 'home'}) do
= link_to "Profile", profile_path = link_to "Profile", profile_path
= nav_link(path: 'profile#account') do = nav_link(path: 'profiles#account') do
= link_to "Account", profile_account_path = link_to "Account", account_profile_path
= nav_link(controller: :keys) do = nav_link(controller: :keys) do
= link_to keys_path do = link_to keys_path do
SSH Keys SSH Keys
%span.count= current_user.keys.count %span.count= current_user.keys.count
= nav_link(path: 'profile#design') do = nav_link(path: 'profiles#design') do
= link_to "Design", profile_design_path = link_to "Design", design_profile_path
= nav_link(path: 'profile#history') do = nav_link(path: 'profiles#history') do
= link_to "History", profile_history_path = link_to "History", history_profile_path
.content= yield .content= yield
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
%span.cred.right %span.cred.right
keep it secret! keep it secret!
.padded .padded
= form_for @user, url: profile_reset_private_token_path, method: :put do |f| = form_for @user, url: reset_private_token_profile_path, method: :put do |f|
.data .data
%p.slead %p.slead
Private token used to access application resources without authentication. Private token used to access application resources without authentication.
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
%fieldset %fieldset
%legend Password %legend Password
= form_for @user, url: profile_password_path, method: :put do |f| = form_for @user, url: update_password_profile_path, method: :put do |f|
.padded .padded
%p.slead After successful password update you will be redirected to login page where you should login with new password %p.slead After successful password update you will be redirected to login page where you should login with new password
-if @user.errors.any? -if @user.errors.any?
...@@ -53,16 +53,24 @@ ...@@ -53,16 +53,24 @@
%fieldset %fieldset.update-username
%legend %legend
Username Username
%small.right %small.cred.right
Changing your username can have unintended side effects! Changing your username can have unintended side effects!
= form_for @user, url: profile_update_path, method: :put do |f| = form_for @user, url: update_username_profile_path, method: :put, remote: true do |f|
.padded .padded
= f.label :username = f.label :username
.input .input
= f.text_field :username, required: true = f.text_field :username, required: true
&nbsp;
%span.loading-gif.hide= image_tag "ajax_loader.gif"
%span.update-success.cgreen.hide
%i.icon-ok
Saved
%span.update-failed.cred.hide
%i.icon-ok
Failed
.input .input
= f.submit 'Save username', class: "btn save-btn" = f.submit 'Save username', class: "btn save-btn"
......
= form_for @user, url: profile_update_path, remote: true, method: :put do |f| = form_for @user, url: profile_path, remote: true, method: :put do |f|
%fieldset.application-theme %fieldset.application-theme
%legend %legend
Application theme Application theme
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
%hr %hr
= form_for @user, url: profile_update_path, method: :put, html: { class: "edit_user form-horizontal" } do |f| = form_for @user, url: profile_path, method: :put, html: { class: "edit_user form-horizontal" } do |f|
-if @user.errors.any? -if @user.errors.any?
%div.alert-message.block-message.error %div.alert-message.block-message.error
%ul %ul
...@@ -39,9 +39,9 @@ ...@@ -39,9 +39,9 @@
- if Gitlab.config.omniauth_enabled? && @user.provider? - if Gitlab.config.omniauth_enabled? && @user.provider?
%li %li
%p.hint %p
You can login through #{@user.provider.titleize}! You can login through #{@user.provider.titleize}!
= link_to "click here to change", profile_account_path = link_to "click here to change", account_profile_path
.row .row
.span7 .span7
......
- if @user.valid?
:plain
$('.update-username .update-success').show();
- else
:plain
$('.update-username .update-failed').show();
...@@ -69,14 +69,18 @@ Gitlab::Application.routes.draw do ...@@ -69,14 +69,18 @@ Gitlab::Application.routes.draw do
# #
# Profile Area # Profile Area
# #
get "profile/account" => "profile#account" resource :profile, only: [:show, :update] do
get "profile/history" => "profile#history" member do
put "profile/password" => "profile#password_update" get :account
get "profile/token" => "profile#token" get :history
put "profile/reset_private_token" => "profile#reset_private_token" get :token
get "profile" => "profile#show" get :design
get "profile/design" => "profile#design"
put "profile/update" => "profile#update" put :update_password
put :reset_private_token
put :update_username
end
end
resources :keys resources :keys
......
...@@ -54,7 +54,7 @@ module SharedPaths ...@@ -54,7 +54,7 @@ module SharedPaths
end end
Given 'I visit profile account page' do Given 'I visit profile account page' do
visit profile_account_path visit account_profile_path
end end
Given 'I visit profile SSH keys page' do Given 'I visit profile SSH keys page' do
...@@ -62,15 +62,11 @@ module SharedPaths ...@@ -62,15 +62,11 @@ module SharedPaths
end end
Given 'I visit profile design page' do Given 'I visit profile design page' do
visit profile_design_path visit design_profile_path
end end
Given 'I visit profile history page' do Given 'I visit profile history page' do
visit profile_history_path visit history_profile_path
end
Given 'I visit profile token page' do
visit profile_token_path
end end
# ---------------------------------------- # ----------------------------------------
......
...@@ -29,7 +29,16 @@ describe "Users Security" do ...@@ -29,7 +29,16 @@ describe "Users Security" do
end end
describe "GET /profile/account" do describe "GET /profile/account" do
subject { profile_account_path } subject { account_profile_path }
it { should be_allowed_for @u1 }
it { should be_allowed_for :admin }
it { should be_allowed_for :user }
it { should be_denied_for :visitor }
end
describe "GET /profile/design" do
subject { design_profile_path }
it { should be_allowed_for @u1 } it { should be_allowed_for @u1 }
it { should be_allowed_for :admin } it { should be_allowed_for :admin }
......
...@@ -82,37 +82,25 @@ end ...@@ -82,37 +82,25 @@ end
# profile GET /profile(.:format) profile#show # profile GET /profile(.:format) profile#show
# profile_design GET /profile/design(.:format) profile#design # profile_design GET /profile/design(.:format) profile#design
# profile_update PUT /profile/update(.:format) profile#update # profile_update PUT /profile/update(.:format) profile#update
describe ProfileController, "routing" do describe ProfilesController, "routing" do
it "to #account" do it "to #account" do
get("/profile/account").should route_to('profile#account') get("/profile/account").should route_to('profiles#account')
end end
it "to #history" do it "to #history" do
get("/profile/history").should route_to('profile#history') get("/profile/history").should route_to('profiles#history')
end
it "to #password_update" do
put("/profile/password").should route_to('profile#password_update')
end
it "to #token" do
get("/profile/token").should route_to('profile#token')
end end
it "to #reset_private_token" do it "to #reset_private_token" do
put("/profile/reset_private_token").should route_to('profile#reset_private_token') put("/profile/reset_private_token").should route_to('profiles#reset_private_token')
end end
it "to #show" do it "to #show" do
get("/profile").should route_to('profile#show') get("/profile").should route_to('profiles#show')
end end
it "to #design" do it "to #design" do
get("/profile/design").should route_to('profile#design') get("/profile/design").should route_to('profiles#design')
end
it "to #update" do
put("/profile/update").should route_to('profile#update')
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment