From fcffb4c3813d037346c7c967fcc490dc529c976b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaakko=20Kantoj=C3=A4rvi?= Date: Sat, 2 Feb 2013 21:25:03 +0200 Subject: [PATCH] Move username change decision into user model --- app/controllers/profiles_controller.rb | 2 +- app/models/user.rb | 4 ++++ app/views/profiles/account.html.haml | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/controllers/profiles_controller.rb b/app/controllers/profiles_controller.rb index 1d1850cf..051a6664 100644 --- a/app/controllers/profiles_controller.rb +++ b/app/controllers/profiles_controller.rb @@ -51,7 +51,7 @@ class ProfilesController < ApplicationController end def update_username - if Gitlab.config.gitlab.username_changing_enabled + if @user.can_change_username? @user.update_attributes(username: params[:user][:username]) end diff --git a/app/models/user.rb b/app/models/user.rb index 35a693fd..d66ce411 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -215,6 +215,10 @@ class User < ActiveRecord::Base keys.count == 0 end + def can_change_username? + Gitlab.config.gitlab.username_changing_enabled + end + def can_create_project? projects_limit > personal_projects.count end diff --git a/app/views/profiles/account.html.haml b/app/views/profiles/account.html.haml index b1c02d3a..ea9bcb64 100644 --- a/app/views/profiles/account.html.haml +++ b/app/views/profiles/account.html.haml @@ -53,7 +53,7 @@ -- if Gitlab.config.gitlab.username_changing_enabled +- if current_user.can_change_username? %fieldset.update-username %legend Username