Merge branch 'private_repos'

Conflicts:
	config/application.yml.sample
	config/locales/ru.yml
	config/routes.rb
	db/schema.rb
This commit is contained in:
George Vinogradov 2011-10-20 19:49:35 +04:00
commit 1659ad5805
16 changed files with 200 additions and 0 deletions

View File

@ -0,0 +1,17 @@
class PrivateUsersController < ApplicationController
def index
@private_users = PrivateUser.where(:platform_id => params[:platform_id]).paginate :page => params[:page]
@platform = Platform.find(params[:platform_id])
end
def create
pair = PrivateUser.generate_pair(params[:platform_id])
redirect_to platform_private_users_path(params[:platform_id]),
:notice => "Логин: #{ pair[:login] } Пароль: #{ pair[:pass] }"
end
def destroy
PrivateUser.find(params[:id]).destroy
redirect_to platform_private_users_path(params[:platform_id])
end
end

View File

@ -0,0 +1,32 @@
class PrivatesController < ApplicationController
require 'digest/sha2'
before_filter :find_platform
before_filter :authenticate
def show
file_name = "#{APP_CONFIG['private_repo_path']}/#{params[:platform_name]}/#{params[:file_path]}"
if File.directory?(file_name) || !File.exists?(file_name)
render :file => "#{Rails.root}/public/404.html", :layout => false, :status => 404
else
send_file file_name
end
end
protected
def authenticate
authenticate_or_request_with_http_basic do |username, password|
PrivateUser.exists?(
:login => username,
:password => Digest::SHA2.new.hexdigest(password),
:platform_id => @platform.try(:id)
)
end
end
def find_platform
@platform = Platform.find_by_name(params[:platform_name])
end
end

View File

@ -0,0 +1,2 @@
module PrivateUsersHelper
end

View File

@ -0,0 +1,2 @@
module PrivatesHelper
end

View File

@ -0,0 +1,21 @@
class PrivateUser < ActiveRecord::Base
require 'digest/sha2'
require 'active_support/secure_random'
validate :login, :uniqueness => true
class << self
def generate_pair(platform_id)
login = "login_#{ActiveSupport::SecureRandom.hex(16)}"
pass = "pass_#{ActiveSupport::SecureRandom.hex(16)}"
PrivateUser.create(
:login => login,
:password => Digest::SHA2.new.hexdigest(pass),
:platform_id => platform_id
)
{:login => login, :pass => pass}
end
end
end

View File

@ -4,6 +4,7 @@
%li.first= link_to t("layout.platforms.list"), platforms_path
%li= link_to t("layout.platforms.new"), new_platform_path
%li.active= link_to t("layout.platforms.show"), platform_path
%li= link_to t("layout.platforms.private_users"), platform_private_users_path(@platform)
.content
.inner
%p

View File

@ -0,0 +1,43 @@
.block
.secondary-navigation
%ul.wat-cf
%li.first=# link_to t("layout.repositories.list"), platform_path(@platform) + "#repositories"
%li=# link_to t("layout.repositories.new"), new_platform_repository_path(@platform)
%li.active=# link_to t("layout.repositories.show"), platform_repository_path(@platform, @repository)
.content
.inner
%p
%b
= t("activerecord.attributes.platform.name")
\:
= @platform.name
%p
%b
= t("activerecord.attributes.repository.platform")
\:
= link_to @platform.name, platform_path(@platform)
.wat-cf
=# link_to image_tag("web-app-theme/icons/cross.png", :alt => t("layout.delete")) + " " + t("layout.delete"), platform_repository_path(@platform, @repository), :method => "delete", :class => "button", :confirm => t("layout.repositories.confirm_delete")
.block
.secondary-navigation
%ul.wat-cf
%li.first.active= link_to t("layout.private_users.list"), platform_private_users_path(@platform)
%li= link_to t("layout.private_users.new"), platform_private_users_path(@platform), :method => :post
.content
%h2.title
= t("layout.private_users.list_header")
.inner
%table.table
%tr
%th.first= t("activerecord.attributes.private_user.login")
%th.last &nbsp;
- @private_users.each do |private_user|
%tr{:class => cycle("odd", "even")}
%td
= link_to private_user.login, platform_private_user_path(@platform, private_user)
%td.last
#{link_to t("layout.delete"), platform_private_user_path(@platform, private_user), :method => :delete, :confirm => t("layout.private_users.confirm_delete")}
.actions-bar.wat-cf
.actions
= will_paginate @private_users

View File

@ -43,6 +43,12 @@ ru:
sessions:
sign_in_header: Вход в систему
private_users:
list: Список
new: Новая пара
list_header: Пары логин/пароль
confirm_delete: Вы уверены, что хотите удалить эту пару логин/пароль?
platforms:
list: Список
new: Создать
@ -67,6 +73,7 @@ ru:
visibility: Видимость
platform_type: Тип платформы
distrib_type: Тип дистрибутива
private_users: Пользователи приватного репозитория
repositories:
list: Список
@ -265,6 +272,10 @@ ru:
download: Статистика
attributes:
private_user:
login: Логин
password: Пароль
repository:
name: Название
platform_id: Платформа

View File

@ -40,8 +40,12 @@ Rosa::Application.routes.draw do
# end
# end
# end
#resources :privates
match '/private/:platform_name/*file_path' => 'privates#show'
resources :platforms do
resources :private_users
member do
get 'freeze'
get 'unfreeze'

View File

@ -0,0 +1,14 @@
class CreatePrivateUsers < ActiveRecord::Migration
def self.up
create_table :private_users do |t|
t.integer :platform_id
t.string :login
t.string :password
t.timestamps
end
end
def self.down
drop_table :private_users
end
end

View File

@ -123,6 +123,14 @@ ActiveRecord::Schema.define(:version => 20111018102655) do
t.string "distrib_type"
end
create_table "private_users", :force => true do |t|
t.integer "platform_id"
t.string "login"
t.string "password"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "products", :force => true do |t|
t.string "name", :null => false
t.integer "platform_id", :null => false

View File

@ -0,0 +1,5 @@
require 'spec_helper'
describe PrivateUsersController do
end

View File

@ -0,0 +1,5 @@
require 'spec_helper'
describe PrivatesController do
end

View File

@ -0,0 +1,15 @@
require 'spec_helper'
# Specs in this file have access to a helper object that includes
# the PrivateUsersHelper. For example:
#
# describe PrivateUsersHelper do
# describe "string concat" do
# it "concats two strings with spaces" do
# helper.concat_strings("this","that").should == "this that"
# end
# end
# end
describe PrivateUsersHelper do
pending "add some examples to (or delete) #{__FILE__}"
end

View File

@ -0,0 +1,15 @@
require 'spec_helper'
# Specs in this file have access to a helper object that includes
# the PrivatesHelper. For example:
#
# describe PrivatesHelper do
# describe "string concat" do
# it "concats two strings with spaces" do
# helper.concat_strings("this","that").should == "this that"
# end
# end
# end
describe PrivatesHelper do
pending "add some examples to (or delete) #{__FILE__}"
end

View File

@ -0,0 +1,5 @@
require 'spec_helper'
describe PrivateUser do
pending "add some examples to (or delete) #{__FILE__}"
end