ssh_access_controller.rb revision f198c0ec200763fe1b0db998cd9418f412be8361
45312f52ff3a3d4c137447be4c7556500c2f8bf2Timo Sirainenclass SSHAccessController < InheritedResources::Base
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen MIRROR_DENY_MSG = "you cannot write to a mirror repository, they are readonly"
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen belongs_to :repository, finder: :find_by_path!
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen def index
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen allowed = SSHAccess.determine_permission(
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen *SSHAccess.extract_permission_params(params, parent), parent)
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen render json: {allowed: allowed}
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen rescue SSHAccess::InvalidAccessOnMirrorError
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen render json: {allowed: false,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen reason: MIRROR_DENY_MSG,
f16c114c20bbd7d292d93415d1e56c8dd6abd3e7Timo Sirainen provide_to_user: true}
f16c114c20bbd7d292d93415d1e56c8dd6abd3e7Timo Sirainen rescue => e# ensure that we always return a valid response
f16c114c20bbd7d292d93415d1e56c8dd6abd3e7Timo Sirainen render json: {allowed: false,
f16c114c20bbd7d292d93415d1e56c8dd6abd3e7Timo Sirainen reason: "internal server problem: #{e.message}",
f16c114c20bbd7d292d93415d1e56c8dd6abd3e7Timo Sirainen provide_to_user: false}
f16c114c20bbd7d292d93415d1e56c8dd6abd3e7Timo Sirainen end
f16c114c20bbd7d292d93415d1e56c8dd6abd3e7Timo Sirainen
f16c114c20bbd7d292d93415d1e56c8dd6abd3e7Timo Sirainenend
f16c114c20bbd7d292d93415d1e56c8dd6abd3e7Timo Sirainen