Revision 912:5e80956cc792 .svn/pristine/0f

View differences:

.svn/pristine/0f/0f12084a6a3192cb0d61cbd2f3ef681df419cac4.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
class Message < ActiveRecord::Base
19
  belongs_to :board
20
  belongs_to :author, :class_name => 'User', :foreign_key => 'author_id'
21
  acts_as_tree :counter_cache => :replies_count, :order => "#{Message.table_name}.created_on ASC"
22
  acts_as_attachable
23
  belongs_to :last_reply, :class_name => 'Message', :foreign_key => 'last_reply_id'
24

  
25
  acts_as_searchable :columns => ['subject', 'content'],
26
                     :include => {:board => :project},
27
                     :project_key => "#{Board.table_name}.project_id",
28
                     :date_column => "#{table_name}.created_on"
29
  acts_as_event :title => Proc.new {|o| "#{o.board.name}: #{o.subject}"},
30
                :description => :content,
31
                :type => Proc.new {|o| o.parent_id.nil? ? 'message' : 'reply'},
32
                :url => Proc.new {|o| {:controller => 'messages', :action => 'show', :board_id => o.board_id}.merge(o.parent_id.nil? ? {:id => o.id} :
33
                                                                                                                                       {:id => o.parent_id, :r => o.id, :anchor => "message-#{o.id}"})}
34

  
35
  acts_as_activity_provider :find_options => {:include => [{:board => :project}, :author]},
36
                            :author_key => :author_id
37
  acts_as_watchable
38

  
39
  attr_protected :locked, :sticky
40
  validates_presence_of :board, :subject, :content
41
  validates_length_of :subject, :maximum => 255
42
  validate :cannot_reply_to_locked_topic, :on => :create
43

  
44
  after_create :add_author_as_watcher, :update_parent_last_reply
45
  after_update :update_messages_board
46
  after_destroy :reset_board_counters
47

  
48
  named_scope :visible, lambda {|*args| { :include => {:board => :project},
49
                                          :conditions => Project.allowed_to_condition(args.shift || User.current, :view_messages, *args) } }
50

  
51
  def visible?(user=User.current)
52
    !user.nil? && user.allowed_to?(:view_messages, project)
53
  end
54

  
55
  def cannot_reply_to_locked_topic
56
    # Can not reply to a locked topic
57
    errors.add :base, 'Topic is locked' if root.locked? && self != root
58
  end
59

  
60
  def update_parent_last_reply
61
    if parent
62
      parent.reload.update_attribute(:last_reply_id, self.id)
63
    end
64
    board.reset_counters!
65
  end
66

  
67
  def update_messages_board
68
    if board_id_changed?
69
      Message.update_all("board_id = #{board_id}", ["id = ? OR parent_id = ?", root.id, root.id])
70
      Board.reset_counters!(board_id_was)
71
      Board.reset_counters!(board_id)
72
    end
73
  end
74

  
75
  def reset_board_counters
76
    board.reset_counters!
77
  end
78

  
79
  def sticky=(arg)
80
    write_attribute :sticky, (arg == true || arg.to_s == '1' ? 1 : 0)
81
  end
82

  
83
  def sticky?
84
    sticky == 1
85
  end
86

  
87
  def project
88
    board.project
89
  end
90

  
91
  def editable_by?(usr)
92
    usr && usr.logged? && (usr.allowed_to?(:edit_messages, project) || (self.author == usr && usr.allowed_to?(:edit_own_messages, project)))
93
  end
94

  
95
  def destroyable_by?(usr)
96
    usr && usr.logged? && (usr.allowed_to?(:delete_messages, project) || (self.author == usr && usr.allowed_to?(:delete_own_messages, project)))
97
  end
98

  
99
  private
100

  
101
  def add_author_as_watcher
102
    Watcher.create(:watchable => self.root, :user => author)
103
  end
104
end
.svn/pristine/0f/0f55ca10803bce4cf5a650e17d0e04f01a9b964d.svn-base
1
<div class="splitcontentleft">
2
<% if @group.users.any? %>
3
  <table class="list users">
4
    <thead><tr>
5
      <th><%= l(:label_user) %></th>
6
      <th style="width:15%"></th>
7
    </tr></thead>
8
    <tbody>
9
    <% @group.users.sort.each do |user| %>
10
      <tr id="user-<%= user.id %>" class="<%= cycle 'odd', 'even' %>">
11
        <td class="user"><%= link_to_user user %></td>
12
        <td class="buttons">
13
            <%= link_to_remote l(:button_delete), { :url => group_user_path(@group, :user_id => user), :method => :delete }, :class => 'icon icon-del' %>
14
        </td>
15
      </tr>
16
    <% end %>
17
    </tbody>
18
  </table>
19
<% else %>
20
  <p class="nodata"><%= l(:label_no_data) %></p>
21
<% end %>
22
</div>
23

  
24
<div class="splitcontentright">
25
<% users = User.active.not_in_group(@group).all(:limit => 100) %>
26
<% if users.any? %>
27
  <% remote_form_for(@group, :url => group_users_path(@group), :html => {:method => :post}) do |f| %>
28
    <fieldset><legend><%=l(:label_user_new)%></legend>
29

  
30
    <p><%= label_tag "user_search", l(:label_user_search) %><%= text_field_tag 'user_search', nil %></p>
31
    <%= observe_field(:user_search,
32
                 :frequency => 0.5,
33
                 :update => :users,
34
                 :url => autocomplete_for_user_group_path(@group),
35
                 :method => :get,
36
                 :with => 'q')
37
                  %>
38

  
39
    <div id="users">
40
      <%= principals_check_box_tags 'user_ids[]', users %>
41
    </div>
42

  
43
    <p><%= submit_tag l(:button_add) %></p>
44
    </fieldset>
45
  <% end %>
46
<% end %>
47

  
48
</div>
.svn/pristine/0f/0f5d0b28aa88dc0b634f0aed6c20653f95af7206.svn-base
1
module CodeRay
2
  
3
  # = FileType
4
  #
5
  # A simple filetype recognizer.
6
  #
7
  # == Usage
8
  #
9
  #  # determine the type of the given
10
  #  lang = FileType[file_name]
11
  #  
12
  #  # return :text if the file type is unknown
13
  #  lang = FileType.fetch file_name, :text
14
  #  
15
  #  # try the shebang line, too
16
  #  lang = FileType.fetch file_name, :text, true
17
  module FileType
18
    
19
    UnknownFileType = Class.new Exception
20
    
21
    class << self
22
      
23
      # Try to determine the file type of the file.
24
      #
25
      # +filename+ is a relative or absolute path to a file.
26
      #
27
      # The file itself is only accessed when +read_shebang+ is set to true.
28
      # That means you can get filetypes from files that don't exist.
29
      def [] filename, read_shebang = false
30
        name = File.basename filename
31
        ext = File.extname(name).sub(/^\./, '')  # from last dot, delete the leading dot
32
        ext2 = filename.to_s[/\.(.*)/, 1]  # from first dot
33
        
34
        type =
35
          TypeFromExt[ext] ||
36
          TypeFromExt[ext.downcase] ||
37
          (TypeFromExt[ext2] if ext2) ||
38
          (TypeFromExt[ext2.downcase] if ext2) ||
39
          TypeFromName[name] ||
40
          TypeFromName[name.downcase]
41
        type ||= shebang(filename) if read_shebang
42
        
43
        type
44
      end
45
      
46
      # This works like Hash#fetch.
47
      #
48
      # If the filetype cannot be found, the +default+ value
49
      # is returned.
50
      def fetch filename, default = nil, read_shebang = false
51
        if default && block_given?
52
          warn 'Block supersedes default value argument; use either.'
53
        end
54
        
55
        if type = self[filename, read_shebang]
56
          type
57
        else
58
          return yield if block_given?
59
          return default if default
60
          raise UnknownFileType, 'Could not determine type of %p.' % filename
61
        end
62
      end
63
      
64
    protected
65
      
66
      def shebang filename
67
        return unless File.exist? filename
68
        File.open filename, 'r' do |f|
69
          if first_line = f.gets
70
            if type = first_line[TypeFromShebang]
71
              type.to_sym
72
            end
73
          end
74
        end
75
      end
76
      
77
    end
78
    
79
    TypeFromExt = {
80
      'c'        => :c,
81
      'cfc'      => :xml,
82
      'cfm'      => :xml,
83
      'clj'      => :clojure,
84
      'css'      => :css,
85
      'diff'     => :diff,
86
      'dpr'      => :delphi,
87
      'gemspec'  => :ruby,
88
      'groovy'   => :groovy,
89
      'gvy'      => :groovy,
90
      'h'        => :c,
91
      'haml'     => :haml,
92
      'htm'      => :page,
93
      'html'     => :page,
94
      'html.erb' => :erb,
95
      'java'     => :java,
96
      'js'       => :java_script,
97
      'json'     => :json,
98
      'mab'      => :ruby,
99
      'pas'      => :delphi,
100
      'patch'    => :diff,
101
      'php'      => :php,
102
      'php3'     => :php,
103
      'php4'     => :php,
104
      'php5'     => :php,
105
      'prawn'    => :ruby,
106
      'py'       => :python,
107
      'py3'      => :python,
108
      'pyw'      => :python,
109
      'rake'     => :ruby,
110
      'raydebug' => :raydebug,
111
      'rb'       => :ruby,
112
      'rbw'      => :ruby,
113
      'rhtml'    => :erb,
114
      'rjs'      => :ruby,
115
      'rpdf'     => :ruby,
116
      'ru'       => :ruby,
117
      'rxml'     => :ruby,
118
      # 'sch'      => :scheme,
119
      'sql'      => :sql,
120
      # 'ss'       => :scheme,
121
      'xhtml'    => :page,
122
      'xml'      => :xml,
123
      'yaml'     => :yaml,
124
      'yml'      => :yaml,
125
    }
126
    for cpp_alias in %w[cc cpp cp cxx c++ C hh hpp h++ cu]
127
      TypeFromExt[cpp_alias] = :cpp
128
    end
129
    
130
    TypeFromShebang = /\b(?:ruby|perl|python|sh)\b/
131
    
132
    TypeFromName = {
133
      'Capfile'  => :ruby,
134
      'Rakefile' => :ruby,
135
      'Rantfile' => :ruby,
136
      'Gemfile'  => :ruby,
137
    }
138
    
139
  end
140
  
141
end
.svn/pristine/0f/0f71516e3a6532ada8045e94e42972a11451afc4.svn-base
1
class CommentsController < ApplicationController
2
  default_search_scope :news
3
  model_object News
4
  before_filter :find_model_object
5
  before_filter :find_project_from_association
6
  before_filter :authorize
7

  
8
  verify :method => :post, :only => :create, :render => {:nothing => true, :status => :method_not_allowed }
9
  def create
10
    @comment = Comment.new(params[:comment])
11
    @comment.author = User.current
12
    if @news.comments << @comment
13
      flash[:notice] = l(:label_comment_added)
14
    end
15

  
16
    redirect_to :controller => 'news', :action => 'show', :id => @news
17
  end
18

  
19
  verify :method => :delete, :only => :destroy, :render => {:nothing => true, :status => :method_not_allowed }
20
  def destroy
21
    @news.comments.find(params[:comment_id]).destroy
22
    redirect_to :controller => 'news', :action => 'show', :id => @news
23
  end
24

  
25
  private
26

  
27
  # ApplicationController's find_model_object sets it based on the controller
28
  # name so it needs to be overriden and set to @news instead
29
  def find_model_object
30
    super
31
    @news = @object
32
    @comment = nil
33
    @news
34
  end
35

  
36
end
.svn/pristine/0f/0f842304e58a7a419abba90bd185840b383c9907.svn-base
1
module Engines
2
  class Plugin
3
    class FileSystemLocator < Rails::Plugin::FileSystemLocator
4
      def create_plugin(path)
5
        plugin = Engines::Plugin.new(path)
6
        plugin.valid? ? plugin : nil
7
      end        
8
    end
9
  end
10
end
11

  
.svn/pristine/0f/0f8c9a445e6d91ddf83b84884895ce07bce0d526.svn-base
1
class AddProjectStatus < ActiveRecord::Migration
2
  def self.up
3
    add_column :projects, :status, :integer, :default => 1, :null => false
4
  end
5

  
6
  def self.down
7
    remove_column :projects, :status
8
  end
9
end
.svn/pristine/0f/0fa8b994f508f388585e802196325aae4a4107f7.svn-base
1
<%= error_messages_for 'user' %>
2

  
3
<div id="user_form">
4
<!--[form:user]-->
5
<div class="splitcontentleft">
6
<fieldset class="box tabular">
7
  <legend><%=l(:label_information_plural)%></legend>
8
  <p><%= f.text_field :login, :required => true, :size => 25  %></p>
9
  <p><%= f.text_field :firstname, :required => true %></p>
10
  <p><%= f.text_field :lastname, :required => true %></p>
11
  <p><%= f.text_field :mail, :required => true %></p>
12
  <p><%= f.select :language, lang_options_for_select %></p>
13
  <% if Setting.openid? %>
14
  <p><%= f.text_field :identity_url  %></p>
15
  <% end %>
16

  
17
  <% @user.custom_field_values.each do |value| %>
18
    <p><%= custom_field_tag_with_label :user, value %></p>
19
  <% end %>
20

  
21
  <p><%= f.check_box :admin, :disabled => (@user == User.current) %></p>
22
  <%= call_hook(:view_users_form, :user => @user, :form => f) %>
23
</fieldset>
24

  
25
<fieldset class="box tabular">
26
  <legend><%=l(:label_authentication)%></legend>
27
  <% unless @auth_sources.empty? %>
28
  <p><%= f.select :auth_source_id, ([[l(:label_internal), ""]] + @auth_sources.collect { |a| [a.name, a.id] }), {}, :onchange => "if (this.value=='') {Element.show('password_fields');} else {Element.hide('password_fields');}" %></p>
29
  <% end %>
30
  <div id="password_fields" style="<%= 'display:none;' if @user.auth_source %>">
31
  <p><%= f.password_field :password, :required => true, :size => 25  %><br />
32
  <em><%= l(:text_caracters_minimum, :count => Setting.password_min_length) %></em></p>
33
  <p><%= f.password_field :password_confirmation, :required => true, :size => 25  %></p>
34
  </div>
35
</fieldset>
36
</div>
37

  
38
<div class="splitcontentright">
39
<fieldset class="box">
40
  <legend><%=l(:field_mail_notification)%></legend>
41
  <%= render :partial => 'users/mail_notifications' %>
42
</fieldset>
43

  
44
<fieldset class="box tabular">
45
  <legend><%=l(:label_preferences)%></legend>
46
  <%= render :partial => 'users/preferences' %>
47
</fieldset>
48
</div>
49
</div>
50
<div style="clear:left;"></div>
51
<!--[eoform:user]-->
.svn/pristine/0f/0fd45ffc205637b86a8a066d7efda723815c1464.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
require 'settings_controller'
20

  
21
# Re-raise errors caught by the controller.
22
class SettingsController; def rescue_action(e) raise e end; end
23

  
24
class SettingsControllerTest < ActionController::TestCase
25
  fixtures :users
26

  
27
  def setup
28
    @controller = SettingsController.new
29
    @request    = ActionController::TestRequest.new
30
    @response   = ActionController::TestResponse.new
31
    User.current = nil
32
    @request.session[:user_id] = 1 # admin
33
  end
34

  
35
  def test_index
36
    get :index
37
    assert_response :success
38
    assert_template 'edit'
39
  end
40

  
41
  def test_get_edit
42
    get :edit
43
    assert_response :success
44
    assert_template 'edit'
45

  
46
    assert_tag 'input', :attributes => {:name => 'settings[enabled_scm][]', :value => ''}
47
  end
48

  
49
  def test_post_edit_notifications
50
    post :edit, :settings => {:mail_from => 'functional@test.foo',
51
                              :bcc_recipients  => '0',
52
                              :notified_events => %w(issue_added issue_updated news_added),
53
                              :emails_footer => 'Test footer'
54
                              }
55
    assert_redirected_to '/settings/edit'
56
    assert_equal 'functional@test.foo', Setting.mail_from
57
    assert !Setting.bcc_recipients?
58
    assert_equal %w(issue_added issue_updated news_added), Setting.notified_events
59
    assert_equal 'Test footer', Setting.emails_footer
60
  end
61
end
.svn/pristine/0f/0ff0bfae04ec7a8241921bdb8bb6771c6ffcd5d9.svn-base
1
api.version do
2
  api.id @version.id
3
  api.project(:id => @version.project_id, :name => @version.project.name) unless @version.project.nil?
4

  
5
  api.name        @version.name
6
  api.description @version.description
7
  api.status      @version.status
8
  api.due_date    @version.effective_date
9

  
10
  render_api_custom_values @version.custom_field_values, api
11

  
12
  api.created_on @version.created_on
13
  api.updated_on @version.updated_on
14
end

Also available in: Unified diff