Commit e049e187809a31ff908d49e5ff70828a12623b04

Authored by Dmitriy Zaporozhets
2 parents ea28519f ba65f291

Merge pull request #2991 from raphendyr/username_change_disablation

Add option to disable username changing
app/controllers/profiles_controller.rb
... ... @@ -51,7 +51,9 @@ class ProfilesController < ApplicationController
51 51 end
52 52  
53 53 def update_username
54   - @user.update_attributes(username: params[:user][:username])
  54 + if @user.can_change_username?
  55 + @user.update_attributes(username: params[:user][:username])
  56 + end
55 57  
56 58 respond_to do |format|
57 59 format.js
... ...
app/models/user.rb
... ... @@ -234,6 +234,10 @@ class User < ActiveRecord::Base
234 234 keys.count == 0
235 235 end
236 236  
  237 + def can_change_username?
  238 + Gitlab.config.gitlab.username_changing_enabled
  239 + end
  240 +
237 241 def can_create_project?
238 242 projects_limit > owned_projects.count
239 243 end
... ...
app/views/profiles/account.html.haml
... ... @@ -53,29 +53,30 @@
53 53  
54 54  
55 55  
56   -%fieldset.update-username
57   - %legend
58   - Username
59   - %small.cred.pull-right
60   - Changing your username can have unintended side effects!
61   - = form_for @user, url: update_username_profile_path, method: :put, remote: true do |f|
62   - .padded
63   - = f.label :username
64   - .input
65   - = f.text_field :username, required: true
66   -  
67   - %span.loading-gif.hide= image_tag "ajax_loader.gif"
68   - %span.update-success.cgreen.hide
69   - %i.icon-ok
70   - Saved
71   - %span.update-failed.cred.hide
72   - %i.icon-remove
73   - Failed
74   - %ul.cred
75   - %li It will change web url for personal projects.
76   - %li It will change the git path to repositories for personal projects.
77   - .input
78   - = f.submit 'Save username', class: "btn btn-save"
  56 +- if current_user.can_change_username?
  57 + %fieldset.update-username
  58 + %legend
  59 + Username
  60 + %small.cred.pull-right
  61 + Changing your username can have unintended side effects!
  62 + = form_for @user, url: update_username_profile_path, method: :put, remote: true do |f|
  63 + .padded
  64 + = f.label :username
  65 + .input
  66 + = f.text_field :username, required: true
  67 +  
  68 + %span.loading-gif.hide= image_tag "ajax_loader.gif"
  69 + %span.update-success.cgreen.hide
  70 + %i.icon-ok
  71 + Saved
  72 + %span.update-failed.cred.hide
  73 + %i.icon-remove
  74 + Failed
  75 + %ul.cred
  76 + %li It will change web url for personal projects.
  77 + %li It will change the git path to repositories for personal projects.
  78 + .input
  79 + = f.submit 'Save username', class: "btn btn-save"
79 80  
80 81 - if Gitlab.config.gitlab.signup_enabled
81 82 %fieldset.remove-account
... ... @@ -83,4 +84,4 @@
83 84 Remove account
84 85 %small.cred.pull-right
85 86 Before removing the account you must remove all projects!
86   - = link_to 'Delete account', user_registration_path, confirm: "REMOVE #{current_user.name}? Are you sure?", method: :delete, class: "btn btn-remove delete-key btn-small pull-right"
87 87 \ No newline at end of file
  88 + = link_to 'Delete account', user_registration_path, confirm: "REMOVE #{current_user.name}? Are you sure?", method: :delete, class: "btn btn-remove delete-key btn-small pull-right"
... ...
config/gitlab.yml.example
... ... @@ -35,6 +35,7 @@ production: &base
35 35 ## Project settings
36 36 default_projects_limit: 10
37 37 # signup_enabled: true # default: false - Account passwords are not sent via the email if signup is enabled.
  38 + # username_changing_enabled: false # default: true - User can change her username/namespace
38 39  
39 40 ## Gravatar
40 41 gravatar:
... ...
config/initializers/1_settings.rb
... ... @@ -57,6 +57,7 @@ Settings.gitlab['support_email'] ||= Settings.gitlab.email_from
57 57 Settings.gitlab['url'] ||= Settings.send(:build_gitlab_url)
58 58 Settings.gitlab['user'] ||= 'git'
59 59 Settings.gitlab['signup_enabled'] ||= false
  60 +Settings.gitlab['username_changing_enabled'] = true if Settings.gitlab['username_changing_enabled'].nil?
60 61  
61 62 #
62 63 # Gravatar
... ...