diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index bf7550183..8add68672 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -7,35 +7,35 @@ //= require_tree ./extra //= require_self -// function disableNotifierCbx(global_cbx) { -// if ($(global_cbx).attr('checked')) { -// $('.notify_cbx').removeAttr('disabled'); -// $('.notify_cbx').each(function(i,el) { $(el).prev().removeAttr('disabled'); }) -// } else { -// $('.notify_cbx').attr('disabled', 'disabled'); -// $('.notify_cbx').each(function(i,el) { $(el).prev().attr('disabled', 'disabled'); }) -// } -// } -// -// $(document).ready(function() { -// $('input.user_role_chbx').click(function() { -// var current = $(this); -// current.parent().find('input.user_role_chbx').each(function(i,el) { -// if ($(el).attr('id') != current.attr('id')) { -// $(el).removeAttr('checked'); -// } -// }); -// }); -// -// $('#settings_notifier_can_notify').click(function() { -// disableNotifierCbx($(this)); -// }); -// -// $('div.information > div.user').live('click', function() { -// droplist(); -// }); -// -// $('div.information > div.profile > a').live('click', function(e) { -// e.preventDefault(); -// }); -// }); +function disableNotifierCbx(global_cbx) { + if ($(global_cbx).attr('checked')) { + $('.notify_cbx').removeAttr('disabled'); + $('.notify_cbx').each(function(i,el) { $(el).prev().removeAttr('disabled'); }) + } else { + $('.notify_cbx').attr('disabled', 'disabled'); + $('.notify_cbx').each(function(i,el) { $(el).prev().attr('disabled', 'disabled'); }) + } +} + +$(document).ready(function() { + $('input.user_role_chbx').click(function() { + var current = $(this); + current.parent().find('input.user_role_chbx').each(function(i,el) { + if ($(el).attr('id') != current.attr('id')) { + $(el).removeAttr('checked'); + } + }); + }); + + $('#settings_notifier_can_notify').click(function() { + disableNotifierCbx($(this)); + }); + + $('div.information > div.user').live('click', function() { + droplist(); + }); + + $('div.information > div.profile > a').live('click', function(e) { + e.preventDefault(); + }); +}); diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 52a4c79c9..f59203d78 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -42,13 +42,25 @@ class UsersController < ApplicationController end def update - @user.role = params[:user][:role] + @user.role = params[:user][:role] if params[:user][:role] && current_user.admin? if @user.update_attributes(params[:user]) flash[:notice] = t('flash.user.saved') - redirect_to users_path + redirect_to edit_user_path(@user) else flash[:error] = t('flash.user.save_error') - render :action => :edit + render(:action => :edit) + end + end + + def private + if request.put? + if @user.update_attributes(params[:user]) + flash[:notice] = t('flash.user.saved') + redirect_to user_private_settings_path(@user) + else + flash[:error] = t('flash.user.save_error') + render(:action => :private) + end end end diff --git a/app/models/ability.rb b/app/models/ability.rb index eaf71d097..129982a40 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -34,6 +34,7 @@ class Ability if user.user? can [:show, :autocomplete_user_uname], User + can [:edit, :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 20906dc5c..26f66ab06 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -29,11 +29,13 @@ class User < ActiveRecord::Base validates :uname, :presence => true, :uniqueness => {:case_sensitive => false}, :format => { :with => /^[a-z0-9_]+$/ } validate { errors.add(:uname, :taken) if Group.where('uname LIKE ?', uname).present? } - validates :ssh_key, :uniqueness => true, :allow_blank => true validates :role, :inclusion => {:in => ROLES}, :allow_blank => true validates :language, :inclusion => {:in => LANGUAGES}, :allow_blank => true + validates_confirmation_of :password - attr_accessible :email, :password, :password_confirmation, :remember_me, :login, :name, :ssh_key, :uname, :language + attr_accessor :password, :password_confirmation, :current_password + attr_accessible :email, :password, :password_confirmation, :current_password, :remember_me, :login, :name, :ssh_key, :uname, :language, + :site, :company, :professional_experience, :location attr_readonly :uname, :own_projects_count attr_readonly :uname attr_accessor :login diff --git a/app/views/devise/registrations/edit.html.haml b/app/views/devise/registrations/edit.html.haml index c9fa797b1..0671270ec 100644 --- a/app/views/devise/registrations/edit.html.haml +++ b/app/views/devise/registrations/edit.html.haml @@ -22,6 +22,11 @@ .rightlist = f.select :language, User::LANGUAGES_FOR_SELECT .both + - if current_user.admin? + .leftlist + = f.label :role, t("activerecord.attributes.user.role"), :class => :label + .rightlist + = f.select :role, User::ROLES.push(""), :selected => resource.role .leftlist = f.label :company, t("activerecord.attributes.user.company") .rightlist diff --git a/app/views/users/_form.html.haml b/app/views/users/_form.html.haml index 1b4500090..40e1ec126 100644 --- a/app/views/users/_form.html.haml +++ b/app/views/users/_form.html.haml @@ -23,15 +23,15 @@ .rightlist = f.text_field :location .both -.leftlist - Аватарка: -.rightlist - %div - .avatar - %img{:alt => "avatar", :src => "pics/ava-admin.png"} - .load - %a.button{:href => "#"} Загрузить -.both +-#.leftlist +-# Аватарка: +-#.rightlist +-# %div +-# .avatar +-# %img{:alt => "avatar", :src => "pics/ava-admin.png"} +-# .load +-# %a.button{:href => "#"} Загрузить +-#.both .leftlist = f.label :professional_experience, t("activerecord.attributes.user.professional_experience") .rightlist diff --git a/app/views/users/_sidebar.html.haml b/app/views/users/_sidebar.html.haml index 84b1fc81f..55fbbe759 100644 --- a/app/views/users/_sidebar.html.haml +++ b/app/views/users/_sidebar.html.haml @@ -5,17 +5,11 @@ .admin-preferences %ul - if can? :edit, @user - %li{:class => (act == :edit && contr == :registrations) ? 'active' : ''} + %li{:class => (act == :edit && :users == contr) ? 'active' : ''} = link_to t("layout.users.edit"), edit_user_path(@user) - - if can? :edit_platform_private_user, @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) - - if can? :user_settings_notifier, @user + - if can? :show, @user.notifier %li{:class => (act == :show && contr == :notifiers) ? 'active' : ''} = link_to t("layout.users.settings_notifier"), user_settings_notifier_path(@user) - --#.block.notice --# %h3= t("layout.users.groups") --# .content --# - @user.groups.each do |group| --# %p= link_to group.name, group diff --git a/app/views/users/private.html.haml b/app/views/users/private.html.haml index e32f70c95..306786875 100644 --- a/app/views/users/private.html.haml +++ b/app/views/users/private.html.haml @@ -1,6 +1,6 @@ %h3.fix.bpadding10= t('layout.users.private_settings_header') -= form_for(@user, :url => registration_path(@user), :html => { :method => :put, :class => "form" }) do |f| += form_for(@user, :url => user_private_settings_path(@user), :html => { :method => :put, :class => "form" }) do |f| .leftlist = f.label :current_password .rightlist @@ -21,16 +21,6 @@ .rightlist = submit_tag t('layout.save') .both - .hr - %h3= t("layout.users.delete_header") - .leftside - = t("layout.users.delete_warning") - .rightside - = link_to t("layout.delete"), user_path(@project), :method => :delete, :confirm => t("layout.users.confirm_delete"), :class => 'button' if can? :destroy, @user - .both - -.notify - %p= t('layout.users.public_data_edit_warning') :javascript $('article .right').addClass('middlepadding'); diff --git a/config/routes.rb b/config/routes.rb index 04a8ac16f..1eefe9526 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -24,7 +24,8 @@ Rosa::Application.routes.draw do resource :notifier, :only => [:show, :update] end end - match 'users/:id/settings/private' => 'users#private', :as => :user_private_settings + match 'users/:id/settings/private' => 'users#private', :as => :user_private_settings, :via => :get + match 'users/:id/settings/private' => 'users#private', :as => :user_private_settings, :via => :put resources :event_logs, :only => :index diff --git a/db/migrate/20120303151303_remove_ssh_key_field_from_users.rb b/db/migrate/20120303151303_remove_ssh_key_field_from_users.rb new file mode 100644 index 000000000..7c65fdfa6 --- /dev/null +++ b/db/migrate/20120303151303_remove_ssh_key_field_from_users.rb @@ -0,0 +1,9 @@ +class RemoveSshKeyFieldFromUsers < ActiveRecord::Migration + def up + remove_column :users, :ssh_key + end + + def down + add_column :users, :ssh_key, :text + end +end diff --git a/db/schema.rb b/db/schema.rb index 8725c403c..88a962aee 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20120303062601) do +ActiveRecord::Schema.define(:version => 20120303151303) do create_table "activity_feeds", :force => true do |t| t.integer "user_id", :null => false @@ -370,7 +370,6 @@ ActiveRecord::Schema.define(:version => 20120303062601) do t.datetime "remember_created_at" t.datetime "created_at" t.datetime "updated_at" - t.text "ssh_key" t.string "uname" t.string "role" t.string "language", :default => "en"