Revision 1297:0a574315af3e .svn/pristine/c5
| .svn/pristine/c5/c52f7b6c9c463e8a51ddc62dfba2a59799b361b2.svn-base | ||
|---|---|---|
| 1 |
# Redmine - project management software |
|
| 2 |
# Copyright (C) 2006-2012 Jean-Philippe Lang |
|
| 3 |
# |
|
| 4 |
# This program is free software; you can redistribute it and/or |
|
| 5 |
# modify it under the terms of the GNU General Public License |
|
| 6 |
# as published by the Free Software Foundation; either version 2 |
|
| 7 |
# of the License, or (at your option) any later version. |
|
| 8 |
# |
|
| 9 |
# This program is distributed in the hope that it will be useful, |
|
| 10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 12 |
# GNU General Public License for more details. |
|
| 13 |
# |
|
| 14 |
# You should have received a copy of the GNU General Public License |
|
| 15 |
# along with this program; if not, write to the Free Software |
|
| 16 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
| 17 |
|
|
| 18 |
require File.expand_path('../test_case', __FILE__)
|
|
| 19 |
require 'tmpdir' |
|
| 20 |
|
|
| 21 |
class RedminePmTest::RepositorySubversionTest < RedminePmTest::TestCase |
|
| 22 |
fixtures :projects, :users, :members, :roles, :member_roles, :auth_sources |
|
| 23 |
|
|
| 24 |
SVN_BIN = Redmine::Configuration['scm_subversion_command'] || "svn" |
|
| 25 |
|
|
| 26 |
def test_anonymous_read_on_public_repo_with_permission_should_succeed |
|
| 27 |
assert_success "ls", svn_url |
|
| 28 |
end |
|
| 29 |
|
|
| 30 |
def test_anonymous_read_on_public_repo_without_permission_should_fail |
|
| 31 |
Role.anonymous.remove_permission! :browse_repository |
|
| 32 |
assert_failure "ls", svn_url |
|
| 33 |
end |
|
| 34 |
|
|
| 35 |
def test_anonymous_read_on_private_repo_should_fail |
|
| 36 |
Project.find(1).update_attribute :is_public, false |
|
| 37 |
assert_failure "ls", svn_url |
|
| 38 |
end |
|
| 39 |
|
|
| 40 |
def test_anonymous_commit_on_public_repo_should_fail |
|
| 41 |
Role.anonymous.add_permission! :commit_access |
|
| 42 |
assert_failure "mkdir --message Creating_a_directory", svn_url(random_filename) |
|
| 43 |
end |
|
| 44 |
|
|
| 45 |
def test_anonymous_commit_on_private_repo_should_fail |
|
| 46 |
Role.anonymous.add_permission! :commit_access |
|
| 47 |
Project.find(1).update_attribute :is_public, false |
|
| 48 |
assert_failure "mkdir --message Creating_a_directory", svn_url(random_filename) |
|
| 49 |
end |
|
| 50 |
|
|
| 51 |
def test_non_member_read_on_public_repo_with_permission_should_succeed |
|
| 52 |
Role.anonymous.remove_permission! :browse_repository |
|
| 53 |
with_credentials "miscuser8", "foo" do |
|
| 54 |
assert_success "ls", svn_url |
|
| 55 |
end |
|
| 56 |
end |
|
| 57 |
|
|
| 58 |
def test_non_member_read_on_public_repo_without_permission_should_fail |
|
| 59 |
Role.anonymous.remove_permission! :browse_repository |
|
| 60 |
Role.non_member.remove_permission! :browse_repository |
|
| 61 |
with_credentials "miscuser8", "foo" do |
|
| 62 |
assert_failure "ls", svn_url |
|
| 63 |
end |
|
| 64 |
end |
|
| 65 |
|
|
| 66 |
def test_non_member_read_on_private_repo_should_fail |
|
| 67 |
Project.find(1).update_attribute :is_public, false |
|
| 68 |
with_credentials "miscuser8", "foo" do |
|
| 69 |
assert_failure "ls", svn_url |
|
| 70 |
end |
|
| 71 |
end |
|
| 72 |
|
|
| 73 |
def test_non_member_commit_on_public_repo_should_fail |
|
| 74 |
Role.non_member.add_permission! :commit_access |
|
| 75 |
assert_failure "mkdir --message Creating_a_directory", svn_url(random_filename) |
|
| 76 |
end |
|
| 77 |
|
|
| 78 |
def test_non_member_commit_on_private_repo_should_fail |
|
| 79 |
Role.non_member.add_permission! :commit_access |
|
| 80 |
Project.find(1).update_attribute :is_public, false |
|
| 81 |
assert_failure "mkdir --message Creating_a_directory", svn_url(random_filename) |
|
| 82 |
end |
|
| 83 |
|
|
| 84 |
def test_member_read_on_public_repo_with_permission_should_succeed |
|
| 85 |
Role.anonymous.remove_permission! :browse_repository |
|
| 86 |
Role.non_member.remove_permission! :browse_repository |
|
| 87 |
with_credentials "dlopper", "foo" do |
|
| 88 |
assert_success "ls", svn_url |
|
| 89 |
end |
|
| 90 |
end |
|
| 91 |
|
|
| 92 |
def test_member_read_on_public_repo_without_permission_should_fail |
|
| 93 |
Role.anonymous.remove_permission! :browse_repository |
|
| 94 |
Role.non_member.remove_permission! :browse_repository |
|
| 95 |
Role.find(2).remove_permission! :browse_repository |
|
| 96 |
with_credentials "dlopper", "foo" do |
|
| 97 |
assert_failure "ls", svn_url |
|
| 98 |
end |
|
| 99 |
end |
|
| 100 |
|
|
| 101 |
def test_member_read_on_private_repo_with_permission_should_succeed |
|
| 102 |
Project.find(1).update_attribute :is_public, false |
|
| 103 |
with_credentials "dlopper", "foo" do |
|
| 104 |
assert_success "ls", svn_url |
|
| 105 |
end |
|
| 106 |
end |
|
| 107 |
|
|
| 108 |
def test_member_read_on_private_repo_without_permission_should_fail |
|
| 109 |
Role.find(2).remove_permission! :browse_repository |
|
| 110 |
Project.find(1).update_attribute :is_public, false |
|
| 111 |
with_credentials "dlopper", "foo" do |
|
| 112 |
assert_failure "ls", svn_url |
|
| 113 |
end |
|
| 114 |
end |
|
| 115 |
|
|
| 116 |
def test_member_commit_on_public_repo_with_permission_should_succeed |
|
| 117 |
Role.find(2).add_permission! :commit_access |
|
| 118 |
with_credentials "dlopper", "foo" do |
|
| 119 |
assert_success "mkdir --message Creating_a_directory", svn_url(random_filename) |
|
| 120 |
end |
|
| 121 |
end |
|
| 122 |
|
|
| 123 |
def test_member_commit_on_public_repo_without_permission_should_fail |
|
| 124 |
Role.find(2).remove_permission! :commit_access |
|
| 125 |
with_credentials "dlopper", "foo" do |
|
| 126 |
assert_failure "mkdir --message Creating_a_directory", svn_url(random_filename) |
|
| 127 |
end |
|
| 128 |
end |
|
| 129 |
|
|
| 130 |
def test_member_commit_on_private_repo_with_permission_should_succeed |
|
| 131 |
Role.find(2).add_permission! :commit_access |
|
| 132 |
Project.find(1).update_attribute :is_public, false |
|
| 133 |
with_credentials "dlopper", "foo" do |
|
| 134 |
assert_success "mkdir --message Creating_a_directory", svn_url(random_filename) |
|
| 135 |
end |
|
| 136 |
end |
|
| 137 |
|
|
| 138 |
def test_member_commit_on_private_repo_without_permission_should_fail |
|
| 139 |
Role.find(2).remove_permission! :commit_access |
|
| 140 |
Project.find(1).update_attribute :is_public, false |
|
| 141 |
with_credentials "dlopper", "foo" do |
|
| 142 |
assert_failure "mkdir --message Creating_a_directory", svn_url(random_filename) |
|
| 143 |
end |
|
| 144 |
end |
|
| 145 |
|
|
| 146 |
def test_invalid_credentials_should_fail |
|
| 147 |
Project.find(1).update_attribute :is_public, false |
|
| 148 |
with_credentials "dlopper", "foo" do |
|
| 149 |
assert_success "ls", svn_url |
|
| 150 |
end |
|
| 151 |
with_credentials "dlopper", "wrong" do |
|
| 152 |
assert_failure "ls", svn_url |
|
| 153 |
end |
|
| 154 |
end |
|
| 155 |
|
|
| 156 |
def test_anonymous_read_should_fail_with_login_required |
|
| 157 |
assert_success "ls", svn_url |
|
| 158 |
with_settings :login_required => '1' do |
|
| 159 |
assert_failure "ls", svn_url |
|
| 160 |
end |
|
| 161 |
end |
|
| 162 |
|
|
| 163 |
def test_authenticated_read_should_succeed_with_login_required |
|
| 164 |
with_settings :login_required => '1' do |
|
| 165 |
with_credentials "miscuser8", "foo" do |
|
| 166 |
assert_success "ls", svn_url |
|
| 167 |
end |
|
| 168 |
end |
|
| 169 |
end |
|
| 170 |
|
|
| 171 |
def test_read_on_archived_projects_should_fail |
|
| 172 |
Project.find(1).update_attribute :status, Project::STATUS_ARCHIVED |
|
| 173 |
assert_failure "ls", svn_url |
|
| 174 |
end |
|
| 175 |
|
|
| 176 |
def test_read_on_archived_private_projects_should_fail |
|
| 177 |
Project.find(1).update_attribute :status, Project::STATUS_ARCHIVED |
|
| 178 |
Project.find(1).update_attribute :is_public, false |
|
| 179 |
with_credentials "dlopper", "foo" do |
|
| 180 |
assert_failure "ls", svn_url |
|
| 181 |
end |
|
| 182 |
end |
|
| 183 |
|
|
| 184 |
def test_read_on_closed_projects_should_succeed |
|
| 185 |
Project.find(1).update_attribute :status, Project::STATUS_CLOSED |
|
| 186 |
assert_success "ls", svn_url |
|
| 187 |
end |
|
| 188 |
|
|
| 189 |
def test_read_on_closed_private_projects_should_succeed |
|
| 190 |
Project.find(1).update_attribute :status, Project::STATUS_CLOSED |
|
| 191 |
Project.find(1).update_attribute :is_public, false |
|
| 192 |
with_credentials "dlopper", "foo" do |
|
| 193 |
assert_success "ls", svn_url |
|
| 194 |
end |
|
| 195 |
end |
|
| 196 |
|
|
| 197 |
def test_commit_on_closed_projects_should_fail |
|
| 198 |
Project.find(1).update_attribute :status, Project::STATUS_CLOSED |
|
| 199 |
Role.find(2).add_permission! :commit_access |
|
| 200 |
with_credentials "dlopper", "foo" do |
|
| 201 |
assert_failure "mkdir --message Creating_a_directory", svn_url(random_filename) |
|
| 202 |
end |
|
| 203 |
end |
|
| 204 |
|
|
| 205 |
def test_commit_on_closed_private_projects_should_fail |
|
| 206 |
Project.find(1).update_attribute :status, Project::STATUS_CLOSED |
|
| 207 |
Project.find(1).update_attribute :is_public, false |
|
| 208 |
Role.find(2).add_permission! :commit_access |
|
| 209 |
with_credentials "dlopper", "foo" do |
|
| 210 |
assert_failure "mkdir --message Creating_a_directory", svn_url(random_filename) |
|
| 211 |
end |
|
| 212 |
end |
|
| 213 |
|
|
| 214 |
if ldap_configured? |
|
| 215 |
def test_user_with_ldap_auth_source_should_authenticate_with_ldap_credentials |
|
| 216 |
ldap_user = User.new(:mail => 'example1@redmine.org', :firstname => 'LDAP', :lastname => 'user', :auth_source_id => 1) |
|
| 217 |
ldap_user.login = 'example1' |
|
| 218 |
ldap_user.save! |
|
| 219 |
|
|
| 220 |
with_settings :login_required => '1' do |
|
| 221 |
with_credentials "example1", "123456" do |
|
| 222 |
assert_success "ls", svn_url |
|
| 223 |
end |
|
| 224 |
end |
|
| 225 |
|
|
| 226 |
with_settings :login_required => '1' do |
|
| 227 |
with_credentials "example1", "wrong" do |
|
| 228 |
assert_failure "ls", svn_url |
|
| 229 |
end |
|
| 230 |
end |
|
| 231 |
end |
|
| 232 |
end |
|
| 233 |
|
|
| 234 |
def test_checkout |
|
| 235 |
Dir.mktmpdir do |dir| |
|
| 236 |
assert_success "checkout", svn_url, dir |
|
| 237 |
end |
|
| 238 |
end |
|
| 239 |
|
|
| 240 |
def test_read_commands |
|
| 241 |
assert_success "info", svn_url |
|
| 242 |
assert_success "ls", svn_url |
|
| 243 |
assert_success "log", svn_url |
|
| 244 |
end |
|
| 245 |
|
|
| 246 |
def test_write_commands |
|
| 247 |
Role.find(2).add_permission! :commit_access |
|
| 248 |
filename = random_filename |
|
| 249 |
|
|
| 250 |
Dir.mktmpdir do |dir| |
|
| 251 |
assert_success "checkout", svn_url, dir |
|
| 252 |
Dir.chdir(dir) do |
|
| 253 |
# creates a file in the working copy |
|
| 254 |
f = File.new(File.join(dir, filename), "w") |
|
| 255 |
f.write "test file content" |
|
| 256 |
f.close |
|
| 257 |
|
|
| 258 |
assert_success "add", filename |
|
| 259 |
with_credentials "dlopper", "foo" do |
|
| 260 |
assert_success "commit --message Committing_a_file" |
|
| 261 |
assert_success "copy --message Copying_a_file", svn_url(filename), svn_url("#{filename}_copy")
|
|
| 262 |
assert_success "delete --message Deleting_a_file", svn_url(filename) |
|
| 263 |
assert_success "mkdir --message Creating_a_directory", svn_url("#{filename}_dir")
|
|
| 264 |
end |
|
| 265 |
assert_success "update" |
|
| 266 |
|
|
| 267 |
# checks that the working copy was updated |
|
| 268 |
assert File.exists?(File.join(dir, "#{filename}_copy"))
|
|
| 269 |
assert File.directory?(File.join(dir, "#{filename}_dir"))
|
|
| 270 |
end |
|
| 271 |
end |
|
| 272 |
end |
|
| 273 |
|
|
| 274 |
def test_read_invalid_repo_should_fail |
|
| 275 |
assert_failure "ls", svn_url("invalid")
|
|
| 276 |
end |
|
| 277 |
|
|
| 278 |
protected |
|
| 279 |
|
|
| 280 |
def execute(*args) |
|
| 281 |
a = [SVN_BIN, "--no-auth-cache --non-interactive"] |
|
| 282 |
a << "--username #{username}" if username
|
|
| 283 |
a << "--password #{password}" if password
|
|
| 284 |
|
|
| 285 |
super a, *args |
|
| 286 |
end |
|
| 287 |
|
|
| 288 |
def svn_url(path=nil) |
|
| 289 |
host = ENV['REDMINE_TEST_DAV_SERVER'] || '127.0.0.1' |
|
| 290 |
url = "http://#{host}/svn/ecookbook"
|
|
| 291 |
url << "/#{path}" if path
|
|
| 292 |
url |
|
| 293 |
end |
|
| 294 |
end |
|
| .svn/pristine/c5/c55cf1763a0504a65085500728d79a51df1f1629.svn-base | ||
|---|---|---|
| 1 |
<p><label>Example setting</label><%= text_field_tag 'settings[sample_setting]', @settings['sample_setting'] %></p> |
|
| .svn/pristine/c5/c56729768267d9f2427731ce1a23f08b9b8899ac.svn-base | ||
|---|---|---|
| 1 |
$:.unshift(File.dirname(__FILE__) + '/../lib') |
|
| 2 |
plugin_test_dir = File.dirname(__FILE__) |
|
| 3 |
|
|
| 4 |
require 'rubygems' |
|
| 5 |
require 'bundler/setup' |
|
| 6 |
|
|
| 7 |
require 'rspec' |
|
| 8 |
require 'logger' |
|
| 9 |
|
|
| 10 |
require 'active_support' |
|
| 11 |
require 'active_model' |
|
| 12 |
require 'active_record' |
|
| 13 |
require 'action_controller' |
|
| 14 |
|
|
| 15 |
require 'awesome_nested_set' |
|
| 16 |
|
|
| 17 |
ActiveRecord::Base.logger = Logger.new(plugin_test_dir + "/debug.log") |
|
| 18 |
|
|
| 19 |
require 'yaml' |
|
| 20 |
require 'erb' |
|
| 21 |
ActiveRecord::Base.configurations = YAML::load(ERB.new(IO.read(plugin_test_dir + "/db/database.yml")).result) |
|
| 22 |
ActiveRecord::Base.establish_connection(ENV["DB"] || "sqlite3mem") |
|
| 23 |
ActiveRecord::Migration.verbose = false |
|
| 24 |
load(File.join(plugin_test_dir, "db", "schema.rb")) |
|
| 25 |
|
|
| 26 |
require 'support/models' |
|
| 27 |
|
|
| 28 |
require 'rspec/rails' |
|
| 29 |
RSpec.configure do |config| |
|
| 30 |
config.fixture_path = "#{plugin_test_dir}/fixtures"
|
|
| 31 |
config.use_transactional_fixtures = true |
|
| 32 |
end |
|
| .svn/pristine/c5/c5875d3c8e61841ef5ad08f475a3db29a1da98e1.svn-base | ||
|---|---|---|
| 1 |
# Redmine - project management software |
|
| 2 |
# Copyright (C) 2006-2012 Jean-Philippe Lang |
|
| 3 |
# |
|
| 4 |
# This program is free software; you can redistribute it and/or |
|
| 5 |
# modify it under the terms of the GNU General Public License |
|
| 6 |
# as published by the Free Software Foundation; either version 2 |
|
| 7 |
# of the License, or (at your option) any later version. |
|
| 8 |
# |
|
| 9 |
# This program is distributed in the hope that it will be useful, |
|
| 10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 12 |
# GNU General Public License for more details. |
|
| 13 |
# |
|
| 14 |
# You should have received a copy of the GNU General Public License |
|
| 15 |
# along with this program; if not, write to the Free Software |
|
| 16 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
| 17 |
|
|
| 18 |
require File.expand_path('../../test_helper', __FILE__)
|
|
| 19 |
|
|
| 20 |
class ProjectsTest < ActionController::IntegrationTest |
|
| 21 |
fixtures :projects, :users, :members, :enabled_modules |
|
| 22 |
|
|
| 23 |
def test_archive_project |
|
| 24 |
subproject = Project.find(1).children.first |
|
| 25 |
log_user("admin", "admin")
|
|
| 26 |
get "admin/projects" |
|
| 27 |
assert_response :success |
|
| 28 |
assert_template "admin/projects" |
|
| 29 |
post "projects/1/archive" |
|
| 30 |
assert_redirected_to "/admin/projects" |
|
| 31 |
assert !Project.find(1).active? |
|
| 32 |
|
|
| 33 |
get 'projects/1' |
|
| 34 |
assert_response 403 |
|
| 35 |
get "projects/#{subproject.id}"
|
|
| 36 |
assert_response 403 |
|
| 37 |
|
|
| 38 |
post "projects/1/unarchive" |
|
| 39 |
assert_redirected_to "/admin/projects" |
|
| 40 |
assert Project.find(1).active? |
|
| 41 |
get "projects/1" |
|
| 42 |
assert_response :success |
|
| 43 |
end |
|
| 44 |
|
|
| 45 |
def test_modules_should_not_allow_get |
|
| 46 |
assert_no_difference 'EnabledModule.count' do |
|
| 47 |
get '/projects/1/modules', {:enabled_module_names => ['']}, credentials('jsmith')
|
|
| 48 |
assert_response 404 |
|
| 49 |
end |
|
| 50 |
end |
|
| 51 |
end |
|
| .svn/pristine/c5/c5ac85b1b901fa66f9ca32fcaa2fc8702a7953a0.svn-base | ||
|---|---|---|
| 1 |
# Redmine - project management software |
|
| 2 |
# Copyright (C) 2006-2012 Jean-Philippe Lang |
|
| 3 |
# |
|
| 4 |
# This program is free software; you can redistribute it and/or |
|
| 5 |
# modify it under the terms of the GNU General Public License |
|
| 6 |
# as published by the Free Software Foundation; either version 2 |
|
| 7 |
# of the License, or (at your option) any later version. |
|
| 8 |
# |
|
| 9 |
# This program is distributed in the hope that it will be useful, |
|
| 10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 12 |
# GNU General Public License for more details. |
|
| 13 |
# |
|
| 14 |
# You should have received a copy of the GNU General Public License |
|
| 15 |
# along with this program; if not, write to the Free Software |
|
| 16 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
| 17 |
|
|
| 18 |
class UsersController < ApplicationController |
|
| 19 |
layout 'admin' |
|
| 20 |
|
|
| 21 |
before_filter :require_admin, :except => :show |
|
| 22 |
before_filter :find_user, :only => [:show, :edit, :update, :destroy, :edit_membership, :destroy_membership] |
|
| 23 |
accept_api_auth :index, :show, :create, :update, :destroy |
|
| 24 |
|
|
| 25 |
helper :sort |
|
| 26 |
include SortHelper |
|
| 27 |
helper :custom_fields |
|
| 28 |
include CustomFieldsHelper |
|
| 29 |
|
|
| 30 |
def index |
|
| 31 |
sort_init 'login', 'asc' |
|
| 32 |
sort_update %w(login firstname lastname mail admin created_on last_login_on) |
|
| 33 |
|
|
| 34 |
case params[:format] |
|
| 35 |
when 'xml', 'json' |
|
| 36 |
@offset, @limit = api_offset_and_limit |
|
| 37 |
else |
|
| 38 |
@limit = per_page_option |
|
| 39 |
end |
|
| 40 |
|
|
| 41 |
@status = params[:status] || 1 |
|
| 42 |
|
|
| 43 |
scope = User.logged.status(@status) |
|
| 44 |
scope = scope.like(params[:name]) if params[:name].present? |
|
| 45 |
scope = scope.in_group(params[:group_id]) if params[:group_id].present? |
|
| 46 |
|
|
| 47 |
@user_count = scope.count |
|
| 48 |
@user_pages = Paginator.new self, @user_count, @limit, params['page'] |
|
| 49 |
@offset ||= @user_pages.current.offset |
|
| 50 |
@users = scope.find :all, |
|
| 51 |
:order => sort_clause, |
|
| 52 |
:limit => @limit, |
|
| 53 |
:offset => @offset |
|
| 54 |
|
|
| 55 |
respond_to do |format| |
|
| 56 |
format.html {
|
|
| 57 |
@groups = Group.all.sort |
|
| 58 |
render :layout => !request.xhr? |
|
| 59 |
} |
|
| 60 |
format.api |
|
| 61 |
end |
|
| 62 |
end |
|
| 63 |
|
|
| 64 |
def show |
|
| 65 |
# show projects based on current user visibility |
|
| 66 |
@memberships = @user.memberships.all(:conditions => Project.visible_condition(User.current)) |
|
| 67 |
|
|
| 68 |
events = Redmine::Activity::Fetcher.new(User.current, :author => @user).events(nil, nil, :limit => 10) |
|
| 69 |
@events_by_day = events.group_by(&:event_date) |
|
| 70 |
|
|
| 71 |
unless User.current.admin? |
|
| 72 |
if !@user.active? || (@user != User.current && @memberships.empty? && events.empty?) |
|
| 73 |
render_404 |
|
| 74 |
return |
|
| 75 |
end |
|
| 76 |
end |
|
| 77 |
|
|
| 78 |
respond_to do |format| |
|
| 79 |
format.html { render :layout => 'base' }
|
|
| 80 |
format.api |
|
| 81 |
end |
|
| 82 |
end |
|
| 83 |
|
|
| 84 |
def new |
|
| 85 |
@user = User.new(:language => Setting.default_language, :mail_notification => Setting.default_notification_option) |
|
| 86 |
@auth_sources = AuthSource.find(:all) |
|
| 87 |
end |
|
| 88 |
|
|
| 89 |
def create |
|
| 90 |
@user = User.new(:language => Setting.default_language, :mail_notification => Setting.default_notification_option) |
|
| 91 |
@user.safe_attributes = params[:user] |
|
| 92 |
@user.admin = params[:user][:admin] || false |
|
| 93 |
@user.login = params[:user][:login] |
|
| 94 |
@user.password, @user.password_confirmation = params[:user][:password], params[:user][:password_confirmation] unless @user.auth_source_id |
|
| 95 |
|
|
| 96 |
if @user.save |
|
| 97 |
@user.pref.attributes = params[:pref] |
|
| 98 |
@user.pref[:no_self_notified] = (params[:no_self_notified] == '1') |
|
| 99 |
@user.pref.save |
|
| 100 |
@user.notified_project_ids = (@user.mail_notification == 'selected' ? params[:notified_project_ids] : []) |
|
| 101 |
|
|
| 102 |
Mailer.account_information(@user, params[:user][:password]).deliver if params[:send_information] |
|
| 103 |
|
|
| 104 |
respond_to do |format| |
|
| 105 |
format.html {
|
|
| 106 |
flash[:notice] = l(:notice_user_successful_create, :id => view_context.link_to(@user.login, user_path(@user))) |
|
| 107 |
redirect_to(params[:continue] ? |
|
| 108 |
{:controller => 'users', :action => 'new'} :
|
|
| 109 |
{:controller => 'users', :action => 'edit', :id => @user}
|
|
| 110 |
) |
|
| 111 |
} |
|
| 112 |
format.api { render :action => 'show', :status => :created, :location => user_url(@user) }
|
|
| 113 |
end |
|
| 114 |
else |
|
| 115 |
@auth_sources = AuthSource.find(:all) |
|
| 116 |
# Clear password input |
|
| 117 |
@user.password = @user.password_confirmation = nil |
|
| 118 |
|
|
| 119 |
respond_to do |format| |
|
| 120 |
format.html { render :action => 'new' }
|
|
| 121 |
format.api { render_validation_errors(@user) }
|
|
| 122 |
end |
|
| 123 |
end |
|
| 124 |
end |
|
| 125 |
|
|
| 126 |
def edit |
|
| 127 |
@auth_sources = AuthSource.find(:all) |
|
| 128 |
@membership ||= Member.new |
|
| 129 |
end |
|
| 130 |
|
|
| 131 |
def update |
|
| 132 |
@user.admin = params[:user][:admin] if params[:user][:admin] |
|
| 133 |
@user.login = params[:user][:login] if params[:user][:login] |
|
| 134 |
if params[:user][:password].present? && (@user.auth_source_id.nil? || params[:user][:auth_source_id].blank?) |
|
| 135 |
@user.password, @user.password_confirmation = params[:user][:password], params[:user][:password_confirmation] |
|
| 136 |
end |
|
| 137 |
@user.safe_attributes = params[:user] |
|
| 138 |
# Was the account actived ? (do it before User#save clears the change) |
|
| 139 |
was_activated = (@user.status_change == [User::STATUS_REGISTERED, User::STATUS_ACTIVE]) |
|
| 140 |
# TODO: Similar to My#account |
|
| 141 |
@user.pref.attributes = params[:pref] |
|
| 142 |
@user.pref[:no_self_notified] = (params[:no_self_notified] == '1') |
|
| 143 |
|
|
| 144 |
if @user.save |
|
| 145 |
@user.pref.save |
|
| 146 |
@user.notified_project_ids = (@user.mail_notification == 'selected' ? params[:notified_project_ids] : []) |
|
| 147 |
|
|
| 148 |
if was_activated |
|
| 149 |
Mailer.account_activated(@user).deliver |
|
| 150 |
elsif @user.active? && params[:send_information] && !params[:user][:password].blank? && @user.auth_source_id.nil? |
|
| 151 |
Mailer.account_information(@user, params[:user][:password]).deliver |
|
| 152 |
end |
|
| 153 |
|
|
| 154 |
respond_to do |format| |
|
| 155 |
format.html {
|
|
| 156 |
flash[:notice] = l(:notice_successful_update) |
|
| 157 |
redirect_to_referer_or edit_user_path(@user) |
|
| 158 |
} |
|
| 159 |
format.api { render_api_ok }
|
|
| 160 |
end |
|
| 161 |
else |
|
| 162 |
@auth_sources = AuthSource.find(:all) |
|
| 163 |
@membership ||= Member.new |
|
| 164 |
# Clear password input |
|
| 165 |
@user.password = @user.password_confirmation = nil |
|
| 166 |
|
|
| 167 |
respond_to do |format| |
|
| 168 |
format.html { render :action => :edit }
|
|
| 169 |
format.api { render_validation_errors(@user) }
|
|
| 170 |
end |
|
| 171 |
end |
|
| 172 |
end |
|
| 173 |
|
|
| 174 |
def destroy |
|
| 175 |
@user.destroy |
|
| 176 |
respond_to do |format| |
|
| 177 |
format.html { redirect_back_or_default(users_url) }
|
|
| 178 |
format.api { render_api_ok }
|
|
| 179 |
end |
|
| 180 |
end |
|
| 181 |
|
|
| 182 |
def edit_membership |
|
| 183 |
@membership = Member.edit_membership(params[:membership_id], params[:membership], @user) |
|
| 184 |
@membership.save |
|
| 185 |
respond_to do |format| |
|
| 186 |
format.html { redirect_to :controller => 'users', :action => 'edit', :id => @user, :tab => 'memberships' }
|
|
| 187 |
format.js |
|
| 188 |
end |
|
| 189 |
end |
|
| 190 |
|
|
| 191 |
def destroy_membership |
|
| 192 |
@membership = Member.find(params[:membership_id]) |
|
| 193 |
if @membership.deletable? |
|
| 194 |
@membership.destroy |
|
| 195 |
end |
|
| 196 |
respond_to do |format| |
|
| 197 |
format.html { redirect_to :controller => 'users', :action => 'edit', :id => @user, :tab => 'memberships' }
|
|
| 198 |
format.js |
|
| 199 |
end |
|
| 200 |
end |
|
| 201 |
|
|
| 202 |
private |
|
| 203 |
|
|
| 204 |
def find_user |
|
| 205 |
if params[:id] == 'current' |
|
| 206 |
require_login || return |
|
| 207 |
@user = User.current |
|
| 208 |
else |
|
| 209 |
@user = User.find(params[:id]) |
|
| 210 |
end |
|
| 211 |
rescue ActiveRecord::RecordNotFound |
|
| 212 |
render_404 |
|
| 213 |
end |
|
| 214 |
end |
|
| .svn/pristine/c5/c5dd710a7f43b09dab39c8f1a38c740cf467e460.svn-base | ||
|---|---|---|
| 1 |
<div class="contextual"> |
|
| 2 |
<%= link_to l(:label_user_new), new_user_path, :class => 'icon icon-add' %> |
|
| 3 |
</div> |
|
| 4 |
|
|
| 5 |
<h2><%=l(:label_user_plural)%></h2> |
|
| 6 |
|
|
| 7 |
<%= form_tag({}, :method => :get) do %>
|
|
| 8 |
<fieldset><legend><%= l(:label_filter_plural) %></legend> |
|
| 9 |
<label for='status'><%= l(:field_status) %>:</label> |
|
| 10 |
<%= select_tag 'status', users_status_options_for_select(@status), :class => "small", :onchange => "this.form.submit(); return false;" %> |
|
| 11 |
|
|
| 12 |
<% if @groups.present? %> |
|
| 13 |
<label for='group_id'><%= l(:label_group) %>:</label> |
|
| 14 |
<%= select_tag 'group_id', content_tag('option') + options_from_collection_for_select(@groups, :id, :name, params[:group_id].to_i), :onchange => "this.form.submit(); return false;" %>
|
|
| 15 |
<% end %> |
|
| 16 |
|
|
| 17 |
<label for='name'><%= l(:label_user) %>:</label> |
|
| 18 |
<%= text_field_tag 'name', params[:name], :size => 30 %> |
|
| 19 |
<%= submit_tag l(:button_apply), :class => "small", :name => nil %> |
|
| 20 |
<%= link_to l(:button_clear), users_path, :class => 'icon icon-reload' %> |
|
| 21 |
</fieldset> |
|
| 22 |
<% end %> |
|
| 23 |
|
|
| 24 |
|
|
| 25 |
<div class="autoscroll"> |
|
| 26 |
<table class="list"> |
|
| 27 |
<thead><tr> |
|
| 28 |
<%= sort_header_tag('login', :caption => l(:field_login)) %>
|
|
| 29 |
<%= sort_header_tag('firstname', :caption => l(:field_firstname)) %>
|
|
| 30 |
<%= sort_header_tag('lastname', :caption => l(:field_lastname)) %>
|
|
| 31 |
<%= sort_header_tag('mail', :caption => l(:field_mail)) %>
|
|
| 32 |
<%= sort_header_tag('admin', :caption => l(:field_admin), :default_order => 'desc') %>
|
|
| 33 |
<%= sort_header_tag('created_on', :caption => l(:field_created_on), :default_order => 'desc') %>
|
|
| 34 |
<%= sort_header_tag('last_login_on', :caption => l(:field_last_login_on), :default_order => 'desc') %>
|
|
| 35 |
<th></th> |
|
| 36 |
</tr></thead> |
|
| 37 |
<tbody> |
|
| 38 |
<% for user in @users -%> |
|
| 39 |
<tr class="<%= user.css_classes %> <%= cycle("odd", "even") %>">
|
|
| 40 |
<td class="username"><%= avatar(user, :size => "14") %><%= link_to h(user.login), edit_user_path(user) %></td> |
|
| 41 |
<td class="firstname"><%= h(user.firstname) %></td> |
|
| 42 |
<td class="lastname"><%= h(user.lastname) %></td> |
|
| 43 |
<td class="email"><%= mail_to(h(user.mail)) %></td> |
|
| 44 |
<td align="center"><%= checked_image user.admin? %></td> |
|
| 45 |
<td class="created_on" align="center"><%= format_time(user.created_on) %></td> |
|
| 46 |
<td class="last_login_on" align="center"><%= format_time(user.last_login_on) unless user.last_login_on.nil? %></td> |
|
| 47 |
<td class="buttons"> |
|
| 48 |
<%= change_status_link(user) %> |
|
| 49 |
<%= delete_link user_path(user, :back_url => users_path(params)) unless User.current == user %> |
|
| 50 |
</td> |
|
| 51 |
</tr> |
|
| 52 |
<% end -%> |
|
| 53 |
</tbody> |
|
| 54 |
</table> |
|
| 55 |
</div> |
|
| 56 |
<p class="pagination"><%= pagination_links_full @user_pages, @user_count %></p> |
|
| 57 |
|
|
| 58 |
<% html_title(l(:label_user_plural)) -%> |
|
Also available in: Unified diff