rosa-build/app/controllers/platforms/platforms_controller.rb

121 lines
3.5 KiB
Ruby
Raw Normal View History

2012-01-30 20:39:34 +00:00
# -*- encoding : utf-8 -*-
class Platforms::PlatformsController < Platforms::BaseController
before_filter :authenticate_user!
skip_before_filter :authenticate_user!, :only => [:advisories, :members, :show] if APP_CONFIG['anonymous_access']
load_and_authorize_resource
2011-03-09 19:27:51 +00:00
def index
2013-05-17 11:28:38 +01:00
@platforms = @platforms.accessible_by(current_ability, :related).order(:name).paginate(:page => params[:page], :per_page => 20)
end
2011-03-09 19:27:51 +00:00
def show
end
def new
@admin_uname = current_user.uname
@admin_id = current_user.id
2011-03-09 19:27:51 +00:00
end
2011-10-25 14:07:19 +01:00
def edit
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
@admin_id = params[:admin_id]
@admin_uname = params[:admin_uname]
# FIXME: do not allow manipulate owner model, only platforms onwer_id and onwer_type
@platform.owner = @admin_id.blank? ? get_owner : User.find(@admin_id)
2011-10-17 15:27:07 +01:00
if @platform.save
flash[:notice] = I18n.t("flash.platform.created")
2011-12-13 13:27:27 +00:00
redirect_to @platform
else
flash[:error] = I18n.t("flash.platform.create_error")
flash[:warning] = @platform.errors.full_messages.join('. ')
2011-12-13 13:27:27 +00:00
render :action => :new
end
end
def update
@admin_id = params[:admin_id]
@admin_uname = params[:admin_uname]
if @platform.update_attributes(
:owner => @admin_id.blank? ? get_owner : User.find(@admin_id),
:description => params[:platform][:description],
:released => (params[:platform][:released] || @platform.released)
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
flash[:error] = I18n.t("flash.platform.save_error")
flash[:warning] = @platform.errors.full_messages.join('. ')
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
@cloned = Platform.new
@cloned.name = @platform.name + "_clone"
@cloned.description = @platform.description + "_clone"
end
def make_clone
@cloned = @platform.full_clone params[:platform].merge(:owner => current_user)
if @cloned.persisted?
flash[:notice] = I18n.t("flash.platform.clone_success")
redirect_to @cloned
2011-05-30 10:04:32 +01:00
else
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
@platform.destroy # later with resque
2011-03-31 03:00:21 +01:00
flash[:notice] = t("flash.platform.destroyed")
redirect_to platforms_path
2011-03-09 19:27:51 +00:00
end
def members
@members = @platform.members.order('name')
end
def remove_members
2012-09-12 21:47:39 +01:00
user_ids = params[:user_remove] ?
params[:user_remove].map{ |k, v| k if v.first == '1' }.compact : []
User.where(:id => user_ids).each{ |user| @platform.remove_member(user) }
redirect_to members_platform_path(@platform)
end
def remove_member
2012-09-12 21:47:39 +01:00
User.where(:id => params[:member_id]).each{ |user| @platform.remove_member(user) }
redirect_to members_platform_path(@platform)
end
def add_member
member = User.where(:id => params[:member_id]).first
if !member
flash[:error] = t("flash.collaborators.wrong_user", :uname => params[:member_id])
elsif @platform.add_member(member)
flash[:notice] = t('flash.platform.members.successfully_added', :name => member.uname)
else
flash[:error] = t('flash.platform.members.error_in_adding', :name => member.uname)
end
redirect_to members_platform_url(@platform)
end
def advisories
@advisories = @platform.advisories.paginate(:page => params[:page])
end
def clear
@platform.clear
flash[:notice] = t('flash.repository.clear')
redirect_to edit_platform_path(@platform)
end
2011-03-09 19:27:51 +00:00
end