Revision 1298:4f746d8966dd .svn/pristine/22

View differences:

.svn/pristine/22/2231a90d74735e9a796f1508f0e2f1bfd1774f24.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 Member < ActiveRecord::Base
19
  belongs_to :user
20
  belongs_to :principal, :foreign_key => 'user_id'
21
  has_many :member_roles, :dependent => :destroy
22
  has_many :roles, :through => :member_roles
23
  belongs_to :project
24

  
25
  validates_presence_of :principal, :project
26
  validates_uniqueness_of :user_id, :scope => :project_id
27
  validate :validate_role
28

  
29
  before_destroy :set_issue_category_nil
30

  
31
  def role
32
  end
33

  
34
  def role=
35
  end
36

  
37
  def name
38
    self.user.name
39
  end
40

  
41
  alias :base_role_ids= :role_ids=
42
  def role_ids=(arg)
43
    ids = (arg || []).collect(&:to_i) - [0]
44
    # Keep inherited roles
45
    ids += member_roles.select {|mr| !mr.inherited_from.nil?}.collect(&:role_id)
46

  
47
    new_role_ids = ids - role_ids
48
    # Add new roles
49
    new_role_ids.each {|id| member_roles << MemberRole.new(:role_id => id) }
50
    # Remove roles (Rails' #role_ids= will not trigger MemberRole#on_destroy)
51
    member_roles_to_destroy = member_roles.select {|mr| !ids.include?(mr.role_id)}
52
    if member_roles_to_destroy.any?
53
      member_roles_to_destroy.each(&:destroy)
54
    end
55
  end
56

  
57
  def <=>(member)
58
    a, b = roles.sort.first, member.roles.sort.first
59
    if a == b
60
      if principal
61
        principal <=> member.principal
62
      else
63
        1
64
      end
65
    elsif a
66
      a <=> b
67
    else
68
      1
69
    end
70
  end
71

  
72
  def deletable?
73
    member_roles.detect {|mr| mr.inherited_from}.nil?
74
  end
75

  
76
  def include?(user)
77
    if principal.is_a?(Group)
78
      !user.nil? && user.groups.include?(principal)
79
    else
80
      self.user == user
81
    end
82
  end
83

  
84
  def set_issue_category_nil
85
    if user
86
      # remove category based auto assignments for this member
87
      IssueCategory.update_all "assigned_to_id = NULL", ["project_id = ? AND assigned_to_id = ?", project.id, user.id]
88
    end
89
  end
90

  
91
  # Find or initilize a Member with an id, attributes, and for a Principal
92
  def self.edit_membership(id, new_attributes, principal=nil)
93
    @membership = id.present? ? Member.find(id) : Member.new(:principal => principal)
94
    @membership.attributes = new_attributes
95
    @membership
96
  end
97

  
98
  # Finds or initilizes a Member for the given project and principal
99
  def self.find_or_new(project, principal)
100
    project_id = project.is_a?(Project) ? project.id : project
101
    principal_id = principal.is_a?(Principal) ? principal.id : principal
102

  
103
    member = Member.find_by_project_id_and_user_id(project_id, principal_id)
104
    member ||= Member.new(:project_id => project_id, :user_id => principal_id)
105
    member
106
  end
107

  
108
  protected
109

  
110
  def validate_role
111
    errors.add_on_empty :role if member_roles.empty? && roles.empty?
112
  end
113
end
.svn/pristine/22/2254c6ada14f9698b9a4320070c88983213e381b.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 RoutingCalendarsTest < ActionController::IntegrationTest
21
  def test_calendars
22
    assert_routing(
23
        { :method => 'get', :path => "/issues/calendar" },
24
        { :controller => 'calendars', :action => 'show' }
25
      )
26
    assert_routing(
27
        { :method => 'get', :path => "/projects/project-name/issues/calendar" },
28
        { :controller => 'calendars', :action => 'show',
29
          :project_id => 'project-name' }
30
      )
31
  end
32
end
.svn/pristine/22/22629c3ce001e5a68327c24a4b23675476508e16.svn-base
1
<%= error_messages_for 'time_entry' %>
2
<%= back_url_hidden_field_tag %>
3

  
4
<div class="box tabular">
5
  <% if @time_entry.new_record? %>
6
    <% if params[:project_id] || @time_entry.issue %>
7
      <%= f.hidden_field :project_id %>
8
    <% else %>
9
      <p><%= f.select :project_id, project_tree_options_for_select(Project.allowed_to(:log_time).all, :selected => @time_entry.project), :required => true %></p>
10
    <% end %>
11
  <% end %>
12
  <p>
13
    <%= f.text_field :issue_id, :size => 6 %>
14
    <span id="time_entry_issue"><%= h("#{@time_entry.issue.tracker.name} ##{@time_entry.issue.id}: #{@time_entry.issue.subject}") if @time_entry.issue %></span>
15
  </p>
16
  <p><%= f.text_field :spent_on, :size => 10, :required => true %><%= calendar_for('time_entry_spent_on') %></p>
17
  <p><%= f.text_field :hours, :size => 6, :required => true %></p>
18
  <p><%= f.text_field :comments, :size => 100, :maxlength => 255 %></p>
19
  <p><%= f.select :activity_id, activity_collection_for_select_options(@time_entry), :required => true %></p>
20
  <% @time_entry.custom_field_values.each do |value| %>
21
    <p><%= custom_field_tag_with_label :time_entry, value %></p>
22
  <% end %>
23
  <%= call_hook(:view_timelog_edit_form_bottom, { :time_entry => @time_entry, :form => f }) %>
24
</div>
25

  
26
<%= javascript_tag do %>
27
  observeAutocompleteField('time_entry_issue_id', '<%= escape_javascript auto_complete_issues_path(:project_id => @project, :scope => (@project ? nil : 'all'))%>', {
28
    select: function(event, ui) {
29
      $('#time_entry_issue').text(ui.item.label);
30
    }
31
  });
32
<% end %>
.svn/pristine/22/2271decb00153f4ca80ae30e23c680b8a941ca9b.svn-base
1
<%= form_tag({:action => 'edit', :tab => 'repositories'}) do %>
2

  
3
<fieldset class="box settings enabled_scm">
4
<legend><%= l(:setting_enabled_scm) %></legend>
5
<%= hidden_field_tag 'settings[enabled_scm][]', '' %>
6
<table>
7
  <tr>
8
    <th></th>
9
    <th><%= l(:text_scm_command)         %></th>
10
    <th><%= l(:text_scm_command_version) %></th>
11
  </tr>
12
  <% Redmine::Scm::Base.all.collect do |choice| %>
13
    <% scm_class = "Repository::#{choice}".constantize %>
14
    <% text, value = (choice.is_a?(Array) ? choice : [choice, choice]) %>
15
    <% setting = :enabled_scm %>
16
		<% enabled = Setting.send(setting).include?(value) %>
17
    <tr>
18
      <td class="scm_name">
19
        <label>
20
        <%= check_box_tag("settings[#{setting}][]", value, enabled, :id => nil) %>
21
        <%= text.to_s %>
22
        </label>
23
      </td>
24
      <td>
25
         <% if enabled %>
26
         <%=
27
           image_tag(
28
              (scm_class.scm_available ? 'true.png' : 'exclamation.png'),
29
              :style => "vertical-align:bottom;"
30
           )
31
           %>
32
          <%= scm_class.scm_command %>
33
					<% end %>
34
       </td>
35
       <td>
36
          <%= scm_class.scm_version_string if enabled %>
37
       </td>
38
     </tr>
39
  <% end %>
40
</table>
41
<p><em class="info"><%= l(:text_scm_config) %></em></p>
42
</fieldset>
43

  
44
<div class="box tabular settings">
45
<p><%= setting_check_box :autofetch_changesets %></p>
46

  
47
<p><%= setting_check_box :sys_api_enabled,
48
                         :onclick =>
49
                             "if (this.checked) { $('#settings_sys_api_key').removeAttr('disabled'); } else { $('#settings_sys_api_key').attr('disabled', true); }" %></p>
50

  
51
<p><%= setting_text_field :sys_api_key,
52
                          :size     => 30,
53
                          :id       => 'settings_sys_api_key',
54
                          :disabled => !Setting.sys_api_enabled?,
55
                          :label    => :setting_mail_handler_api_key %>
56
  <%= link_to_function l(:label_generate_key),
57
                       "if (!$('#settings_sys_api_key').attr('disabled')) { $('#settings_sys_api_key').val(randomKey(20)) }" %>
58
</p>
59

  
60
<p><%= setting_text_field :repository_log_display_limit, :size => 6 %></p>
61
</div>
62

  
63
<fieldset class="box tabular settings">
64
<legend><%= l(:text_issues_ref_in_commit_messages) %></legend>
65
<p><%= setting_text_field :commit_ref_keywords, :size => 30 %>
66
<em class="info"><%= l(:text_comma_separated) %></em></p>
67

  
68
<p><%= setting_text_field :commit_fix_keywords, :size => 30 %>
69
&nbsp;<%= l(:label_applied_status) %>: <%= setting_select :commit_fix_status_id,
70
                                                          [["", 0]] +
71
                                                              IssueStatus.sorted.all.collect{
72
                                                                 |status| [status.name, status.id.to_s]
73
                                                              },
74
                                                          :label => false %>
75
&nbsp;<%= l(:field_done_ratio) %>: <%= setting_select :commit_fix_done_ratio,
76
                                                       (0..10).to_a.collect {|r| ["#{r*10} %", "#{r*10}"] },
77
                                                       :blank => :label_no_change_option,
78
                                                       :label => false %>
79
<em class="info"><%= l(:text_comma_separated) %></em></p>
80

  
81
<p><%= setting_check_box :commit_cross_project_ref %></p>
82

  
83
<p><%= setting_check_box :commit_logtime_enabled,
84
                         :onclick =>
85
                            "if (this.checked) { $('#settings_commit_logtime_activity_id').removeAttr('disabled'); } else { $('#settings_commit_logtime_activity_id').attr('disabled', true); }"%></p>
86

  
87
<p><%= setting_select :commit_logtime_activity_id,
88
                      [[l(:label_default), 0]] +
89
                          TimeEntryActivity.shared.active.collect{|activity| [activity.name, activity.id.to_s]},
90
                      :disabled => !Setting.commit_logtime_enabled?%></p>
91
</fieldset>
92

  
93
<%= submit_tag l(:button_save) %>
94
<% end %>
.svn/pristine/22/229053adf4d0f0cdc30b283c6478a18c47c6fe1d.svn-base
1
if RUBY_VERSION < '1.9'
2
  require 'iconv'
3
end
4

  
5
module Redmine
6
  module CodesetUtil
7

  
8
    def self.replace_invalid_utf8(str)
9
      return str if str.nil?
10
      if str.respond_to?(:force_encoding)
11
        str.force_encoding('UTF-8')
12
        if ! str.valid_encoding?
13
          str = str.encode("US-ASCII", :invalid => :replace,
14
                :undef => :replace, :replace => '?').encode("UTF-8")
15
        end
16
      elsif RUBY_PLATFORM == 'java'
17
        begin
18
          ic = Iconv.new('UTF-8', 'UTF-8')
19
          str = ic.iconv(str)
20
        rescue
21
          str = str.gsub(%r{[^\r\n\t\x20-\x7e]}, '?')
22
        end
23
      else
24
        ic = Iconv.new('UTF-8', 'UTF-8')
25
        txtar = ""
26
        begin
27
          txtar += ic.iconv(str)
28
        rescue Iconv::IllegalSequence
29
          txtar += $!.success
30
          str = '?' + $!.failed[1,$!.failed.length]
31
          retry
32
        rescue
33
          txtar += $!.success
34
        end
35
        str = txtar
36
      end
37
      str
38
    end
39

  
40
    def self.to_utf8(str, encoding)
41
      return str if str.nil?
42
      str.force_encoding("ASCII-8BIT") if str.respond_to?(:force_encoding)
43
      if str.empty?
44
        str.force_encoding("UTF-8") if str.respond_to?(:force_encoding)
45
        return str
46
      end
47
      enc = encoding.blank? ? "UTF-8" : encoding
48
      if str.respond_to?(:force_encoding)
49
        if enc.upcase != "UTF-8"
50
          str.force_encoding(enc)
51
          str = str.encode("UTF-8", :invalid => :replace,
52
                :undef => :replace, :replace => '?')
53
        else
54
          str.force_encoding("UTF-8")
55
          if ! str.valid_encoding?
56
            str = str.encode("US-ASCII", :invalid => :replace,
57
                  :undef => :replace, :replace => '?').encode("UTF-8")
58
          end
59
        end
60
      elsif RUBY_PLATFORM == 'java'
61
        begin
62
          ic = Iconv.new('UTF-8', enc)
63
          str = ic.iconv(str)
64
        rescue
65
          str = str.gsub(%r{[^\r\n\t\x20-\x7e]}, '?')
66
        end
67
      else
68
        ic = Iconv.new('UTF-8', enc)
69
        txtar = ""
70
        begin
71
          txtar += ic.iconv(str)
72
        rescue Iconv::IllegalSequence
73
          txtar += $!.success
74
          str = '?' + $!.failed[1,$!.failed.length]
75
          retry
76
        rescue
77
          txtar += $!.success
78
        end
79
        str = txtar
80
      end
81
      str
82
    end
83

  
84
    def self.to_utf8_by_setting(str)
85
      return str if str.nil?
86
      str = self.to_utf8_by_setting_internal(str)
87
      if str.respond_to?(:force_encoding)
88
        str.force_encoding('UTF-8')
89
      end
90
      str
91
    end
92

  
93
    def self.to_utf8_by_setting_internal(str)
94
      return str if str.nil?
95
      if str.respond_to?(:force_encoding)
96
        str.force_encoding('ASCII-8BIT')
97
      end
98
      return str if str.empty?
99
      return str if /\A[\r\n\t\x20-\x7e]*\Z/n.match(str) # for us-ascii
100
      if str.respond_to?(:force_encoding)
101
        str.force_encoding('UTF-8')
102
      end
103
      encodings = Setting.repositories_encodings.split(',').collect(&:strip)
104
      encodings.each do |encoding|
105
        if str.respond_to?(:force_encoding)
106
          begin
107
            str.force_encoding(encoding)
108
            utf8 = str.encode('UTF-8')
109
            return utf8 if utf8.valid_encoding?
110
          rescue
111
            # do nothing here and try the next encoding
112
          end
113
        else
114
          begin
115
            return Iconv.conv('UTF-8', encoding, str)
116
          rescue Iconv::Failure
117
            # do nothing here and try the next encoding
118
          end
119
        end
120
      end
121
      str = self.replace_invalid_utf8(str)
122
      if str.respond_to?(:force_encoding)
123
        str.force_encoding('UTF-8')
124
      end
125
      str
126
    end
127

  
128
    def self.from_utf8(str, encoding)
129
      str ||= ''
130
      if str.respond_to?(:force_encoding)
131
        str.force_encoding('UTF-8')
132
        if encoding.upcase != 'UTF-8'
133
          str = str.encode(encoding, :invalid => :replace,
134
                           :undef => :replace, :replace => '?')
135
        else
136
          str = self.replace_invalid_utf8(str)
137
        end
138
      elsif RUBY_PLATFORM == 'java'
139
        begin
140
          ic = Iconv.new(encoding, 'UTF-8')
141
          str = ic.iconv(str)
142
        rescue
143
          str = str.gsub(%r{[^\r\n\t\x20-\x7e]}, '?')
144
        end
145
      else
146
        ic = Iconv.new(encoding, 'UTF-8')
147
        txtar = ""
148
        begin
149
          txtar += ic.iconv(str)
150
        rescue Iconv::IllegalSequence
151
          txtar += $!.success
152
          str = '?' + $!.failed[1, $!.failed.length]
153
          retry
154
        rescue
155
          txtar += $!.success
156
        end
157
        str = txtar
158
      end
159
    end
160
  end
161
end
.svn/pristine/22/22a7851f8ede366924cba144fbbe8879121ee70d.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 RoutingWelcomeTest < ActionController::IntegrationTest
21
  def test_welcome
22
    assert_routing(
23
        { :method => 'get', :path => "/" },
24
        { :controller => 'welcome', :action => 'index' }
25
      )
26
    assert_routing(
27
        { :method => 'get', :path => "/robots.txt" },
28
        { :controller => 'welcome', :action => 'robots' }
29
      )
30
  end
31
end

Also available in: Unified diff