rosa-build/app/controllers/platforms_controller.rb

124 lines
3.5 KiB
Ruby
Raw Normal View History

2011-09-15 18:56:20 +01:00
# coding: UTF-8
2011-03-09 19:27:51 +00:00
class PlatformsController < ApplicationController
before_filter :authenticate_user!, :except => :easy_urpmi
2011-10-31 21:55:56 +00:00
before_filter :find_platform, :only => [:freeze, :unfreeze, :clone, :edit, :destroy]
2011-10-17 15:27:07 +01:00
before_filter :get_paths, :only => [:new, :create]
2011-10-31 21:55:56 +00:00
before_filter :check_global_access, :only => [:index, :new, :create]#:except => :easy_urpmi
2011-03-09 19:27:51 +00:00
def index
@platforms = Platform.visible_to(current_user).paginate(:page => params[:platform_page])
end
def easy_urpmi
2011-10-31 15:19:55 +00:00
@platforms = Platform.where(:distrib_type => APP_CONFIG['distr_types'].first, :visibility => 'open', :platform_type => 'main')
respond_to do |format|
format.json do
render :json => {
:platforms => @platforms.map do |p|
{:name => p.unixname,
:architectures => ['i586', 'x86_64'],
:repositories => p.repositories.map(&:unixname),
:url => "http://#{request.host_with_port}/downloads/platforms/#{p.unixname}/repository"}
end
}
end
end
2011-03-09 19:27:51 +00:00
end
def show
@platform = Platform.find params[:id], :include => :repositories
2011-10-31 21:55:56 +00:00
can_perform? @platform if @platform
@repositories = @platform.repositories
2011-10-17 15:27:07 +01:00
@members = @platform.members.uniq
2011-03-09 19:27:51 +00:00
end
def new
@platforms = Platform.visible_to current_user
2011-03-09 19:27:51 +00:00
@platform = Platform.new
end
2011-10-25 14:07:19 +01:00
def edit
2011-10-31 18:14:25 +00:00
can_perform? @platform if @platform
@platforms = Platform.visible_to current_user
2011-10-25 14:07:19 +01:00
end
2011-03-09 19:27:51 +00:00
def create
2011-10-17 15:27:07 +01:00
@platform = Platform.new params[:platform]
@platform.owner = get_owner
2011-10-17 15:27:07 +01:00
if @platform.save
flash[:notice] = I18n.t("flash.platform.saved")
redirect_to @platform
else
flash[:error] = I18n.t("flash.platform.saved_error")
@platforms = Platform.visible_to current_user
2011-10-17 15:27:07 +01:00
render :action => :new
end
2011-03-09 19:27:51 +00:00
end
2011-03-17 14:47:16 +00:00
def freeze
2011-10-31 18:14:25 +00:00
can_perform? @platform if @platform
2011-03-17 14:47:16 +00:00
@platform.released = true
if @platform.save
flash[:notice] = I18n.t("flash.platform.freezed")
else
flash[:notice] = I18n.t("flash.platform.freeze_error")
end
2011-03-17 14:47:16 +00:00
redirect_to @platform
end
def unfreeze
2011-10-31 18:14:25 +00:00
can_perform? @platform if @platform
2011-03-17 14:47:16 +00:00
@platform.released = false
if @platform.save
flash[:notice] = I18n.t("flash.platform.unfreezed")
else
flash[:notice] = I18n.t("flash.platform.unfreeze_error")
end
redirect_to @platform
end
2011-05-30 10:04:32 +01:00
def clone
2011-10-31 18:14:25 +00:00
can_perform? @platform if @platform
2011-05-30 10:04:32 +01:00
cloned = @platform.clone(@platform.name + "_clone", @platform.unixname + "_clone")
if cloned
flash[:notice] = 'Клонирование успешно'
redirect_to cloned
else
flash[:notice] = 'Ошибка клонирования'
redirect_to @platform
end
end
2011-03-09 19:27:51 +00:00
def destroy
2011-10-31 18:14:25 +00:00
can_perform? @platform if @platform
2011-10-31 21:55:56 +00:00
@platform.destroy if @platform
2011-03-31 03:00:21 +01:00
flash[:notice] = t("flash.platform.destroyed")
2011-03-09 19:27:51 +00:00
redirect_to root_path
end
2011-03-17 14:47:16 +00:00
protected
2011-10-17 15:27:07 +01:00
def get_paths
if params[:user_id]
@user = User.find params[:user_id]
@platforms_path = user_platforms_path @user
@new_platform_path = new_user_platform_path @user
elsif params[:group_id]
@group = Group.find params[:group_id]
@platforms_path = group_platforms_path @group
@new_platform_path = new_group_platform_path @group
else
@platforms_path = platforms_path
@new_platform_path = new_platform_path
end
end
2011-03-17 14:47:16 +00:00
def find_platform
@platform = Platform.find params[:id]
end
2011-03-09 19:27:51 +00:00
end