Added collaborators management.
This commit is contained in:
parent
c7e267ba00
commit
b9ee6e365b
|
@ -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
|
|
@ -0,0 +1,2 @@
|
|||
module CollaboratorsHelper
|
||||
end
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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?
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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: Статистика закачек пакетов
|
||||
|
@ -193,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: Список
|
||||
|
@ -273,6 +289,10 @@ ru:
|
|||
project_version_not_found: версия не найден
|
||||
|
||||
flash:
|
||||
collaborators:
|
||||
successfuly_changed: Список коллабораторов успешно изменен
|
||||
error_in_changing: Ошибка изменения списка коллабораторов
|
||||
|
||||
auto_build_list:
|
||||
success: Сборка проекта автоматизорована!
|
||||
failed: Не удалось автоматизировать сборку!
|
||||
|
|
|
@ -80,7 +80,7 @@ Rosa::Application.routes.draw do
|
|||
end
|
||||
end
|
||||
|
||||
resources :collaborators do
|
||||
resources :collaborators, :only => [:index, :edit, :update] do
|
||||
collection do
|
||||
get :add
|
||||
post :add
|
||||
|
@ -88,6 +88,9 @@ Rosa::Application.routes.draw do
|
|||
get :edit
|
||||
post :update
|
||||
end
|
||||
member do
|
||||
post :update
|
||||
end
|
||||
end
|
||||
# resources :groups, :controller => 'project_groups' do
|
||||
# end
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe CollaboratorsController do
|
||||
|
||||
end
|
|
@ -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
|
Loading…
Reference in New Issue