2012-08-17 14:40:57 +01:00
|
|
|
# -*- encoding : utf-8 -*-
|
|
|
|
class Api::V1::RepositoriesController < Api::V1::BaseController
|
2012-09-26 18:15:11 +01:00
|
|
|
|
|
|
|
before_filter :authenticate_user!
|
2012-10-19 15:49:01 +01:00
|
|
|
skip_before_filter :authenticate_user!, :only => [:show, :projects] if APP_CONFIG['anonymous_access']
|
2012-08-17 14:40:57 +01:00
|
|
|
|
|
|
|
load_and_authorize_resource :repository, :through => :platform, :shallow => true
|
2012-09-26 18:15:11 +01:00
|
|
|
|
|
|
|
def show
|
2012-10-14 13:00:49 +01:00
|
|
|
end
|
|
|
|
|
2012-10-19 14:52:36 +01:00
|
|
|
def projects
|
|
|
|
@projects = @repository.projects.
|
|
|
|
recent.paginate(paginate_params)
|
|
|
|
end
|
|
|
|
|
2012-10-14 13:00:49 +01:00
|
|
|
def update
|
2012-10-14 13:39:58 +01:00
|
|
|
update_subject @repository
|
2012-10-14 13:00:49 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def add_member
|
2012-10-14 13:39:58 +01:00
|
|
|
add_member_to_subject @repository
|
2012-10-14 13:00:49 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def remove_member
|
2012-10-14 13:39:58 +01:00
|
|
|
remove_member_from_subject @repository
|
2012-10-14 13:00:49 +01:00
|
|
|
end
|
2012-09-26 18:15:11 +01:00
|
|
|
|
2012-10-14 13:00:49 +01:00
|
|
|
def destroy
|
2012-10-14 13:39:58 +01:00
|
|
|
destroy_subject @repository
|
2012-09-26 18:15:11 +01:00
|
|
|
end
|
|
|
|
|
2012-12-20 19:46:16 +00:00
|
|
|
def key_pair
|
|
|
|
end
|
|
|
|
|
2012-10-14 14:38:06 +01:00
|
|
|
def add_project
|
|
|
|
project = Project.where(:id => params[:project_id]).first
|
|
|
|
if project
|
|
|
|
begin
|
|
|
|
@repository.projects << project
|
|
|
|
render_json_response @repository, "Project '#{project.id}' has been added to repository successfully"
|
|
|
|
rescue ActiveRecord::RecordInvalid
|
|
|
|
render_validation_error @repository, t('flash.repository.project_not_added')
|
|
|
|
end
|
|
|
|
else
|
|
|
|
render_validation_error @repository, "Project has not been added to repository"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def remove_project
|
|
|
|
project_id = params[:project_id]
|
|
|
|
ProjectToRepository.where(:project_id => project_id, :repository_id => @repository.id).destroy_all
|
|
|
|
render_json_response @repository, "Project '#{project_id}' has been removed from repository successfully"
|
|
|
|
end
|
|
|
|
|
|
|
|
def signatures
|
|
|
|
key_pair = @repository.key_pair
|
|
|
|
key_pair.destroy if key_pair
|
2012-10-14 15:44:10 +01:00
|
|
|
key_pair = @repository.build_key_pair(params[:repository])
|
2012-10-14 14:38:06 +01:00
|
|
|
key_pair.user_id = current_user.id
|
|
|
|
if key_pair.save
|
|
|
|
render_json_response @repository, 'Signatures have been updated for repository successfully'
|
|
|
|
else
|
2012-10-15 15:06:08 +01:00
|
|
|
render_json_response @repository, error_message(key_pair, 'Signatures have not been updated for repository'), 422
|
2012-10-14 14:38:06 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|