Merge branch 'master' of github.com:warpc/rosa-build

This commit is contained in:
Vladimir Sharshov 2011-10-31 03:27:11 +04:00
commit 4b0f23cfa3
18 changed files with 343 additions and 115 deletions

View File

@ -0,0 +1,124 @@
class CollaboratorsController < ApplicationController
before_filter :authenticate_user!
before_filter :check_global_access
before_filter :find_project
before_filter :find_roles
before_filter :find_default_roles, :only => [:create, :update, :edit]
before_filter :find_users
before_filter :find_groups
def index
redirect_to edit_project_collaborators_path(@project)
end
def show
end
def new
end
def edit
if params[:id]
@user = User.find params[:id]
render :edit_rights and return
end
end
def create
end
def update
unless params[:id]
if params[:user]
users_for_removing = @project.collaborators.select do |u|
!params[:user].keys.map{|k| k.to_i}.include? u.id and @project.owner != u
end
users_for_creating = params[:user].keys.map{|p| p.to_i} - @project.collaborators.map(&:id)
puts users_for_removing.inspect
puts users_for_creating.inspect
users_for_removing.each do |u|
Relation.by_object(u).by_target(@project).each {|r| r.destroy}
end
# @project.collaborators.delete_if{|c| users_for_removing.include? c}
users_for_creating.each do |user|
@project.add_roles_to User.find(user), @def_user_roles
end
end
# if params[:group]
# groups_for_removing = @project.groups.select do |g|
# !params[:group].keys.map{|k| k.to_i}.include? g.id and @project.owner != g
# end
# groups_for_creating = params[:group].keys.map{|p| p.to_i} - @project.groups.map(&:id)
#
# puts groups_for_removing.inspect
# puts groups_for_creating.inspect
#
# @project.groups.delete_if{|g| groups_for_removing.include? g}
# groups_for_creating.each do |group|
# @project.add_roles_to Group.find(group), @def_group_roles
# end
# end
if @project.save
flash[:notice] = t("flash.collaborators.successfully_changed")
else
flash[:error] = t("flash.collaborators.error_in_changing")
end
redirect_to project_path(@project)
else
@user = User.find params[:id]
if params[:role]
roles_for_removing = @user.roles_to(@project).select do |r|
!params[:role].keys.map{|k| k.to_i}.include? r.id
end
roles_for_creating = params[:role].keys.map{|r| r.to_i} - @user.roles_to(@project).map(&:id)
puts roles_for_removing.inspect
puts roles_for_creating.inspect
roles_for_removing.each do |r|
Relation.by_object(@user).by_target(@project).each do |rel|
RoleLine.where(:role_id => r.id).where(:relation_id => rel.id).each {|rl| rl.destroy}
end
end
@project.add_roles_to @user, Role.find(roles_for_creating)
end
# if @user.save!
flash[:notice] = t("flash.collaborators.successfully_changed")
# else
# flash[:error] = t("flash.collaborators.error_in_changing")
# end
redirect_to edit_project_collaborators_path(@project)
end
end
def destroy
end
protected
def find_project
@project = Project.find params[:project_id]
end
def find_roles
@user_roles = Role.by_acter(User).by_target(Project) + Role.by_acter(:all).by_target(Project)
@group_roles = Role.by_acter(Group).by_target(Project) + Role.by_acter(:all).by_target(Project)
end
def find_default_roles
@def_user_roles = Role.by_acter(User).by_target(Project).default + Role.by_acter(:all).by_target(Project).default
@def_group_roles = Role.by_acter(Group).by_target(Project).default + Role.by_acter(:all).by_target(Project).default
end
def find_users
@users = User.all
end
def find_groups
@groups = Group.all
end
end

View File

@ -63,7 +63,7 @@ class ProjectsController < ApplicationController
:pl_id => auto_build_list.pl_id,
:bpl_id => auto_build_list.bpl_id,
:arch_id => auto_build_list.arch_id,
:project_version => project.project_versions.last.try(:name),
:project_version => project.collected_project_versions.last.try(:first),
:build_requires => true,
:update_type => 'bugfix') if auto_build_list
@ -74,7 +74,7 @@ class ProjectsController < ApplicationController
@arches = Arch.recent
@bpls = Platform.main
@pls = @project.repositories.collect { |rep| ["#{rep.platform.name}/#{rep.unixname}", rep.platform.id] }
@project_versions = @project.project_versions.collect { |tag| [tag.name, tag.name.gsub(/^\w+\./, "")] }
@project_versions = @project.collected_project_versions
end
def process_build
@ -90,7 +90,7 @@ class ProjectsController < ApplicationController
update_type = params[:build][:update_type]
build_requires = params[:build][:build_requires]
@project_versions = @project.project_versions.collect { |tag| [tag.name, tag.name.gsub(/^\w+\./, "")] }.select { |pv| pv[0] =~ /^v\./ }
@project_versions = @project.collected_project_versions
if !check_arches || !check_project_versions
@arches = Arch.recent

View File

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

View File

@ -14,13 +14,13 @@ module PersonalRepository
pl.platform_type = 'personal'
pl.distrib_type = 'mandriva2011'
pl.visibility = 'open'
pl.save
pl.save!
rep = pl.repositories.build
rep.owner = pl.owner
rep.name = 'main'
rep.unixname = 'main'
rep.save
rep.save!
end
def personal_platform

View File

@ -19,9 +19,9 @@ class Platform < ActiveRecord::Base
validates :unixname, :uniqueness => true, :presence => true, :format => { :with => /^[a-zA-Z0-9_]+$/ }, :allow_nil => false, :allow_blank => false
validates :distrib_type, :presence => true, :allow_nil => :false, :allow_blank => false, :inclusion => {:in => APP_CONFIG['distr_types']}
# after_create :make_owner_rel
after_create :make_owner_rel
# before_save :create_directory
before_save :add_owner_rel
before_save :check_owner_rel
# after_destroy :remove_directory
before_create :xml_rpc_create
before_destroy :xml_rpc_destroy
@ -175,12 +175,14 @@ class Platform < ActiveRecord::Base
FileUtils.rm_rf symlink_downloads_path
end
def add_owner_rel
if new_record? and owner
add_owner owner
elsif owner_id_changed?
remove_owner owner_type_was.classify.find(owner_id_was)
add_owner owner
def make_owner_rel
add_owner owner
end
def check_owner_rel
if !new_record? and owner_id_changed?
remove_owner owner_type_was.classify.find(owner_id_was) if owner_type_was
add_owner owner if owner
end
end

View File

@ -39,10 +39,13 @@ class Project < ActiveRecord::Base
after_rollback lambda { destroy_git_repo rescue true if new_record? }
def project_versions
#tags.collect { |tag| [tag.name, tag.name.gsub(/^\w+\./, "")] }.select { |pv| pv[0] =~ /^v\./ }
tags.select { |tag| tag.name =~ /^v\./ }
end
def collected_project_versions
project_versions.collect { |tag| new_tag = tag.name.gsub(/^\w+\./, ""); [new_tag, new_tag] }
end
def tags
self.git_repository.tags
end

View File

@ -34,7 +34,7 @@ class User < ActiveRecord::Base
attr_readonly :uname
attr_accessor :login
before_create :add_default_role
after_create :add_default_role
before_update {
if ssh_key_was.blank? and ssh_key.present?

View File

@ -2,6 +2,7 @@
.content
.inner
%h2= t('layout.auto_build_lists.header')
%h3= t('layout.auto_build_lists.message')
.inner
= render :partial => "auto_build_lists/not_automated"

View File

@ -3,6 +3,7 @@
%ul.wat-cf
%li.first= link_to t("layout.personal_repositories.show"), personal_repository_path(@repository)
%li.active= link_to t("layout.personal_repositories.settings"), settings_personal_repository_path(@repository)
%li= link_to t("layout.personal_repositories.private_users"), platform_private_users_path(@repository.platform) if @repository.platform.hidden?
.content
%h2.title= t("layout.personal_repositories.settings_header")
.inner

View File

@ -3,6 +3,7 @@
%ul.wat-cf
%li.first.active= link_to t("layout.personal_repositories.show"), personal_repository_path(@repository)
%li= link_to t("layout.personal_repositories.settings"), settings_personal_repository_path(@repository)
%li= link_to t("layout.personal_repositories.private_users"), platform_private_users_path(@repository.platform) if @repository.platform.hidden?
.content
.inner
%p

View File

@ -1,3 +1,34 @@
.block.notice
%h3= t("layout.projects.members")
.content
%p
%b
= "#{t("layout.projects.collaborators")}:"
%ul
- @project.collaborators.each do |user|
%li
- if current_user.can_perform? 'users', 'show'
= link_to user.name, user_path(user)
- else
= user.name
- if (@project.owner == user)
= '(' + t("layout.owner") + ')'
%br
- if current_user.can_perform? 'collaborators', 'edit'
= link_to t("layout.projects.edit_collaborators"), edit_project_collaborators_path(@project)
%p
%b
= "#{t("layout.projects.groups")}:"
%ul
- @project.groups.each do |group|
%li
= link_to group.name, group_path(group)
- if (@project.owner == group)
= '(' + t("layout.owner") + ')'
%br
= link_to t("layout.projects.add_groups"), '#' #add_collaborators_project_path(@project)
/ .block.notice
/ %h3= t("layout.platforms.current_platform_header")
/ .content

View File

@ -3,6 +3,7 @@ ru:
previous_label: Предыдущая
next_label: Следующая
page_gap: ...
layout:
global_header: Сборочная платформа ROSA
logged_in_as: Вы вошли как
@ -27,6 +28,7 @@ ru:
add: Добавить
upload: Загрузить
not_access: Нет доступа!
owner: Владелец
downloads:
title: Статистика закачек пакетов
@ -146,6 +148,7 @@ ru:
change_visibility_from_open: Сменить статус на "Приватный"
settings: Настройки
show: Мой репозиторий
private_users: Пользователи приватного репозитория
products:
list: Список
@ -192,6 +195,20 @@ ru:
current_build_lists: Текущие сборки
build_button: Начать сборку
add_collaborators: Добавить коллабораторов
members: Участники
collaborators: Коллабораторы
groups: Группы
edit_collaborators: Изменить список участников
collaborators:
back_to_proj: Вернуться к проекту
edit: Редактировать список
add: Добавить/Удалить
list: Список
edit_roles: Редактировать роли
roles_header: Роли для
add_role: Добавить/Удалить роль
groups:
list: Список
@ -272,6 +289,10 @@ ru:
project_version_not_found: версия не найден
flash:
collaborators:
successfuly_changed: Список коллабораторов успешно изменен
error_in_changing: Ошибка изменения списка коллабораторов
auto_build_list:
success: Сборка проекта автоматизорована!
failed: Не удалось автоматизировать сборку!

View File

@ -1,5 +1,76 @@
---
:Roles:
- name: !binary |
0JDQtNC80LjQvdC40YHRgtGA0LDRgtC+0YAg0L/Qu9Cw0YLRhNC+0YDQvNGL
use_default: false
use_default_for_owner: false
rights:
groups:
- index
- destroy
id: 2
to: ""
can_see: !map:ActiveSupport::HashWithIndifferentAccess
Project:
- open
"on": Platform
- name: !binary |
0JDQtNC80LjQvdC40YHRgtGA0LDRgtC+0YAg0YDQtdC/0L7Qt9C40YLQvtGA
0LjRjw==
use_default: false
use_default_for_owner: false
rights: {}
id: 3
to: ""
can_see:
"on": Repository
- name: !binary |
0JDQtNC80LjQvdC40YHRgtGA0LDRgtC+0YAg0LPRgNGD0L/Qv9GL
use_default: false
use_default_for_owner: true
rights: {}
id: 5
to: User
can_see:
"on": Group
- name: !binary |
0JzQsNC50L3RgtC10LnQvdC10YAg0L/RgNC+0LXQutGC0LA=
use_default: false
use_default_for_owner: false
rights: {}
id: 7
to: ""
can_see:
"on": Project
- name: !binary |
0J/QvtC70YzQt9C+0LLQsNGC0LXQu9GMINC/0LvQsNGC0YTQvtGA0LzRiw==
use_default: false
use_default_for_owner: false
rights: {}
id: 8
to: ""
can_see:
"on": Platform
- name: !binary |
0KPRh9Cw0YHRgtC90LjQuiDQs9GA0YPQv9C/0Ys=
use_default: false
use_default_for_owner: false
rights: {}
id: 9
to: User
can_see:
"on": Group
- name: !binary |
0JDQtNC80LjQvdC40YHRgtGA0LDRgtC+0YAg0YHQuNGB0YLQtdC80Ys=
@ -8,7 +79,11 @@
rights:
event_logs:
- index
auto_build_lists:
- index
- create
groups:
- update
- index
- create
- show
@ -39,6 +114,11 @@
- new
- unfreeze
projects:
- index
- auto_build
- edit
- update
- add_collaborators
- process_build
- create
- show
@ -107,12 +187,15 @@
- new
- load_from_dump
- get_dump
personal_repositories:
- change_visibility
- settings
- show
- add_project
- remove_project
id: 1
to: ""
can_see: !map:ActiveSupport::HashWithIndifferentAccess
Repository:
- open
- hidden
Project:
- open
- hidden
@ -120,107 +203,23 @@
- open
- hidden
"on": ""
- name: !binary |
0JDQtNC80LjQvdC40YHRgtGA0LDRgtC+0YAg0L/Qu9Cw0YLRhNC+0YDQvNGL
use_default: false
use_default_for_owner: false
rights:
groups:
- index
- destroy
id: 2
to: ""
can_see: !map:ActiveSupport::HashWithIndifferentAccess
Project:
- open
"on": Platform
- name: !binary |
0JDQtNC80LjQvdC40YHRgtGA0LDRgtC+0YAg0YDQtdC/0L7Qt9C40YLQvtGA
0LjRjw==
use_default: false
use_default_for_owner: false
rights: {}
id: 3
to: ""
can_see:
"on": Repository
- name: !binary |
0JDQtNC80LjQvdC40YHRgtGA0LDRgtC+0YAg0L/RgNC+0LXQutGC0LA=
use_default: false
use_default_for_owner: false
rights: {}
id: 4
to: ""
can_see:
"on": Project
- name: !binary |
0JDQtNC80LjQvdC40YHRgtGA0LDRgtC+0YAg0LPRgNGD0L/Qv9GL
use_default: false
use_default_for_owner: true
rights: {}
id: 5
id: 4
to: User
can_see:
"on": Group
- name: !binary |
0JDQtNC80LjQvdC40YHRgtGA0LDRgtC+0YAg0L/RgNC+0LTRg9C60YLQsA==
use_default: false
use_default_for_owner: false
rights: {}
id: 6
to: ''
can_see:
"on": ''
- name: !binary |
0JzQsNC50L3RgtC10LnQvdC10YAg0L/RgNC+0LXQutGC0LA=
use_default: false
use_default_for_owner: false
rights: {}
id: 7
to: ""
can_see:
"on": Project
- name: !binary |
0J/QvtC70YzQt9C+0LLQsNGC0LXQu9GMINC/0LvQsNGC0YTQvtGA0LzRiw==
use_default: false
use_default_for_owner: false
rights: {}
id: 8
to: ""
can_see:
"on": Platform
- name: !binary |
0KPRh9Cw0YHRgtC90LjQuiDQs9GA0YPQv9C/0Ys=
use_default: false
use_default_for_owner: false
rights: {}
id: 9
to: User
can_see:
"on": Group
- name: !binary |
0J/QvtC70YzQt9C+0LLQsNGC0LXQu9GMINGB0LjRgdGC0LXQvNGL
use_default: true
use_default_for_owner: false
rights:
event_logs:
- index
groups:
- index
personal_repositories:
@ -243,13 +242,20 @@
- index
products:
- show
categories:
- index
users:
- index
roles:
- index
personal_repositories:
- show
id: 10
to: User
can_see:
"on": ""
- name: !binary |
0JDQtNC80LjQvdC40YHRgtGA0LDRgtC+0YAg0L/RgNC+0LTRg9C60YLQsA==
use_default: false
use_default_for_owner: false
rights: {}
id: 6
to: ""
can_see:
"on": Project

View File

@ -80,12 +80,24 @@ Rosa::Application.routes.draw do
end
end
resources :collaborators, :only => [:index, :edit, :update] do
collection do
get :add
post :add
get :edit
post :update
end
member do
post :update
end
end
# resources :groups, :controller => 'project_groups' do
# end
member do
get :build
post :process_build
get :add_collaborators
post :add_collaborators
end
collection do
get :auto_build
@ -107,6 +119,8 @@ Rosa::Application.routes.draw do
resources :repositories, :only => [:new, :create]
end
match '/catalogs', :to => 'categories#platforms'
match 'build_lists/status_build', :to => "build_lists#status_build"
match 'build_lists/post_build', :to => "build_lists#post_build"
match 'build_lists/pre_build', :to => "build_lists#pre_build"

View File

@ -218,6 +218,7 @@ ActiveRecord::Schema.define(:version => 20111029150934) do
t.string "object_type"
t.integer "target_id"
t.string "target_type"
t.integer "role_id"
t.datetime "created_at"
t.datetime "updated_at"
end
@ -278,8 +279,9 @@ ActiveRecord::Schema.define(:version => 20111029150934) do
t.datetime "remember_created_at"
t.datetime "created_at"
t.datetime "updated_at"
t.text "ssh_key"
t.string "uname"
t.text "ssh_key"
t.integer "role_id"
t.integer "global_role_id"
end

View File

@ -71,7 +71,7 @@ class ActiveRecord::Base
else
r = possible.inject([]) do |arr, mod|
rels = Relation.by_object(mod).by_target(object)
arr.concat rel.map{|rel| rel.roles} if rels.size > 0
arr.concat rels.map{|rel| rel.roles} if rels.size > 0
arr << mod.global_role
arr
end

View File

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

View File

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