Revision 1298:4f746d8966dd .svn/pristine/50
| .svn/pristine/50/504a75e28140e0b003d557f020f846d8f93e9c79.svn-base | ||
|---|---|---|
| 1 |
# Redmine - project management software |
|
| 2 |
# Copyright (C) 2006-2013 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 SettingsController < ApplicationController |
|
| 19 |
layout 'admin' |
|
| 20 |
menu_item :plugins, :only => :plugin |
|
| 21 |
|
|
| 22 |
helper :queries |
|
| 23 |
|
|
| 24 |
before_filter :require_admin |
|
| 25 |
|
|
| 26 |
def index |
|
| 27 |
edit |
|
| 28 |
render :action => 'edit' |
|
| 29 |
end |
|
| 30 |
|
|
| 31 |
def edit |
|
| 32 |
@notifiables = Redmine::Notifiable.all |
|
| 33 |
if request.post? && params[:settings] && params[:settings].is_a?(Hash) |
|
| 34 |
settings = (params[:settings] || {}).dup.symbolize_keys
|
|
| 35 |
settings.each do |name, value| |
|
| 36 |
# remove blank values in array settings |
|
| 37 |
value.delete_if {|v| v.blank? } if value.is_a?(Array)
|
|
| 38 |
Setting[name] = value |
|
| 39 |
end |
|
| 40 |
flash[:notice] = l(:notice_successful_update) |
|
| 41 |
redirect_to settings_path(:tab => params[:tab]) |
|
| 42 |
else |
|
| 43 |
@options = {}
|
|
| 44 |
user_format = User::USER_FORMATS.collect{|key, value| [key, value[:setting_order]]}.sort{|a, b| a[1] <=> b[1]}
|
|
| 45 |
@options[:user_format] = user_format.collect{|f| [User.current.name(f[0]), f[0].to_s]}
|
|
| 46 |
@deliveries = ActionMailer::Base.perform_deliveries |
|
| 47 |
|
|
| 48 |
@guessed_host_and_path = request.host_with_port.dup |
|
| 49 |
@guessed_host_and_path << ('/'+ Redmine::Utils.relative_url_root.gsub(%r{^\/}, '')) unless Redmine::Utils.relative_url_root.blank?
|
|
| 50 |
|
|
| 51 |
Redmine::Themes.rescan |
|
| 52 |
end |
|
| 53 |
end |
|
| 54 |
|
|
| 55 |
def plugin |
|
| 56 |
@plugin = Redmine::Plugin.find(params[:id]) |
|
| 57 |
unless @plugin.configurable? |
|
| 58 |
render_404 |
|
| 59 |
return |
|
| 60 |
end |
|
| 61 |
|
|
| 62 |
if request.post? |
|
| 63 |
Setting.send "plugin_#{@plugin.id}=", params[:settings]
|
|
| 64 |
flash[:notice] = l(:notice_successful_update) |
|
| 65 |
redirect_to plugin_settings_path(@plugin) |
|
| 66 |
else |
|
| 67 |
@partial = @plugin.settings[:partial] |
|
| 68 |
@settings = Setting.send "plugin_#{@plugin.id}"
|
|
| 69 |
end |
|
| 70 |
rescue Redmine::PluginNotFound |
|
| 71 |
render_404 |
|
| 72 |
end |
|
| 73 |
end |
|
| .svn/pristine/50/50652fe8225e67d65adfd17ea2e35e3021fb4461.svn-base | ||
|---|---|---|
| 1 |
# Redmine - project management software |
|
| 2 |
# Copyright (C) 2006-2013 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 Redmine::SafeAttributesTest < ActiveSupport::TestCase |
|
| 21 |
fixtures :users |
|
| 22 |
|
|
| 23 |
class Base |
|
| 24 |
def attributes=(attrs) |
|
| 25 |
attrs.each do |key, value| |
|
| 26 |
send("#{key}=", value)
|
|
| 27 |
end |
|
| 28 |
end |
|
| 29 |
end |
|
| 30 |
|
|
| 31 |
class Person < Base |
|
| 32 |
attr_accessor :firstname, :lastname, :login |
|
| 33 |
include Redmine::SafeAttributes |
|
| 34 |
safe_attributes :firstname, :lastname |
|
| 35 |
safe_attributes :login, :if => lambda {|person, user| user.admin?}
|
|
| 36 |
end |
|
| 37 |
|
|
| 38 |
class Book < Base |
|
| 39 |
attr_accessor :title |
|
| 40 |
include Redmine::SafeAttributes |
|
| 41 |
safe_attributes :title |
|
| 42 |
end |
|
| 43 |
|
|
| 44 |
def test_safe_attribute_names |
|
| 45 |
p = Person.new |
|
| 46 |
user = User.anonymous |
|
| 47 |
assert_equal ['firstname', 'lastname'], p.safe_attribute_names(user) |
|
| 48 |
assert p.safe_attribute?('firstname', user)
|
|
| 49 |
assert !p.safe_attribute?('login', user)
|
|
| 50 |
|
|
| 51 |
p = Person.new |
|
| 52 |
user = User.find(1) |
|
| 53 |
assert_equal ['firstname', 'lastname', 'login'], p.safe_attribute_names(user) |
|
| 54 |
assert p.safe_attribute?('firstname', user)
|
|
| 55 |
assert p.safe_attribute?('login', user)
|
|
| 56 |
end |
|
| 57 |
|
|
| 58 |
def test_safe_attribute_names_without_user |
|
| 59 |
p = Person.new |
|
| 60 |
User.current = nil |
|
| 61 |
assert_equal ['firstname', 'lastname'], p.safe_attribute_names |
|
| 62 |
assert p.safe_attribute?('firstname')
|
|
| 63 |
assert !p.safe_attribute?('login')
|
|
| 64 |
|
|
| 65 |
p = Person.new |
|
| 66 |
User.current = User.find(1) |
|
| 67 |
assert_equal ['firstname', 'lastname', 'login'], p.safe_attribute_names |
|
| 68 |
assert p.safe_attribute?('firstname')
|
|
| 69 |
assert p.safe_attribute?('login')
|
|
| 70 |
end |
|
| 71 |
|
|
| 72 |
def test_set_safe_attributes |
|
| 73 |
p = Person.new |
|
| 74 |
p.send('safe_attributes=', {'firstname' => 'John', 'lastname' => 'Smith', 'login' => 'jsmith'}, User.anonymous)
|
|
| 75 |
assert_equal 'John', p.firstname |
|
| 76 |
assert_equal 'Smith', p.lastname |
|
| 77 |
assert_nil p.login |
|
| 78 |
|
|
| 79 |
p = Person.new |
|
| 80 |
User.current = User.find(1) |
|
| 81 |
p.send('safe_attributes=', {'firstname' => 'John', 'lastname' => 'Smith', 'login' => 'jsmith'}, User.find(1))
|
|
| 82 |
assert_equal 'John', p.firstname |
|
| 83 |
assert_equal 'Smith', p.lastname |
|
| 84 |
assert_equal 'jsmith', p.login |
|
| 85 |
end |
|
| 86 |
|
|
| 87 |
def test_set_safe_attributes_without_user |
|
| 88 |
p = Person.new |
|
| 89 |
User.current = nil |
|
| 90 |
p.safe_attributes = {'firstname' => 'John', 'lastname' => 'Smith', 'login' => 'jsmith'}
|
|
| 91 |
assert_equal 'John', p.firstname |
|
| 92 |
assert_equal 'Smith', p.lastname |
|
| 93 |
assert_nil p.login |
|
| 94 |
|
|
| 95 |
p = Person.new |
|
| 96 |
User.current = User.find(1) |
|
| 97 |
p.safe_attributes = {'firstname' => 'John', 'lastname' => 'Smith', 'login' => 'jsmith'}
|
|
| 98 |
assert_equal 'John', p.firstname |
|
| 99 |
assert_equal 'Smith', p.lastname |
|
| 100 |
assert_equal 'jsmith', p.login |
|
| 101 |
end |
|
| 102 |
end |
|
| .svn/pristine/50/509ee267bffe97965ae0a631af5009f5ad9e1775.svn-base | ||
|---|---|---|
| 1 |
<div class="contextual"> |
|
| 2 |
<% form_tag({:action => 'revision', :id => @project}) do %>
|
|
| 3 |
<%= l(:label_revision) %>: <%= text_field_tag 'rev', @rev, :size => 8 %> |
|
| 4 |
<%= submit_tag 'OK' %> |
|
| 5 |
<% end %> |
|
| 6 |
</div> |
|
| 7 |
|
|
| 8 |
<h2><%= l(:label_revision_plural) %></h2> |
|
| 9 |
|
|
| 10 |
<%= render :partial => 'revisions', |
|
| 11 |
:locals => {:project => @project,
|
|
| 12 |
:path => '', |
|
| 13 |
:revisions => @changesets, |
|
| 14 |
:entry => nil } %> |
|
| 15 |
|
|
| 16 |
<p class="pagination"><%= pagination_links_full @changeset_pages,@changeset_count %></p> |
|
| 17 |
|
|
| 18 |
<% content_for :header_tags do %> |
|
| 19 |
<%= stylesheet_link_tag "scm" %> |
|
| 20 |
<%= auto_discovery_link_tag( |
|
| 21 |
:atom, |
|
| 22 |
params.merge( |
|
| 23 |
{:format => 'atom', :page => nil, :key => User.current.rss_key})) %>
|
|
| 24 |
<% end %> |
|
| 25 |
|
|
| 26 |
<% other_formats_links do |f| %> |
|
| 27 |
<%= f.link_to 'Atom', :url => {:key => User.current.rss_key} %>
|
|
| 28 |
<% end %> |
|
| 29 |
|
|
| 30 |
<% html_title(l(:label_revision_plural)) -%> |
|
| .svn/pristine/50/50da835a6f15cfea65885171e3501d71716f5bea.svn-base | ||
|---|---|---|
| 1 |
# Redmine - project management software |
|
| 2 |
# Copyright (C) 2006-2011 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 EnabledModuleTest < ActiveSupport::TestCase |
|
| 21 |
fixtures :projects, :wikis |
|
| 22 |
|
|
| 23 |
def test_enabling_wiki_should_create_a_wiki |
|
| 24 |
CustomField.delete_all |
|
| 25 |
project = Project.create!(:name => 'Project with wiki', :identifier => 'wikiproject') |
|
| 26 |
assert_nil project.wiki |
|
| 27 |
project.enabled_module_names = ['wiki'] |
|
| 28 |
project.reload |
|
| 29 |
assert_not_nil project.wiki |
|
| 30 |
assert_equal 'Wiki', project.wiki.start_page |
|
| 31 |
end |
|
| 32 |
|
|
| 33 |
def test_reenabling_wiki_should_not_create_another_wiki |
|
| 34 |
project = Project.find(1) |
|
| 35 |
assert_not_nil project.wiki |
|
| 36 |
project.enabled_module_names = [] |
|
| 37 |
project.reload |
|
| 38 |
assert_no_difference 'Wiki.count' do |
|
| 39 |
project.enabled_module_names = ['wiki'] |
|
| 40 |
end |
|
| 41 |
assert_not_nil project.wiki |
|
| 42 |
end |
|
| 43 |
end |
|
| .svn/pristine/50/50fe0fccbefe1bf6410e617ed3aed18dfc4dd61e.svn-base | ||
|---|---|---|
| 1 |
# Redmine - project management software |
|
| 2 |
# Copyright (C) 2006-2013 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 JournalTest < ActiveSupport::TestCase |
|
| 21 |
fixtures :projects, :issues, :issue_statuses, :journals, :journal_details, |
|
| 22 |
:users, :members, :member_roles, :roles, :enabled_modules, |
|
| 23 |
:projects_trackers, :trackers |
|
| 24 |
|
|
| 25 |
def setup |
|
| 26 |
@journal = Journal.find 1 |
|
| 27 |
end |
|
| 28 |
|
|
| 29 |
def test_journalized_is_an_issue |
|
| 30 |
issue = @journal.issue |
|
| 31 |
assert_kind_of Issue, issue |
|
| 32 |
assert_equal 1, issue.id |
|
| 33 |
end |
|
| 34 |
|
|
| 35 |
def test_new_status |
|
| 36 |
status = @journal.new_status |
|
| 37 |
assert_not_nil status |
|
| 38 |
assert_kind_of IssueStatus, status |
|
| 39 |
assert_equal 2, status.id |
|
| 40 |
end |
|
| 41 |
|
|
| 42 |
def test_create_should_send_email_notification |
|
| 43 |
ActionMailer::Base.deliveries.clear |
|
| 44 |
issue = Issue.first |
|
| 45 |
user = User.first |
|
| 46 |
journal = issue.init_journal(user, issue) |
|
| 47 |
|
|
| 48 |
assert journal.save |
|
| 49 |
assert_equal 1, ActionMailer::Base.deliveries.size |
|
| 50 |
end |
|
| 51 |
|
|
| 52 |
def test_should_not_save_journal_with_blank_notes_and_no_details |
|
| 53 |
journal = Journal.new(:journalized => Issue.first, :user => User.first) |
|
| 54 |
|
|
| 55 |
assert_no_difference 'Journal.count' do |
|
| 56 |
assert_equal false, journal.save |
|
| 57 |
end |
|
| 58 |
end |
|
| 59 |
|
|
| 60 |
def test_create_should_not_split_non_private_notes |
|
| 61 |
assert_difference 'Journal.count' do |
|
| 62 |
assert_no_difference 'JournalDetail.count' do |
|
| 63 |
journal = Journal.generate!(:notes => 'Notes') |
|
| 64 |
end |
|
| 65 |
end |
|
| 66 |
|
|
| 67 |
assert_difference 'Journal.count' do |
|
| 68 |
assert_difference 'JournalDetail.count' do |
|
| 69 |
journal = Journal.generate!(:notes => 'Notes', :details => [JournalDetail.new]) |
|
| 70 |
end |
|
| 71 |
end |
|
| 72 |
|
|
| 73 |
assert_difference 'Journal.count' do |
|
| 74 |
assert_difference 'JournalDetail.count' do |
|
| 75 |
journal = Journal.generate!(:notes => '', :details => [JournalDetail.new]) |
|
| 76 |
end |
|
| 77 |
end |
|
| 78 |
end |
|
| 79 |
|
|
| 80 |
def test_create_should_split_private_notes |
|
| 81 |
assert_difference 'Journal.count' do |
|
| 82 |
assert_no_difference 'JournalDetail.count' do |
|
| 83 |
journal = Journal.generate!(:notes => 'Notes', :private_notes => true) |
|
| 84 |
journal.reload |
|
| 85 |
assert_equal true, journal.private_notes |
|
| 86 |
assert_equal 'Notes', journal.notes |
|
| 87 |
end |
|
| 88 |
end |
|
| 89 |
|
|
| 90 |
assert_difference 'Journal.count', 2 do |
|
| 91 |
assert_difference 'JournalDetail.count' do |
|
| 92 |
journal = Journal.generate!(:notes => 'Notes', :private_notes => true, :details => [JournalDetail.new]) |
|
| 93 |
journal.reload |
|
| 94 |
assert_equal true, journal.private_notes |
|
| 95 |
assert_equal 'Notes', journal.notes |
|
| 96 |
assert_equal 0, journal.details.size |
|
| 97 |
|
|
| 98 |
journal_with_changes = Journal.order('id DESC').offset(1).first
|
|
| 99 |
assert_equal false, journal_with_changes.private_notes |
|
| 100 |
assert_nil journal_with_changes.notes |
|
| 101 |
assert_equal 1, journal_with_changes.details.size |
|
| 102 |
assert_equal journal.created_on, journal_with_changes.created_on |
|
| 103 |
end |
|
| 104 |
end |
|
| 105 |
|
|
| 106 |
assert_difference 'Journal.count' do |
|
| 107 |
assert_difference 'JournalDetail.count' do |
|
| 108 |
journal = Journal.generate!(:notes => '', :private_notes => true, :details => [JournalDetail.new]) |
|
| 109 |
journal.reload |
|
| 110 |
assert_equal false, journal.private_notes |
|
| 111 |
assert_equal '', journal.notes |
|
| 112 |
assert_equal 1, journal.details.size |
|
| 113 |
end |
|
| 114 |
end |
|
| 115 |
end |
|
| 116 |
|
|
| 117 |
def test_visible_scope_for_anonymous |
|
| 118 |
# Anonymous user should see issues of public projects only |
|
| 119 |
journals = Journal.visible(User.anonymous).all |
|
| 120 |
assert journals.any? |
|
| 121 |
assert_nil journals.detect {|journal| !journal.issue.project.is_public?}
|
|
| 122 |
# Anonymous user should not see issues without permission |
|
| 123 |
Role.anonymous.remove_permission!(:view_issues) |
|
| 124 |
journals = Journal.visible(User.anonymous).all |
|
| 125 |
assert journals.empty? |
|
| 126 |
end |
|
| 127 |
|
|
| 128 |
def test_visible_scope_for_user |
|
| 129 |
user = User.find(9) |
|
| 130 |
assert user.projects.empty? |
|
| 131 |
# Non member user should see issues of public projects only |
|
| 132 |
journals = Journal.visible(user).all |
|
| 133 |
assert journals.any? |
|
| 134 |
assert_nil journals.detect {|journal| !journal.issue.project.is_public?}
|
|
| 135 |
# Non member user should not see issues without permission |
|
| 136 |
Role.non_member.remove_permission!(:view_issues) |
|
| 137 |
user.reload |
|
| 138 |
journals = Journal.visible(user).all |
|
| 139 |
assert journals.empty? |
|
| 140 |
# User should see issues of projects for which he has view_issues permissions only |
|
| 141 |
Member.create!(:principal => user, :project_id => 1, :role_ids => [1]) |
|
| 142 |
user.reload |
|
| 143 |
journals = Journal.visible(user).all |
|
| 144 |
assert journals.any? |
|
| 145 |
assert_nil journals.detect {|journal| journal.issue.project_id != 1}
|
|
| 146 |
end |
|
| 147 |
|
|
| 148 |
def test_visible_scope_for_admin |
|
| 149 |
user = User.find(1) |
|
| 150 |
user.members.each(&:destroy) |
|
| 151 |
assert user.projects.empty? |
|
| 152 |
journals = Journal.visible(user).all |
|
| 153 |
assert journals.any? |
|
| 154 |
# Admin should see issues on private projects that he does not belong to |
|
| 155 |
assert journals.detect {|journal| !journal.issue.project.is_public?}
|
|
| 156 |
end |
|
| 157 |
|
|
| 158 |
def test_details_should_normalize_dates |
|
| 159 |
j = JournalDetail.create!(:old_value => Date.parse('2012-11-03'), :value => Date.parse('2013-01-02'))
|
|
| 160 |
j.reload |
|
| 161 |
assert_equal '2012-11-03', j.old_value |
|
| 162 |
assert_equal '2013-01-02', j.value |
|
| 163 |
end |
|
| 164 |
|
|
| 165 |
def test_details_should_normalize_true_values |
|
| 166 |
j = JournalDetail.create!(:old_value => true, :value => true) |
|
| 167 |
j.reload |
|
| 168 |
assert_equal '1', j.old_value |
|
| 169 |
assert_equal '1', j.value |
|
| 170 |
end |
|
| 171 |
|
|
| 172 |
def test_details_should_normalize_false_values |
|
| 173 |
j = JournalDetail.create!(:old_value => false, :value => false) |
|
| 174 |
j.reload |
|
| 175 |
assert_equal '0', j.old_value |
|
| 176 |
assert_equal '0', j.value |
|
| 177 |
end |
|
| 178 |
end |
|
Also available in: Unified diff