From 5f6ca140d99c76f1eb904403a2a9d4ec7586d6bf Mon Sep 17 00:00:00 2001 From: Alexander Machehin Date: Mon, 12 Mar 2012 18:51:07 +0600 Subject: [PATCH 1/5] [refs #257] add ability to destroy avatar --- app/controllers/users_controller.rb | 4 ++++ app/views/users/_form.html.haml | 9 +++++++-- config/locales/users.en.yml | 1 + config/locales/users.ru.yml | 1 + 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 4501ebea8..ab554bfd7 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -46,6 +46,10 @@ 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) else diff --git a/app/views/users/_form.html.haml b/app/views/users/_form.html.haml index f964a5802..98f27236e 100644 --- a/app/views/users/_form.html.haml +++ b/app/views/users/_form.html.haml @@ -32,8 +32,13 @@ = f.label :avatar, t("activerecord.attributes.user.avatar") .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/config/locales/users.en.yml b/config/locales/users.en.yml index 4328e808b..fd860f5e4 100644 --- a/config/locales/users.en.yml +++ b/config/locales/users.en.yml @@ -22,6 +22,7 @@ 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 activerecord: attributes: diff --git a/config/locales/users.ru.yml b/config/locales/users.ru.yml index 3ba4f318d..954664993 100644 --- a/config/locales/users.ru.yml +++ b/config/locales/users.ru.yml @@ -22,6 +22,7 @@ ru: delete_warning: Внимание! Удаленный аккаунт восстановлению не подлежит. private_settings_header: Изменение пароля avatar_notice: При отсутствии загруженной аватарки будет использована Ваша аватарка на сервисе gravatar. + delete_avatar: Удалить аватар activerecord: attributes: From a800b4364de6e553f5cba066b332afba8f23ba7d Mon Sep 17 00:00:00 2001 From: Alexander Machehin Date: Mon, 12 Mar 2012 18:52:32 +0600 Subject: [PATCH 2/5] [refs #257] fixed translation --- config/locales/users.ru.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/locales/users.ru.yml b/config/locales/users.ru.yml index 954664993..381e773cf 100644 --- a/config/locales/users.ru.yml +++ b/config/locales/users.ru.yml @@ -41,7 +41,7 @@ ru: password: Пароль password_confirm: Повторите пароль professional_experience: Профессиональный опыт - site: Вэб-сайт + site: Веб-сайт location: Местонахождение company: Компания avatar: Аватар From 24639b8684bfedb61e6b93c6edc3fe5d4f114ffa Mon Sep 17 00:00:00 2001 From: Alexander Machehin Date: Mon, 12 Mar 2012 21:03:25 +0600 Subject: [PATCH 3/5] [refs 257] renamed to profile --- app/controllers/users_controller.rb | 7 ++++--- app/models/ability.rb | 2 +- app/views/layouts/application.html.haml | 2 +- app/views/users/_sidebar.html.haml | 2 +- .../users/{edit.html.haml => profile.html.haml} | 0 config/locales/users.en.yml | 2 +- config/locales/users.ru.yml | 2 +- config/routes.rb | 12 ++++++++++-- 8 files changed, 19 insertions(+), 10 deletions(-) rename app/views/users/{edit.html.haml => profile.html.haml} (100%) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index ab554bfd7..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 @@ -51,11 +52,11 @@ class UsersController < ApplicationController @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 129982a40..9828fe4a2 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/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index 523926e10..62438437d 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/_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 fd860f5e4..0c0b8cc8f 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 new_header: New user edit_header: Edit list_header: Users diff --git a/config/locales/users.ru.yml b/config/locales/users.ru.yml index 381e773cf..f02b1910f 100644 --- a/config/locales/users.ru.yml +++ b/config/locales/users.ru.yml @@ -3,7 +3,7 @@ ru: users: list: Список new: Создать - edit: Редактировать + edit: Профиль new_header: Новый пользователь edit_header: Редактировать list_header: Пользователи diff --git a/config/routes.rb b/config/routes.rb index 5e6343b38..e0a534a58 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] From 4fd91e2bfe1ba8dee1554b888fdbd692397c265e Mon Sep 17 00:00:00 2001 From: Alexander Machehin Date: Mon, 12 Mar 2012 22:28:56 +0600 Subject: [PATCH 4/5] [refs #257] force convert avatar to jpg --- app/models/user.rb | 9 ++++++++- app/views/users/_form.html.haml | 2 +- config/locales/users.en.yml | 3 ++- config/locales/users.ru.yml | 3 ++- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index d1dd648be..acecfeec8 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/users/_form.html.haml b/app/views/users/_form.html.haml index 98f27236e..ff52c8865 100644 --- a/app/views/users/_form.html.haml +++ b/app/views/users/_form.html.haml @@ -29,7 +29,7 @@ = 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)) .leftlist diff --git a/config/locales/users.en.yml b/config/locales/users.en.yml index 0c0b8cc8f..23db86c3e 100644 --- a/config/locales/users.en.yml +++ b/config/locales/users.en.yml @@ -23,6 +23,7 @@ en: 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 +46,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 f02b1910f..602c1f909 100644 --- a/config/locales/users.ru.yml +++ b/config/locales/users.ru.yml @@ -23,6 +23,7 @@ ru: private_settings_header: Изменение пароля avatar_notice: При отсутствии загруженной аватарки будет использована Ваша аватарка на сервисе gravatar. delete_avatar: Удалить аватар + avatar_with_size: Аватар (менее %{max}) activerecord: attributes: @@ -45,4 +46,4 @@ ru: location: Местонахождение company: Компания avatar: Аватар - + avatar_file_size: Размер аватара From 843d95b64e5e3c36eb4ae1bd66a916b3c4b9334d Mon Sep 17 00:00:00 2001 From: Alexander Machehin Date: Mon, 12 Mar 2012 23:02:02 +0600 Subject: [PATCH 5/5] [refs #257] fixed 'big' geometry --- app/models/user.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/user.rb b/app/models/user.rb index acecfeec8..699aa8ab2 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -9,7 +9,7 @@ class User < ActiveRecord::Base { :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'} + :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