Project

General

Profile

Feature #23894 » 0001-Planio-Add-a-read-only-API-for-repositories.patch

Holger Just, 2016-09-26 16:17

View differences:

app/controllers/repositories_controller.rb
30 30

  
31 31
  before_action :find_project_by_project_id, :only => [:new, :create]
32 32
  before_action :find_repository, :only => [:edit, :update, :destroy, :committers]
33
  before_action :find_project_repository, :except => [:new, :create, :edit, :update, :destroy, :committers]
33
  before_action :find_project_repository, :except => [:new, :create, :edit, :update, :destroy, :committers, :index]
34 34
  before_action :find_changeset, :only => [:revision, :add_related_issue, :remove_related_issue]
35
  before_action :authorize
35
  before_action :authorize, :except => [:index]
36
  before_action :authorize_global, :only => [:index]
37

  
36 38
  accept_rss_auth :revisions
39
  accept_api_auth :index
37 40

  
38 41
  rescue_from Redmine::Scm::Adapters::CommandFailed, :with => :show_error_command_failed
39 42

  
43
  def index
44
    klass = Repository.repository_class(params[:scm]) || Repository
45
    scope = klass.visible
46

  
47
    @offset, @limit = api_offset_and_limit
48

  
49
    respond_to do |format|
50
      format.html { render_404 }
51
      format.api do
52
        @repository_count = scope.count
53
        @repositories = scope.offset(@offset).limit(@limit).order("#{Project.table_name}.identifier", "#{Repository.table_name}.identifier")
54
      end
55
    end
56
  end
57

  
40 58
  def new
41 59
    scm = params[:repository_scm] || (Redmine::Scm::Base.all & Setting.enabled_scm).first
42 60
    @repository = Repository.factory(scm)
app/models/repository.rb
48 48
  validate :validate_repository_path
49 49
  attr_protected :id
50 50

  
51
  scope :visible, lambda {|*args|
52
    joins(:project).where(Project.allowed_to_condition(args.shift || User.current, :browse_repository, *args))
53
  }
54

  
51 55
  safe_attributes 'identifier',
52 56
    'login',
53 57
    'password',
app/views/repositories/index.api.rsb
1
api.array :repositories, api_meta(:total_count => @repository_count, :offset => @offset, :limit => @limit) do
2
  @repositories.each do |repository|
3
    api.repository do
4
      api.id         repository.id
5
      api.project    id: repository.project_id,
6
                     name: repository.project.name
7
      api.name       repository.name
8
      api.identifier repository.identifier
9
      api.is_default repository.is_default
10
      api.scm        repository.scm_name
11

  
12
      Redmine::Hook.call_hook :api_repositories_index, { repository: repository, api: api }
13

  
14
      api.array :branches do
15
        Array(repository.branches).each do |branch|
16
          api.branch name: branch
17
        end
18
      end if include_in_api_response?('branches')
19

  
20
      api.created_on repository.created_on
21
    end
22
  end
23
end
config/routes.rb
179 179
    get 'wiki/:id/:version/diff', :to => 'wiki#diff'
180 180
  end
181 181

  
182
  resources :repositories, :only => [:index]
183

  
182 184
  resources :issues do
183 185
    member do
184 186
      # Used when updating the form of an existing issue
lib/redmine.rb
162 162

  
163 163
  map.project_module :repository do |map|
164 164
    map.permission :view_changesets, {:repositories => [:show, :revisions, :revision]}, :read => true
165
    map.permission :browse_repository, {:repositories => [:show, :browse, :entry, :raw, :annotate, :changes, :diff, :stats, :graph]}, :read => true
165
    map.permission :browse_repository, {:repositories => [:show, :browse, :entry, :raw, :annotate, :changes, :diff, :stats, :graph, :index]}, :read => true
166 166
    map.permission :commit_access, {}
167 167
    map.permission :manage_related_issues, {:repositories => [:add_related_issue, :remove_related_issue]}
168 168
    map.permission :manage_repository, {:repositories => [:new, :create, :edit, :update, :committers, :destroy]}, :require => :member
(2-2/2)