2012-05-02 10:18:07 +01:00
|
|
|
class Platforms::PlatformsController < Platforms::BaseController
|
2013-08-27 16:43:30 +01:00
|
|
|
include FileStoreHelper
|
2012-05-17 16:20:03 +01:00
|
|
|
|
2015-03-04 23:19:19 +00:00
|
|
|
before_action :authenticate_user!
|
2016-03-20 09:24:23 +00:00
|
|
|
skip_before_action :authenticate_user!, only: [:members, :show] if APP_CONFIG['anonymous_access']
|
2012-05-17 16:20:03 +01:00
|
|
|
|
2011-03-09 19:27:51 +00:00
|
|
|
def index
|
2015-03-19 23:45:15 +00:00
|
|
|
authorize :platform
|
2016-06-16 13:11:08 +01:00
|
|
|
@platforms = PlatformPolicy::Scope.new(current_user, Platform).related.select(:name, :distrib_type)
|
2011-10-27 12:02:25 +01:00
|
|
|
end
|
|
|
|
|
2011-03-09 19:27:51 +00:00
|
|
|
def show
|
2016-06-16 13:11:08 +01:00
|
|
|
@repositories = @platform.repositories
|
|
|
|
@repositories = Repository.custom_sort(@repositories).paginate(page: current_page)
|
2011-03-09 19:27:51 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
2015-03-19 23:45:15 +00:00
|
|
|
authorize @platform = Platform.new
|
2014-10-24 23:43:46 +01:00
|
|
|
@admin_uname = current_user.uname
|
|
|
|
@admin_id = current_user.id
|
2011-03-09 19:27:51 +00:00
|
|
|
end
|
2012-03-11 23:08:50 +00:00
|
|
|
|
2011-10-25 14:07:19 +01:00
|
|
|
def edit
|
2015-03-19 23:45:15 +00:00
|
|
|
authorize @platform
|
2011-12-13 13:27:27 +00:00
|
|
|
@admin_id = @platform.owner.id
|
|
|
|
@admin_uname = @platform.owner.uname
|
2011-10-25 14:07:19 +01:00
|
|
|
end
|
2011-03-09 19:27:51 +00:00
|
|
|
|
|
|
|
def create
|
2015-05-20 22:35:00 +01:00
|
|
|
authorize @platform = Platform.new(platform_params)
|
2015-03-19 23:45:15 +00:00
|
|
|
@admin_id = params[:admin_id]
|
2011-12-12 15:37:28 +00:00
|
|
|
@admin_uname = params[:admin_uname]
|
2012-04-01 16:19:54 +01:00
|
|
|
# FIXME: do not allow manipulate owner model, only platforms onwer_id and onwer_type
|
2011-12-12 15:37:28 +00:00
|
|
|
@platform.owner = @admin_id.blank? ? get_owner : User.find(@admin_id)
|
2011-10-17 15:27:07 +01:00
|
|
|
|
2011-12-13 21:48:25 +00:00
|
|
|
if @platform.save
|
2012-03-15 22:56:12 +00:00
|
|
|
flash[:notice] = I18n.t("flash.platform.created")
|
2011-12-13 13:27:27 +00:00
|
|
|
redirect_to @platform
|
|
|
|
else
|
2012-03-15 22:56:12 +00:00
|
|
|
flash[:error] = I18n.t("flash.platform.create_error")
|
2014-01-21 04:51:49 +00:00
|
|
|
render action: :new
|
2011-12-13 13:27:27 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2015-03-19 23:45:15 +00:00
|
|
|
authorize @platform
|
2011-12-13 13:27:27 +00:00
|
|
|
@admin_id = params[:admin_id]
|
|
|
|
@admin_uname = params[:admin_uname]
|
|
|
|
|
2015-05-20 22:35:00 +01:00
|
|
|
pp = platform_params
|
|
|
|
pp[:owner] = User.find(@admin_id) if @admin_id.present?
|
2013-07-24 15:43:41 +01:00
|
|
|
|
2014-02-11 20:23:34 +00:00
|
|
|
respond_to do |format|
|
|
|
|
format.html do
|
2015-05-20 22:35:00 +01:00
|
|
|
if @platform.update_attributes(pp)
|
2014-02-11 20:23:34 +00:00
|
|
|
flash[:notice] = I18n.t("flash.platform.saved")
|
|
|
|
redirect_to @platform
|
|
|
|
else
|
|
|
|
flash[:error] = I18n.t("flash.platform.save_error")
|
|
|
|
render action: :edit
|
|
|
|
end
|
|
|
|
end
|
|
|
|
format.json do
|
2015-05-20 22:35:00 +01:00
|
|
|
if @platform.update_attributes(pp)
|
2014-02-11 20:23:34 +00:00
|
|
|
render json: { notice: I18n.t("flash.platform.saved") }.to_json
|
|
|
|
else
|
2014-02-12 16:23:07 +00:00
|
|
|
render json: { error: I18n.t("flash.platform.save_error") }.to_json, status: 422
|
2014-02-11 20:23:34 +00:00
|
|
|
end
|
|
|
|
end
|
2013-06-26 10:00:51 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-08-23 19:58:29 +01:00
|
|
|
def regenerate_metadata
|
2015-03-19 23:45:15 +00:00
|
|
|
authorize @platform
|
2013-08-23 19:58:29 +01:00
|
|
|
if @platform.regenerate
|
|
|
|
flash[:notice] = I18n.t('flash.platform.saved')
|
|
|
|
else
|
|
|
|
flash[:error] = I18n.t('flash.platform.save_error')
|
|
|
|
end
|
|
|
|
redirect_to edit_platform_path(@platform)
|
|
|
|
end
|
|
|
|
|
2013-06-26 10:00:51 +01:00
|
|
|
def change_visibility
|
2015-03-19 23:45:15 +00:00
|
|
|
authorize @platform
|
2013-06-26 10:00:51 +01:00
|
|
|
if @platform.change_visibility
|
2011-12-13 13:27:27 +00:00
|
|
|
flash[:notice] = I18n.t("flash.platform.saved")
|
2011-10-17 15:27:07 +01:00
|
|
|
redirect_to @platform
|
|
|
|
else
|
2011-12-28 02:57:42 +00:00
|
|
|
flash[:error] = I18n.t("flash.platform.save_error")
|
2012-04-01 16:19:54 +01:00
|
|
|
flash[:warning] = @platform.errors.full_messages.join('. ')
|
2014-01-21 04:51:49 +00:00
|
|
|
render action: :edit
|
2011-10-17 15:27:07 +01:00
|
|
|
end
|
2011-03-09 19:27:51 +00:00
|
|
|
end
|
|
|
|
|
2011-05-30 10:04:32 +01:00
|
|
|
def clone
|
2015-03-19 23:45:15 +00:00
|
|
|
authorize @platform
|
2012-02-21 21:27:11 +00:00
|
|
|
@cloned = Platform.new
|
|
|
|
@cloned.name = @platform.name + "_clone"
|
|
|
|
@cloned.description = @platform.description + "_clone"
|
|
|
|
end
|
|
|
|
|
|
|
|
def make_clone
|
2015-03-19 23:45:15 +00:00
|
|
|
authorize @platform
|
2015-05-20 22:35:00 +01:00
|
|
|
@cloned = @platform.full_clone platform_params.merge(owner: current_user)
|
2012-02-22 20:24:29 +00:00
|
|
|
if @cloned.persisted?
|
2012-02-21 21:27:11 +00:00
|
|
|
flash[:notice] = I18n.t("flash.platform.clone_success")
|
|
|
|
redirect_to @cloned
|
2011-05-30 10:04:32 +01:00
|
|
|
else
|
2012-02-21 21:27:11 +00:00
|
|
|
flash[:error] = @cloned.errors.full_messages.join('. ')
|
|
|
|
render 'clone'
|
2011-05-30 10:04:32 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-03-09 19:27:51 +00:00
|
|
|
def destroy
|
2015-03-19 23:45:15 +00:00
|
|
|
authorize @platform
|
2012-06-16 23:51:02 +01:00
|
|
|
@platform.destroy # later with resque
|
2011-03-31 03:00:21 +01:00
|
|
|
flash[:notice] = t("flash.platform.destroyed")
|
2012-03-15 22:56:12 +00:00
|
|
|
redirect_to platforms_path
|
2011-03-09 19:27:51 +00:00
|
|
|
end
|
2012-03-20 16:24:18 +00:00
|
|
|
|
|
|
|
def members
|
2015-03-19 23:45:15 +00:00
|
|
|
authorize @platform
|
2014-03-24 18:37:51 +00:00
|
|
|
@members = @platform.members.order(:uname)
|
2012-03-20 16:24:18 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def remove_members
|
2015-03-19 23:45:15 +00:00
|
|
|
authorize @platform
|
2014-11-11 23:50:15 +00:00
|
|
|
User.where(id: params[:members]).each do |user|
|
|
|
|
@platform.remove_member(user)
|
|
|
|
end
|
2012-03-20 16:24:18 +00:00
|
|
|
redirect_to members_platform_path(@platform)
|
|
|
|
end
|
|
|
|
|
|
|
|
def add_member
|
2015-03-19 23:45:15 +00:00
|
|
|
authorize @platform
|
|
|
|
member = User.find_by(id: params[:member_id])
|
2012-11-13 14:29:45 +00:00
|
|
|
if !member
|
2014-01-21 04:51:49 +00:00
|
|
|
flash[:error] = t("flash.collaborators.wrong_user", uname: params[:member_id])
|
2012-11-13 14:29:45 +00:00
|
|
|
elsif @platform.add_member(member)
|
2014-01-21 04:51:49 +00:00
|
|
|
flash[:notice] = t('flash.platform.members.successfully_added', name: member.uname)
|
2012-11-13 14:29:45 +00:00
|
|
|
else
|
2014-01-21 04:51:49 +00:00
|
|
|
flash[:error] = t('flash.platform.members.error_in_adding', name: member.uname)
|
2012-03-20 16:24:18 +00:00
|
|
|
end
|
|
|
|
redirect_to members_platform_url(@platform)
|
|
|
|
end
|
|
|
|
|
2012-06-21 08:15:20 +01:00
|
|
|
def clear
|
2015-03-19 23:45:15 +00:00
|
|
|
authorize @platform
|
2012-06-21 08:15:20 +01:00
|
|
|
@platform.clear
|
|
|
|
flash[:notice] = t('flash.repository.clear')
|
2012-06-20 19:02:42 +01:00
|
|
|
redirect_to edit_platform_path(@platform)
|
|
|
|
end
|
|
|
|
|
2015-03-19 23:45:15 +00:00
|
|
|
private
|
|
|
|
|
2015-05-20 22:35:00 +01:00
|
|
|
def platform_params
|
|
|
|
subject_params(Platform)
|
|
|
|
end
|
|
|
|
|
2015-03-19 23:45:15 +00:00
|
|
|
def load_platform
|
2016-06-16 13:11:08 +01:00
|
|
|
return unless params[:id]
|
|
|
|
authorize @platform = Platform.find_cached(params[:id]), :show?
|
2015-03-19 23:45:15 +00:00
|
|
|
end
|
|
|
|
|
2011-03-09 19:27:51 +00:00
|
|
|
end
|