Skip to content

Commit

Permalink
Merge branch 'master' into danilo-sandbox
Browse files Browse the repository at this point in the history
Conflicts:
	app/controllers/projects/repositories/auth_controller.rb
	app/views/projects/repositories/auth/new.html.erb
	test/functional/projects/repositories/auth_controller_test.rb
	test/integration/repository_authentication_test.rb
	test/test_helper.rb
	todo.list
  • Loading branch information
daniloisr committed May 5, 2013
2 parents 18f128f + 6472c3f commit d12f4b2
Show file tree
Hide file tree
Showing 32 changed files with 242 additions and 166 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,4 @@ config/phpmigration.yml
*.swp
Vagrantfile
\.vagrant
*tags
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ group :assets do
gem 'coffee-rails', '~> 3.2.1'
gem 'therubyracer'
gem 'uglifier', '>= 1.0.3'
gem 'font-awesome-sass-rails'
end

group :development do
Expand Down
7 changes: 7 additions & 0 deletions Guardfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# A sample Guardfile
# More info at https://github.com/guard/guard#readme

guard 'ctags-bundler', :src_path => ["app", "lib", "spec/support"] do
watch(/^(app|lib|spec\/support)\/.*\.rb$/)
watch('Gemfile.lock')
end
Binary file added app/assets/images/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed app/assets/images/rails.png
Binary file not shown.
58 changes: 58 additions & 0 deletions app/assets/stylesheets/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
*= require chosen
*= require_self
*= require layout
*= require _font-awesome
*= require_tree ./admin/
*/

Expand All @@ -30,3 +31,60 @@ table.nowrap td >div {
form#new-session a.pull-right {
margin-left: 1em;
}

.bottom-line {
border-bottom: 8px solid #005ca1;
padding-bottom: .3em;
margin-bottom: 1em;
}

div.logo {
margin: 0.3em 0 0.5em;
font-size: 40px;
font-family: 'Skranji', cursive;
position: relative;

img {
height: 75px;
}

a {
color: #005ca1;
&:hover {
text-decoration: none;
}
}

div#menu {
position: absolute;
right: 0;
top: 0;

ul {
display: block;
}
ul~ul {
margin-top: .1em;
}

li {
list-style: none;
display: block;
float: right;

a,i {
padding: .25em;
font-size: 25px;
color: #005ca1;

&:hover {
background: #005ca1;
color: white;
}
}
a {
padding: 0;
}
}
}
}
9 changes: 5 additions & 4 deletions app/controllers/projects/repositories/auth_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ def create
project = Project.find(params[:project_id])
repository = Repository.find(params[:repository_id])

if repository.auth(params[:login], params[:pass])
session[:repo_login] = params[:login]
session[:repo_pass] = params[:pass]
if repository.auth(params[:auth][:login], params[:auth][:pass])
session[:repo_login] = params[:auth][:login]
session[:repo_pass] = params[:auth][:pass]
redirect_to project_repository_url(project, repository)
else
render :new, :alert => 'dados errados'
flash.now['alert'] = t('projects.repositories.auth.create.auth_failed')
render :new
end
end

Expand Down
14 changes: 8 additions & 6 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
module ApplicationHelper
def admin_menu(label, link, icon = '')
raw content_tag(:li, link_to(icon + t(".#{label}"), link), class: current_page?(link) ? 'active' : '') if can?('view', 'admin')
def admin_menu(icon_name, title, link, args = {})
header_menu(icon_name, title, link, args) if can?('view', 'admin')
end

def icon(name, color = '')
color.size != 0 and color = 'icon-white'
name = %`icon-#{name}`
def header_menu(icon_name, title, link, args = {})
args.reverse_merge!(:'data-toggle' => 'tooltip', :title => title)
content_tag(:li, link_to(icon(icon_name), link, args))
end

content_tag :i, '', :class => %`#{name} #{color}`
def icon(name, color = 'icon-white')
content_tag(:i, '', :class => "icon-#{name} #{color}")
end
end
4 changes: 4 additions & 0 deletions app/views/layouts/_head.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<title>Cranelift</title>
<%= stylesheet_link_tag "application", :media => "all" %>
<%= csrf_meta_tags %>
<link href='http://fonts.googleapis.com/css?family=Skranji' rel='stylesheet' type='text/css'>
13 changes: 13 additions & 0 deletions app/views/layouts/_header.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<div class="row logo bottom-line">
<div class="span12">
<%= link_to root_path do %>
<%= image_tag 'logo.png' %>
Cranelift
<% end %>

<div id="menu">
<ul class="clearfix"><%= render '/layouts/menu_user' %></ul>
<ul><%= render '/layouts/menu_admin' %></ul>
</div>
</div>
</div>
30 changes: 0 additions & 30 deletions app/views/layouts/_menu.html.erb

This file was deleted.

5 changes: 5 additions & 0 deletions app/views/layouts/_menu_admin.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<%= admin_menu('cog', t('.settings'), admin_settings_path) %>
<%= admin_menu('list-alt', t('.roles'), admin_roles_path) %>
<%= admin_menu('book', t('.logs'), admin_logs_path) %>
<%= admin_menu('filter', t('.ips'), admin_ips_path) %>
<%= admin_menu('user', t('.users'), admin_users_path) %>
11 changes: 11 additions & 0 deletions app/views/layouts/_menu_user.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<% if current_user %>
<%= header_menu('off', t('.logout'), logout_path, :method => :delete) %>
<%= header_menu('edit', t('.editaccount'), editaccount_path) %>
<% else %>
<% if Setting.find_or_default('allow_register').value == 'true' %>
<%= header_menu('pencil', t('.register'), new_user_path) %>
<% end %>
<%= header_menu('refresh', t('.login'), login_path) %>
<% end %>

<%= header_menu('folder-open', t('.projects'), projects_path) %>
23 changes: 7 additions & 16 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
@@ -1,23 +1,14 @@
<!DOCTYPE html>
<html lang="pt-BR">
<head>
<title>Cranelift</title>
<%= stylesheet_link_tag "application", :media => "all" %>
<%= csrf_meta_tags %>
<%= render 'layouts/head' %>
</head>
<body>
<div class="container" style="margin-top: 1em">
<div class="row">
<div class="span3">
<div class="well sidebar-nav" style="padding: 8px 0;">

<ul class="nav nav-list">
<%= render 'layouts/menu' %>
</ul>
</div><!--/.well -->
</div><!--/span-->
<div class="container">
<%= render 'layouts/header' %>

<div class="span9 content">
<div class="row">
<div class="span12 content">
<div class="messages">
<% flash.each do |name, msg| %>
<div class="alert alert-<%= name == :notice ? "success" : "error" %>">
Expand All @@ -28,9 +19,9 @@
</div>

<%= yield %>
</div><!--/span-->
</div>

</div><!--/row-->
</div>
</div>

<%= javascript_include_tag "application" %>
Expand Down
13 changes: 6 additions & 7 deletions app/views/layouts/menuless.html.erb
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
<!DOCTYPE html>
<html lang="pt-BR">
<head>
<title>Cranelift</title>
<%= stylesheet_link_tag "application", :media => "all" %>
<%= csrf_meta_tags %>
<%= render 'layouts/head' %>
</head>
<body>
<div class="container" style="margin-top: 1em">
<div class="row">
<div class="container">
<%= render 'layouts/header' %>

<div class="row">
<div class="span8 offset2 content">
<div class="messages">
<% flash.each do |name, msg| %>
Expand All @@ -20,9 +19,9 @@
</div>

<%= yield %>
</div><!--/span-->
</div>

</div><!--/row-->
</div>
</div>

<%= javascript_include_tag "application" %>
Expand Down
14 changes: 10 additions & 4 deletions app/views/projects/repositories/auth/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
<%= simple_form_for :auth, url: [@project, @repository, :auth], :method => :post, :html => { :class => 'form-horizontal' } do %>
login:<input type='text' name='login'><br>
password:<input type='text' name='pass'><br>
<input type="submit" value="submit" id="submit">
<h1><%= t('.auth_required') %></h1>

<%= simple_form_for :auth, url: [@project, @repository, :auth], method: :post, html: { class: 'form-horizontal' } do |f| %>
<% render 'shared/form_errors', :f => f %>
<%= f.input :login, label: t('.login') %>
<%= f.input :pass, as: :password, label: t('.pass') %>

<div class="form-actions">
<%= f.button :submit, :class => 'btn-primary', value: t('.submit') %>
</div>
<% end %>
14 changes: 8 additions & 6 deletions config/locales/views/defaults/pt-BR.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,19 @@ pt-BR:
destroy: Remover
new_obj: "Novo %{obj}"
layouts:
menu:
menu_admin:
settings: Configurações
roles: Papeis/Permissões
logs: Logs
ips: IPs
users: Usuários
menu_user:
login: Login
logout: Sair
home: Home Page
register: Registrar
projects: Projetos
admin: Administração
users: Usuários
ips: IPs
logs: Logs
roles: Papeis/Permissões
settings: Configurações
editaccount: Editar seus Dados
views:
pagination:
Expand Down
11 changes: 11 additions & 0 deletions config/locales/views/projects/repositories/auth/pt-BR.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
pt-BR:
projects:
repositories:
auth:
create:
auth_failed: A autenticação falhou
new:
auth_required: Este repositório exige autenticação
login: Login
pass: Senha
submit: Autenticar
Binary file added doc/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion lib/migrate/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def config
def mysql
if @@mysql.nil?
c = self::config
@@mysql = Mysql2::Client.new(
@@mysql = ::Mysql2::Client.new(
:host => c.host,
:username => c.user,
:password => c.pass,
Expand Down
2 changes: 1 addition & 1 deletion lib/migrate/ips_migrate.rb → lib/migrate/ips.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Migrate
class IpsMigrate < Migrate::Base
class Ips < Migrate::Base
def migrate
puts "Migrando ips..."

Expand Down
58 changes: 58 additions & 0 deletions lib/migrate/projects.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
module Migrate
class FakeRepository < ::ActiveRecord::Base
self.table_name = 'repositories'
end

class Projects < Migrate::Base
def migrate
puts "Migrando projetos..."

phpsvn_projects.each do |reg|
copy_repository_from_php(reg['alias'])

pj = ::Project.create(name: reg['alias'])
debug_obj(pj)

repo = FakeRepository.create(name: reg['alias'],
url: reg['nome'],
enable_autoupdate: reg['autoupdate'],
login: reg['co_login'],
password: reg['co_password'],
project_id: pj.id)

add_users_to_project(pj, reg['id'])
end
end

def phpsvn_projects
mysql.query('select * from projetos')
end

def add_users_to_project(cr_project, old_project_id)
regs = mysql.query("select * from user_projetos
where id_projetos = #{old_project_id}")

users_ids = regs.map{ |reg| ::Migrate::UserMap.new_id(reg['id_user']) }
debugger if users_ids.include?(0)
cr_project.users = ::User.find(users_ids) if users_ids.any?
end

def copy_repository_from_php(repository)
origin = File.join(config.php_projects_path, repository)
destiny = Rails.root.join('repositories', repository)

FileUtils.mkdir destiny
FileUtils.cp_r Dir[origin], File.join(destiny, ''), :verbose => true
end

def create_fake_folders
puts "Criando pastas fakes para desenvolvimento..."

regs = mysql.query('select * from projetos')
regs.each do |r|
name = r['alias']
FileUtils.mkpath File.join(config.php_projects_path, name, name)
end
end
end
end
Loading

0 comments on commit d12f4b2

Please sign in to comment.