diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 4501ebea8..af1911ef3 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -25,7 +25,8 @@ class UsersController < ApplicationController @user = User.new end - def edit + def profile + @user ||= current_user end def create @@ -46,12 +47,16 @@ class UsersController < ApplicationController end @user ||= current_user if @user.update_without_password(params[:user]) + if @user.avatar && params[:delete_avatar] == '1' + @user.avatar = nil + @user.save + end flash[:notice] = t('flash.user.saved') - redirect_to edit_user_path(@user) + redirect_to @user == current_user ? edit_profile_path : edit_user_path(@user) else flash[:error] = t('flash.user.save_error') flash[:warning] = @user.errors.full_messages.join('. ') - render(:action => :edit) + render(:action => :profile) end end diff --git a/app/models/ability.rb b/app/models/ability.rb index 87a59203d..652dbb315 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -34,7 +34,7 @@ class Ability if user.user? can [:show, :autocomplete_user_uname], User - can [:edit, :update, :private], User, :id => user.id + can [:profile, :update, :private], User, :id => user.id can [:show, :update], Settings::Notifier, :user_id => user.id diff --git a/app/models/user.rb b/app/models/user.rb index babf50819..cb16c94c3 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -3,8 +3,15 @@ class User < ActiveRecord::Base ROLES = ['admin'] LANGUAGES_FOR_SELECT = [['Russian', 'ru'], ['English', 'en']] LANGUAGES = LANGUAGES_FOR_SELECT.map(&:last) + MAX_AVATAR_SIZE = 5.megabyte - has_attached_file :avatar, :styles => { :micro => "16x16", :small => "30x30>", :medium => "40x40>", :big => "81x81" } + has_attached_file :avatar, :styles => + { :micro => { :geometry => "16x16", :format => :jpg, :convert_options => '-strip -background white -flatten -quality 70'}, + :small => { :geometry => "30x30>", :format => :jpg, :convert_options => '-strip -background white -flatten -quality 70'}, + :medium => { :geometry => "40x40>", :format => :jpg, :convert_options => '-strip -background white -flatten -quality 70'}, + :big => { :geometry => "81x81>", :format => :jpg, :convert_options => '-strip -background white -flatten -quality 70'} + } + validates_inclusion_of :avatar_file_size, :in => (0..MAX_AVATAR_SIZE), :allow_nil => true devise :database_authenticatable, :registerable, #:omniauthable, # :token_authenticatable, :encryptable, :timeoutable :recoverable, :rememberable, :validatable #, :trackable, :confirmable, :lockable diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index 58d8d569f..23c58d426 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -29,7 +29,7 @@ .droplist-wrap #droplist.droplist .a= link_to current_user.uname, current_user - .a= link_to t('layout.settings.label'), edit_user_registration_path + .a= link_to t('layout.settings.label'), edit_profile_path .a= link_to t('layout.logout'), destroy_user_session_path, :method => :delete .right .both diff --git a/app/views/users/_form.html.haml b/app/views/users/_form.html.haml index f964a5802..ff52c8865 100644 --- a/app/views/users/_form.html.haml +++ b/app/views/users/_form.html.haml @@ -29,11 +29,16 @@ = f.text_field :location .both .leftlist - = f.label :avatar, t("activerecord.attributes.user.avatar") + = f.label :avatar, t("layout.users.avatar_with_size", :max => number_to_human_size(User::MAX_AVATAR_SIZE)) .rightlist = image_tag(avatar_url(@user, :medium)) - %br - %br +.leftlist +.rightlist + .check + %span#niceCheckbox1.niceCheck-main + = check_box_tag "delete_avatar", 1, false, :class => 'niceCheckbox1' + .forcheck= t('layout.users.delete_avatar') + .both = f.file_field :avatar .both .leftlist diff --git a/app/views/users/_sidebar.html.haml b/app/views/users/_sidebar.html.haml index 55fbbe759..c2b434cc8 100644 --- a/app/views/users/_sidebar.html.haml +++ b/app/views/users/_sidebar.html.haml @@ -6,7 +6,7 @@ %ul - if can? :edit, @user %li{:class => (act == :edit && :users == contr) ? 'active' : ''} - = link_to t("layout.users.edit"), edit_user_path(@user) + = link_to t("layout.users.edit"), @user == current_user ? edit_profile_path : edit_user_path(@user) - if can? :private, @user %li{:class => (act == :private && contr == :users) ? 'active' : ''} = link_to t("layout.users.user_private_settings"), user_private_settings_path(@user) diff --git a/app/views/users/edit.html.haml b/app/views/users/profile.html.haml similarity index 100% rename from app/views/users/edit.html.haml rename to app/views/users/profile.html.haml diff --git a/config/locales/users.en.yml b/config/locales/users.en.yml index 129710349..d39fefeb9 100644 --- a/config/locales/users.en.yml +++ b/config/locales/users.en.yml @@ -3,7 +3,7 @@ en: users: list: List new: Create - edit: Edit + edit: Profile settings: Settings new_header: New user edit_header: Edit @@ -23,6 +23,8 @@ en: delete_warning: Warning! Deleted account can not be recovered. private_settings_header: Password change avatar_notice: Without uploaded avatar will be used avatar from gravar web service. + delete_avatar: Delete avatar + avatar_with_size: Avatar (less than %{max}) activerecord: attributes: @@ -45,4 +47,4 @@ en: location: Location company: Company avatar: Avatar - + avatar_file_size: Avatar file size diff --git a/config/locales/users.ru.yml b/config/locales/users.ru.yml index 31d550160..54a06a89f 100644 --- a/config/locales/users.ru.yml +++ b/config/locales/users.ru.yml @@ -3,7 +3,7 @@ ru: users: list: Список new: Создать - edit: Редактировать + edit: Профиль settings: Настройки new_header: Новый пользователь edit_header: Редактировать @@ -23,6 +23,8 @@ ru: delete_warning: Внимание! Удаленный аккаунт восстановлению не подлежит. private_settings_header: Изменение пароля avatar_notice: При отсутствии загруженной аватарки будет использована Ваша аватарка на сервисе gravatar. + delete_avatar: Удалить аватар + avatar_with_size: Аватар (менее %{max}) activerecord: attributes: @@ -41,8 +43,8 @@ ru: password: Пароль password_confirm: Повторите пароль professional_experience: Профессиональный опыт - site: Вэб-сайт + site: Веб-сайт location: Местонахождение company: Компания avatar: Аватар - + avatar_file_size: Размер аватара diff --git a/config/routes.rb b/config/routes.rb index 9e631ed7f..c728f892e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -3,11 +3,19 @@ Rosa::Application.routes.draw do # XML RPC match 'api/xmlrpc' => 'rpc#xe_index' - put '/users' => 'users#update' devise_scope :user do get '/users/auth/:provider' => 'users/omniauth_callbacks#passthru' end - devise_for :users, :controllers => {:omniauth_callbacks => 'users/omniauth_callbacks'} + devise_for :users, :controllers => {:omniauth_callbacks => 'users/omniauth_callbacks'}, :skip => [:registrations] do + get '/users/cancel' => 'devise/registrations#cancel', :as => 'cancel_user_registration' + post '/users' => 'devise/registrations#create', :as => 'user_registration' + get '/users/sign_up' => 'devise/registrations#new', :as => 'new_user_registration' + delete '/users' => 'devise/registrations#destroy' + get '/user' => 'users#profile', :as => 'edit_profile' + put '/user' => 'users#update', :as => 'update_profile' + get '/users/:id' => 'users#profile', :as => 'edit_user' + put '/users/:id' => 'users#update', :as => 'update_user' + end resources :users do resources :groups, :only => [:new, :create, :index]