[refs #195] Add owner choose on project create
This commit is contained in:
parent
3c5cdfd5e4
commit
72fec3b314
|
@ -42,8 +42,8 @@ class ProjectsController < ApplicationController
|
|||
|
||||
def create
|
||||
@project = Project.new params[:project]
|
||||
@project.owner = get_owner
|
||||
# puts @project.owner.inspect
|
||||
#@project.owner = get_owner
|
||||
@project.owner = choose_owner
|
||||
|
||||
if @project.save
|
||||
flash[:notice] = t('flash.project.saved')
|
||||
|
@ -116,4 +116,12 @@ class ProjectsController < ApplicationController
|
|||
def find_project
|
||||
@project = Project.find params[:id]
|
||||
end
|
||||
|
||||
def choose_owner
|
||||
if params[:who_owns] == 'group'
|
||||
Group.find(params[:owner_id])
|
||||
else
|
||||
current_user
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -17,6 +17,9 @@ class Group < ActiveRecord::Base
|
|||
validates :uname, :presence => true, :uniqueness => {:case_sensitive => false}, :format => { :with => /^[a-z0-9_]+$/ }
|
||||
validate { errors.add(:uname, :taken) if User.where('uname LIKE ?', uname).present? }
|
||||
|
||||
scope :by_owner, lambda { |owner| where(:owner_id => owner.id) }
|
||||
scope :by_admin, lambda { |admin| joins(:relations).where(:'relations.role' => 'admin', :'relations.target_id' => admin.id, :'relations.target_type' => 'User') }
|
||||
|
||||
attr_readonly :uname, :own_projects_count
|
||||
|
||||
delegate :ssh_key, :email, :to => :owner
|
||||
|
@ -26,6 +29,10 @@ class Group < ActiveRecord::Base
|
|||
include Modules::Models::PersonalRepository
|
||||
# include Modules::Models::Owner
|
||||
|
||||
def self.can_own_project(user)
|
||||
(by_owner(user) | by_admin(user)).collect { |el| [el.name, el.id] }
|
||||
end
|
||||
|
||||
protected
|
||||
def add_owner_to_members
|
||||
Relation.create_with_role(self.owner, self, 'admin')
|
||||
|
|
|
@ -10,6 +10,16 @@
|
|||
.rightlist
|
||||
= f.text_area :description, :class => 'text_field', :cols => 80
|
||||
.both
|
||||
- if ['new', 'create'].include? controller.action_name
|
||||
.leftlist
|
||||
= f.label :owner_id, t("activerecord.attributes.project.owner"), :class => :label
|
||||
.rightlist
|
||||
= label_tag t("activerecord.attributes.project.who_owns.me")
|
||||
= radio_button_tag :who_owns, 'me'
|
||||
= label_tag t("activerecord.attributes.project.who_owns.group")
|
||||
= radio_button_tag :who_owns, 'group'
|
||||
= select_tag :owner_id, options_for_select( Group.can_own_project(current_user) )
|
||||
.both
|
||||
-#- if [:new, :create].include? act
|
||||
-# .leftlist
|
||||
-# = f.label :category_id, t("activerecord.attributes.project.category_id"), :class => :label
|
||||
|
|
|
@ -834,6 +834,9 @@ en:
|
|||
has_issues: Tracker on
|
||||
has_wiki: Wiki on
|
||||
srpm: Import code from src.rpm
|
||||
who_owns:
|
||||
me: I
|
||||
group: Group
|
||||
|
||||
rpm:
|
||||
name: Name
|
||||
|
|
|
@ -696,6 +696,9 @@ ru:
|
|||
has_issues: Включить трэкер
|
||||
has_wiki: Включить Wiki
|
||||
srpm: Импортировать код из src.rpm
|
||||
who_owns:
|
||||
me: Я
|
||||
group: Группа
|
||||
|
||||
rpm:
|
||||
name: Название
|
||||
|
|
Loading…
Reference in New Issue