Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2012-12-02 15:29:24 +0400
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2012-12-02 15:29:24 +0400
commit46bf3a094988327b08c88006c694f0a0a15f7da2 (patch)
tree82458b24bc2d77b1f711bc6579d39080748ab972
parent2be5e6d44347dfb6374b4b2c87a953da06d6167d (diff)
Refactored profile to resource. Added missing flash notice on successfull updated. Update username via ajax
-rw-r--r--app/assets/javascripts/profile.js.coffee10
-rw-r--r--app/controllers/profiles_controller.rb (renamed from app/controllers/profile_controller.rb)29
-rw-r--r--app/views/layouts/profile.html.haml14
-rw-r--r--app/views/profile/index.html.haml1
-rw-r--r--app/views/profiles/account.html.haml (renamed from app/views/profile/account.html.haml)18
-rw-r--r--app/views/profiles/design.html.haml (renamed from app/views/profile/design.html.haml)2
-rw-r--r--app/views/profiles/history.html.haml (renamed from app/views/profile/history.html.haml)0
-rw-r--r--app/views/profiles/show.html.haml (renamed from app/views/profile/show.html.haml)6
-rw-r--r--app/views/profiles/update.js.erb (renamed from app/views/profile/update.js.erb)0
-rw-r--r--app/views/profiles/update_username.js.haml6
-rw-r--r--config/routes.rb20
-rw-r--r--features/steps/shared/paths.rb10
-rw-r--r--spec/requests/security/profile_access_spec.rb11
-rw-r--r--spec/routing/routing_spec.rb24
14 files changed, 95 insertions, 56 deletions
diff --git a/app/assets/javascripts/profile.js.coffee b/app/assets/javascripts/profile.js.coffee
index e536afad939..42207a390b3 100644
--- a/app/assets/javascripts/profile.js.coffee
+++ b/app/assets/javascripts/profile.js.coffee
@@ -8,3 +8,13 @@ $ ->
# Go up the hierarchy and show the corresponding submission feedback element
$(@).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()
diff --git a/app/controllers/profile_controller.rb b/app/controllers/profiles_controller.rb
index 5f8b11fdded..1d1efb16f04 100644
--- a/app/controllers/profile_controller.rb
+++ b/app/controllers/profiles_controller.rb
@@ -1,5 +1,6 @@
-class ProfileController < ApplicationController
+class ProfilesController < ApplicationController
before_filter :user
+ layout 'profile'
def show
end
@@ -7,8 +8,15 @@ class ProfileController < ApplicationController
def design
end
+ def account
+ end
+
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|
format.html { redirect_to :back }
@@ -19,7 +27,7 @@ class ProfileController < ApplicationController
def token
end
- def password_update
+ def update_password
params[:user].reject!{ |k, v| k != "password" && k != "password_confirmation"}
if @user.update_attributes(params[:user])
@@ -31,14 +39,25 @@ class ProfileController < ApplicationController
end
def reset_private_token
- current_user.reset_authentication_token!
- redirect_to profile_account_path
+ if current_user.reset_authentication_token!
+ flash[:notice] = "Token was successfully updated"
+ end
+
+ redirect_to account_profile_path
end
def history
@events = current_user.recent_events.page(params[:page]).per(20)
end
+ def update_username
+ @user.update_attributes(username: params[:user][:username])
+
+ respond_to do |format|
+ format.js
+ end
+ end
+
private
def user
diff --git a/app/views/layouts/profile.html.haml b/app/views/layouts/profile.html.haml
index b2743222281..7852ed6f0e1 100644
--- a/app/views/layouts/profile.html.haml
+++ b/app/views/layouts/profile.html.haml
@@ -6,17 +6,17 @@
= render "layouts/head_panel", title: "Profile"
.container
%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
- = nav_link(path: 'profile#account') do
- = link_to "Account", profile_account_path
+ = nav_link(path: 'profiles#account') do
+ = link_to "Account", account_profile_path
= nav_link(controller: :keys) do
= link_to keys_path do
SSH Keys
%span.count= current_user.keys.count
- = nav_link(path: 'profile#design') do
- = link_to "Design", profile_design_path
- = nav_link(path: 'profile#history') do
- = link_to "History", profile_history_path
+ = nav_link(path: 'profiles#design') do
+ = link_to "Design", design_profile_path
+ = nav_link(path: 'profiles#history') do
+ = link_to "History", history_profile_path
.content= yield
diff --git a/app/views/profile/index.html.haml b/app/views/profile/index.html.haml
deleted file mode 100644
index 84174ac5be7..00000000000
--- a/app/views/profile/index.html.haml
+++ /dev/null
@@ -1 +0,0 @@
-%h1 Profile
diff --git a/app/views/profile/account.html.haml b/app/views/profiles/account.html.haml
index e2c5bcdb8e2..1c51f48f401 100644
--- a/app/views/profile/account.html.haml
+++ b/app/views/profiles/account.html.haml
@@ -15,7 +15,7 @@
%span.cred.right
keep it secret!
.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
%p.slead
Private token used to access application resources without authentication.
@@ -31,7 +31,7 @@
%fieldset
%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
%p.slead After successful password update you will be redirected to login page where you should login with new password
-if @user.errors.any?
@@ -53,16 +53,24 @@
-%fieldset
+%fieldset.update-username
%legend
Username
- %small.right
+ %small.cred.right
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
= f.label :username
.input
= 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
= f.submit 'Save username', class: "btn save-btn"
diff --git a/app/views/profile/design.html.haml b/app/views/profiles/design.html.haml
index 502cca42f2d..f4b50677203 100644
--- a/app/views/profile/design.html.haml
+++ b/app/views/profiles/design.html.haml
@@ -1,4 +1,4 @@
-= 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
%legend
Application theme
diff --git a/app/views/profile/history.html.haml b/app/views/profiles/history.html.haml
index aa7006c569b..aa7006c569b 100644
--- a/app/views/profile/history.html.haml
+++ b/app/views/profiles/history.html.haml
diff --git a/app/views/profile/show.html.haml b/app/views/profiles/show.html.haml
index 7d9e90cf3f8..ac36fa3aa55 100644
--- a/app/views/profile/show.html.haml
+++ b/app/views/profiles/show.html.haml
@@ -8,7 +8,7 @@
%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?
%div.alert-message.block-message.error
%ul
@@ -39,9 +39,9 @@
- if Gitlab.config.omniauth_enabled? && @user.provider?
%li
- %p.hint
+ %p
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
.span7
diff --git a/app/views/profile/update.js.erb b/app/views/profiles/update.js.erb
index 04b5cf4827d..04b5cf4827d 100644
--- a/app/views/profile/update.js.erb
+++ b/app/views/profiles/update.js.erb
diff --git a/app/views/profiles/update_username.js.haml b/app/views/profiles/update_username.js.haml
new file mode 100644
index 00000000000..abd90269c93
--- /dev/null
+++ b/app/views/profiles/update_username.js.haml
@@ -0,0 +1,6 @@
+- if @user.valid?
+ :plain
+ $('.update-username .update-success').show();
+- else
+ :plain
+ $('.update-username .update-failed').show();
diff --git a/config/routes.rb b/config/routes.rb
index 9c58ce17fc2..1e24e0a5ca1 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -69,14 +69,18 @@ Gitlab::Application.routes.draw do
#
# Profile Area
#
- get "profile/account" => "profile#account"
- get "profile/history" => "profile#history"
- put "profile/password" => "profile#password_update"
- get "profile/token" => "profile#token"
- put "profile/reset_private_token" => "profile#reset_private_token"
- get "profile" => "profile#show"
- get "profile/design" => "profile#design"
- put "profile/update" => "profile#update"
+ resource :profile, only: [:show, :update] do
+ member do
+ get :account
+ get :history
+ get :token
+ get :design
+
+ put :update_password
+ put :reset_private_token
+ put :update_username
+ end
+ end
resources :keys
diff --git a/features/steps/shared/paths.rb b/features/steps/shared/paths.rb
index 33a94027472..a12576288df 100644
--- a/features/steps/shared/paths.rb
+++ b/features/steps/shared/paths.rb
@@ -54,7 +54,7 @@ module SharedPaths
end
Given 'I visit profile account page' do
- visit profile_account_path
+ visit account_profile_path
end
Given 'I visit profile SSH keys page' do
@@ -62,15 +62,11 @@ module SharedPaths
end
Given 'I visit profile design page' do
- visit profile_design_path
+ visit design_profile_path
end
Given 'I visit profile history page' do
- visit profile_history_path
- end
-
- Given 'I visit profile token page' do
- visit profile_token_path
+ visit history_profile_path
end
# ----------------------------------------
diff --git a/spec/requests/security/profile_access_spec.rb b/spec/requests/security/profile_access_spec.rb
index 8562b8e78af..f854f3fb066 100644
--- a/spec/requests/security/profile_access_spec.rb
+++ b/spec/requests/security/profile_access_spec.rb
@@ -29,7 +29,16 @@ describe "Users Security" do
end
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 :admin }
diff --git a/spec/routing/routing_spec.rb b/spec/routing/routing_spec.rb
index cb8dbf373ba..988063db4b0 100644
--- a/spec/routing/routing_spec.rb
+++ b/spec/routing/routing_spec.rb
@@ -82,37 +82,25 @@ end
# profile GET /profile(.:format) profile#show
# profile_design GET /profile/design(.:format) profile#design
# profile_update PUT /profile/update(.:format) profile#update
-describe ProfileController, "routing" do
+describe ProfilesController, "routing" do
it "to #account" do
- get("/profile/account").should route_to('profile#account')
+ get("/profile/account").should route_to('profiles#account')
end
it "to #history" do
- get("/profile/history").should route_to('profile#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')
+ get("/profile/history").should route_to('profiles#history')
end
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
it "to #show" do
- get("/profile").should route_to('profile#show')
+ get("/profile").should route_to('profiles#show')
end
it "to #design" do
- get("/profile/design").should route_to('profile#design')
- end
-
- it "to #update" do
- put("/profile/update").should route_to('profile#update')
+ get("/profile/design").should route_to('profiles#design')
end
end