Merge pull request #318 from warpc/279-new_design_for_platforms

[Refs #279] new design for platforms(add control for members, fix bugs)
This commit is contained in:
Vladimir Sharshov 2012-03-20 09:48:57 -07:00
commit 047425a27f
17 changed files with 150 additions and 44 deletions

View File

@ -511,8 +511,10 @@ table.tablesorter.repo-projects th.th1 {
width: 250px;
}
table.tablesorter.repo-projects th.th3 {
table.tablesorter.repo-projects th.th3,
table.tablesorter th.buttons {
width: 60px;
text-align: center;
}
table.tablesorter.repo-projects td.td2,

View File

@ -1,7 +1,7 @@
# -*- encoding : utf-8 -*-
class PlatformsController < ApplicationController
before_filter :authenticate_user!, :except => :easy_urpmi
before_filter :find_platform, :only => [:clone, :edit, :destroy]
before_filter :find_platform, :only => [:clone, :edit, :destroy, :members]
before_filter :get_paths, :only => [:new, :create, :clone]
load_and_authorize_resource
@ -14,7 +14,7 @@ class PlatformsController < ApplicationController
end
def index
@platforms = @platforms.paginate(:page => params[:page], :per_page => 20)
@platforms = @platforms.accessible_by(current_ability, :related).paginate(:page => params[:page], :per_page => 20)
end
def easy_urpmi
@ -109,6 +109,43 @@ class PlatformsController < ApplicationController
def forbidden
end
def members
@members = @platform.members.order('name')
end
def remove_members
all_user_ids = params['user_remove'].inject([]) {|a, (k, v)| a << k if v.first == '1'; a}
all_user_ids.each do |uid|
Relation.by_target(@platform).where(:object_id => uid, :object_type => 'User').each{|r| r.destroy}
end
redirect_to members_platform_path(@platform)
end
def remove_member
u = User.find(params[:member_id])
Relation.by_object(u).by_target(@platform).each{|r| r.destroy}
redirect_to members_platform_path(@platform)
end
def add_member
if params[:member_id].present?
member = User.find(params[:member_id])
if @platform.relations.exists?(:object_id => member.id, :object_type => member.class.to_s) or @platform.owner == member
flash[:warning] = t('flash.platform.members.already_added', :name => member.uname)
else
rel = @platform.relations.build(:role => 'admin')
rel.object = member
if rel.save
flash[:notice] = t('flash.platform.members.successfully_added', :name => member.uname)
else
flash[:error] = t('flash.platform.members.error_in_adding', :name => member.uname)
end
end
end
redirect_to members_platform_url(@platform)
end
protected
def get_paths
if params[:user_id]

View File

@ -31,6 +31,7 @@ class Ability
cannot :approve, RegisterRequest, :approved => true
cannot :reject, RegisterRequest, :rejected => true
cannot [:owned, :related], BuildList
cannot [:owned, :related], Platform
end
if user.user?
@ -70,14 +71,12 @@ class Ability
can(:publish, BuildList) {|build_list| build_list.can_publish? && can?(:write, build_list.project)}
can(:cancel, BuildList) {|build_list| build_list.can_cancel? && can?(:write, build_list.project)}
can :read, Platform, :visibility => 'open'
can :read, Platform, :owner_type => 'User', :owner_id => user.id
can :read, Platform, :owner_type => 'Group', :owner_id => user.group_ids
can(:read, Platform, read_relations_for('platforms')) {|platform| local_reader? platform}
# can([:update, :build_all], Platform) {|platform| local_admin? platform}
can([:update], Platform) {|platform| local_admin? platform}
#can([:freeze, :unfreeze, :destroy], Platform) {|platform| owner? platform}
can(:destroy, Platform) {|platform| owner? platform}
can [:read, :members], Platform, :visibility => 'open'
can [:read, :owned, :related, :members], Platform, :owner_type => 'User', :owner_id => user.id
can [:read, :related, :members], Platform, :owner_type => 'Group', :owner_id => user.group_ids
can([:read, :related, :members], Platform, read_relations_for('platforms')) {|platform| local_reader? platform}
can([:update, :members], Platform) {|platform| local_admin? platform}
can([:destroy, :members, :add_member, :remove_member, :remove_members] , Platform) {|platform| owner? platform}
can :autocomplete_user_uname, Platform
can [:read, :projects_list], Repository, :platform => {:visibility => 'open'}

View File

@ -15,7 +15,7 @@
- @users.each do |user|
%tr#admin-table-members-row1
%td
%span#niceCheckbox1.niceCheck-main{:onclick => "changeCheck(this)", :style => "background-position: 0px 0px; "}
%span#niceCheckbox1.niceCheck-main{ :style => "background-position: 0px 0px; "}
= check_box_tag "user_remove[#{user.id}][]"
%td
.img

View File

@ -12,9 +12,9 @@
.rightlist= f.select :distrib_type, options_for_select(APP_CONFIG['distr_types'])
.both
.leftlist= f.label :parent, :class => :label
.rightlist= f.collection_select :parent_platform_id, Platform.all, :id, :description, :include_blank => true
.both
-#.leftlist= f.label :parent, :class => :label
.rightlist= f.collection_select :parent_platform_id, Platform.all, :id, :description, :include_blank => true
.both
- unless @platform.platform_type.in? ['personal']
.leftlist= f.label :released, :class => :label

View File

@ -4,17 +4,24 @@
- content_for :sidebar do
%aside
.admin-preferences
%ul
%li{:class => (act == :show && contr == :platforms) ? 'active' : ''}
= link_to t("layout.platforms.about"), platform_path(@platform)
%li{:class => (contr == :repositories) ? 'active' : ''}
= link_to t("layout.repositories.list_header"), platform_repositories_path(@platform)
- if can? :read, @platform.products.build
%li{:class => (contr == :products) ? 'active' : ''}
= link_to t("layout.products.list_header"), platform_products_path(@platform)
-#- if current_user.owner_of? @platform or current_user.admin?
%li{:class => (act == :index && contr == :private_users) ? 'active' : ''}
= link_to t("layout.platforms.private_users"), platform_private_users_path(@platform)
%nav
%ul
%li{:class => (act == :show && contr == :platforms) ? 'active' : ''}
= link_to t("layout.platforms.about"), platform_path(@platform)
%li{:class => (contr == :repositories) ? 'active' : ''}
= link_to t("layout.repositories.list_header"), platform_repositories_path(@platform)
- if can? :read, @platform.products.build
%li{:class => (contr == :products) ? 'active' : ''}
= link_to t("layout.products.list_header"), platform_products_path(@platform)
- if can? :update, @platform
%li{:class => (act == :edit && contr == :platforms) ? 'active' : nil}
= link_to t("platform_menu.settings"), edit_platform_path(@platform)
- if can? :members, @platform
%li{:class => (act == :members && contr == :platforms) ? 'active' : nil}
= link_to t("layout.platforms.members"), members_platform_path(@platform)
-#- if current_user.owner_of? @platform or current_user.admin?
%li{:class => (act == :index && contr == :private_users) ? 'active' : ''}
= link_to t("layout.platforms.private_users"), platform_private_users_path(@platform)
-#.block.notice
%h3= t("layout.groups.members")
.content

View File

@ -3,5 +3,3 @@
.left= @platform.name
%nav
%ul
- if can? :update, @platform
%li= link_to t("platform_menu.settings"), edit_platform_path(@platform), :class => (act == :edit && contr == :platforms) ? 'active' : nil

View File

@ -4,13 +4,13 @@
= form_for @platform, :url => platform_path(@platform), :html => { :class => :form } do |f|
= render :partial => "form", :locals => {:f => f}
.hr
.leftside
= t("layout.platforms.delete_warning")
.rightside
- if can? :destroy, @platform
= link_to t("layout.delete"), platform_path(@platform), :method => :delete, :confirm => t("layout.platforms.confirm_delete"), :class => 'button'
.both
- if can? :destroy, @platform
.hr
.leftside
= t("layout.platforms.delete_warning")
.rightside
= link_to t("layout.delete"), platform_path(@platform), :method => :delete, :confirm => t("layout.platforms.confirm_delete"), :class => 'button'
.both
-#.block
.secondary-navigation

View File

@ -0,0 +1,42 @@
= render :partial => 'submenu'
= render :partial => 'sidebar'
= form_tag remove_members_platform_path(@platform), :id => 'members_form', :method => :post do
%table.tablesorter{:cellpadding => "0", :cellspacing => "0"}
%thead
%tr
- if can? :remove_members, @platform
%th
\ 
%th
= t("layout.collaborators.members")
- if can? :remove_member, @platform
%th.buttons
= t("layout.remove")
%tbody
- @members.select{|u| u != @platform.owner}.each_with_index do |user, num|
%tr{:id => "admin-table-members-row#{num}", :class => cycle(:odd, :even)}
- if can? :remove_members, @platform
%td
%span.niceCheck-main{:id => "niceCheckbox#{num}", :style => "background-position: 0px 0px; "}
= check_box_tag "user_remove[#{user.id}][]"
%td
.img
= image_tag avatar_url(user)
.forimg= link_to "#{user.uname} (#{user.name})", user_path(user)
- if can? :remove_member, @platform
%td.buttons
= link_to remove_member_platform_path(@platform, :member_id => user.id), :method => :delete, :confirm => t("layout.confirm") do
%span.delete &nbsp;
- if can? :remove_memvers, @platforms
= submit_tag t("layout.delete"), :class => 'button'
.both
- if can? :add_member, @platform
.hr.top
= form_tag add_member_platform_path(@platform) do
.admin-search
= autocomplete_field_tag 'member_id', params[:member_id], autocomplete_user_uname_users_path, :id_element => '#member_id_field'
= hidden_field_tag 'member_id', nil, :id => 'member_id_field'
= submit_tag t("layout.add"), :class => 'button'
.both

View File

@ -1,7 +1,7 @@
= render :partial => 'submenu'
= render :partial => 'sidebar'
%h3.fix= t("layout.platforms.about")
%h3.fix= "#{t("layout.platforms.about")} #{@platform.name}"
%p= @platform.description

View File

@ -6,7 +6,7 @@
<% @projects.each do |project| %>
[
"<%=j link_to("#{project.owner.respond_to?(:uname) ? project.owner.uname : project.owner.name} / #{project.name}", project) %>",
"<%= truncate(project.description, :length => 60).gsub("\n", ' ') %>",
"<%= truncate(project.description || '', :length => 60).gsub("\n", ' ') %>",
"<%=j link_to t("layout.add"), url_for(:controller => :repositories, :action => :add_project, :project_id => project.id) %>"
]<%= project == @projects.last ? '' : ',' %>
<% end %>

View File

@ -13,7 +13,7 @@
j(link_to("#{project.owner.respond_to?(:uname) ? project.owner.uname : project.owner.name} / #{project.name}", project)) +
"</div>").html_safe
%>",
"<%= truncate(project.description, :length => 60).gsub("\n", ' ') %>",
"<%= truncate(project.description || '', :length => 60).gsub("\n", ' ') %>",
"<%=
if can? :remove_project, @repository
j(link_to('<span class="delete">&nbsp;</span>'.html_safe,

View File

@ -12,6 +12,8 @@ en:
by: by
remove: Remove
visibilities:
open: open
hidden: hidden

View File

@ -12,6 +12,8 @@ ru:
by: ''
remove: Убрать
visibilities:
open: открытая
hidden: скрытая

View File

@ -37,6 +37,10 @@ en:
clone: To clone
delete_warning: Attention! Deleted platform can not be restored!
sys_repos_header: Connecting info
target_platform: Target platform
target_architecture: Target architecture
members: Members
flash:
platform:
@ -51,6 +55,10 @@ en:
destroyed: Platform deleted
build_all_success: All project build in progress
clone_success: Cloned successfully
members:
already_added: "%{name} is already added to platform"
successfully_added: "%{name} successfully added as member"
error_in_adding: "Fail to add %{name} as member"
activerecord:
models:

View File

@ -35,10 +35,11 @@ ru:
private_users: Данные для доступа
confirm_clone: Клонировать?
clone: Клонировать
delete_warning: Внимание! Удаленная платформа удалению не подлежит.
delete_warning: Внимание! Удаленная платформа восстановлению не подлежит.
sys_repos_header: Данные для подключения
target_platform: Целевая платформа
target_architecture: Целевая архитектура
members: Участники
flash:
platform:
@ -53,6 +54,10 @@ ru:
destroyed: Платформа успешно удалена
build_all_success: Все проекты успешно отправлены на сборку
clone_success: Клонирование успешно
members:
already_added: "%{name} уже является участником платформы"
successfully_added: "Участник #{name} успешно добавлен к платформе"
error_in_adding: "Не удалось добавить участника %{name}"
activerecord:
models:

View File

@ -74,13 +74,17 @@ Rosa::Application.routes.draw do
resources :private_users, :except => [:show, :destroy, :update]
member do
get 'clone'
post 'make_clone'
post 'build_all'
get :clone
get :members
post :remove_members
delete :remove_member
post :add_member
post :make_clone
post :build_all
end
collection do
get 'easy_urpmi'
get :easy_urpmi
get :autocomplete_user_uname
end