comparison plugins/redmine_checkout/init.rb @ 1484:51364c0cd58f redmine-2.4-integration

Merge from live branch. Still need to merge manually in files overridden by plugins.
author Chris Cannam
date Wed, 15 Jan 2014 09:59:14 +0000
parents 22ab16c93c1c
children
comparison
equal deleted inserted replaced
1464:261b3d9a4903 1484:51364c0cd58f
1 require 'redmine'
2
3 ActionDispatch::Callbacks.to_prepare do
4 # Patches
5 require_dependency 'checkout/settings_controller_patch'
6
7 require_dependency 'checkout/repositories_helper_patch'
8 require_dependency 'checkout/repository_patch'
9
10 require_dependency 'checkout/settings_helper_patch'
11 require_dependency 'checkout/setting_patch'
12 end
13
14 # Hooks
15 require 'checkout/repository_hooks'
16
17 Redmine::Plugin.register :redmine_checkout do
18 name 'Redmine Checkout plugin'
19 url 'http://dev.holgerjust.de/projects/redmine-checkout'
20 author 'Holger Just'
21 author_url 'http://meine-er.de'
22 description 'Add links to the actual repository to the repository view.'
23 version '0.5'
24
25 requires_redmine :version_or_higher => '0.9'
26
27 settings_defaults = HashWithIndifferentAccess.new({
28 'display_login' => nil,
29 'use_zero_clipboard' => '1',
30
31 'display_checkout_info' => '1',
32 'description_Abstract' => <<-EOF
33 The data contained in this repository can be downloaded to your computer using one of several clients.
34 Please see the documentation of your version control software client for more information.
35
36 Please select the desired protocol below to get the URL.
37 EOF
38 })
39
40 # this is needed for setting the defaults
41 require 'checkout/repository_patch'
42
43 CheckoutHelper.supported_scm.each do |scm|
44 klazz = "Repository::#{scm}".constantize
45
46 settings_defaults["description_#{scm}"] = ''
47 settings_defaults["overwrite_description_#{scm}"] = '0'
48 settings_defaults["display_command_#{scm}"] = '0'
49
50 # access can be one of
51 # read+write => this protocol always allows read/write access
52 # read-only => this protocol always allows read access only
53 # permission => Access depends on redmine permissions
54 settings_defaults["protocols_#{scm}"] = [HashWithIndifferentAccess.new({
55 :protocol => scm,
56 :command => klazz.checkout_default_command,
57 :regex => '',
58 :regex_replacement => '',
59 :fixed_url => '',
60 :access => 'permission',
61 :append_path => (klazz.allow_subtree_checkout? ? '1' : '0'),
62 :is_default => '1'
63 })]
64 end
65
66 settings :default => settings_defaults, :partial => 'settings/redmine_checkout'
67
68 Redmine::WikiFormatting::Macros.register do
69 desc <<-EOF
70 Creates a checkout link to the actual repository. Example:
71
72 use the default checkout protocol !{{repository}}
73 or use a specific protocol !{{repository(SVN)}}
74 or use the checkout protocol of a specific specific project: !{{repository(projectname:SVN)}}"
75 EOF
76
77 macro :repository do |obj, args|
78 proto = args.first
79 if proto.to_s =~ %r{^([^\:]+)\:(.*)$}
80 project_identifier, proto = $1, $2
81 project = Project.find_by_identifier(project_identifier) || Project.find_by_name(project_identifier)
82 else
83 project = @project
84 end
85
86 if project && project.repository
87 protocols = project.repository.checkout_protocols.select{|p| p.access_rw(User.current)}
88
89 if proto.present?
90 proto_obj = protocols.find{|p| p.protocol.downcase == proto.downcase}
91 else
92 proto_obj = protocols.find(&:default?) || protocols.first
93 end
94 end
95 raise "Checkout protocol #{proto} not found" unless proto_obj
96
97 cmd = (project.repository.checkout_display_command? && proto_obj.command.present?) ? proto_obj.command.strip + " " : ""
98 cmd + link_to(proto_obj.url, proto_obj.url)
99 end
100 end
101 end