Commit e940fbc7 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Add UsersGroup relation to be respected by abilities and Project#team

parent fa877b63
...@@ -64,11 +64,11 @@ class GroupsController < ApplicationController ...@@ -64,11 +64,11 @@ class GroupsController < ApplicationController
def people def people
@project = group.projects.find(params[:project_id]) if params[:project_id] @project = group.projects.find(params[:project_id]) if params[:project_id]
@users_groups = group.users_groups
if @project if @project
@members = @project.users_projects
@team_member = @project.users_projects.new @team_member = @project.users_projects.new
else else
@members = group.users_groups
@team_member = UsersGroup.new @team_member = UsersGroup.new
end end
end end
......
...@@ -50,6 +50,10 @@ class Ability ...@@ -50,6 +50,10 @@ class Ability
rules << project_admin_rules rules << project_admin_rules
end end
if project.group && project.group.owners.include?(user)
rules << project_admin_rules
end
rules.flatten rules.flatten
end end
......
...@@ -47,23 +47,23 @@ class ProjectTeam ...@@ -47,23 +47,23 @@ class ProjectTeam
end end
def members def members
project.users_projects fetch_members
end end
def guests def guests
members.guests.map(&:user) @guests ||= fetch_members(:guests)
end end
def reporters def reporters
members.reporters.map(&:user) @reporters ||= fetch_members(:reporters)
end end
def developers def developers
members.developers.map(&:user) @developers ||= fetch_members(:developers)
end end
def masters def masters
members.masters.map(&:user) @masters ||= fetch_members(:masters)
end end
def import(source_project) def import(source_project)
...@@ -96,4 +96,18 @@ class ProjectTeam ...@@ -96,4 +96,18 @@ class ProjectTeam
rescue rescue
false false
end end
private
def fetch_members(level = nil)
project_members = project.users_projects
group_members = project.group.users_groups
if level
project_members = project_members.send(level)
group_members = group_members.send(level)
end
(project_members + group_members).map(&:user).uniq
end
end end
...@@ -35,7 +35,7 @@ class UsersGroup < ActiveRecord::Base ...@@ -35,7 +35,7 @@ class UsersGroup < ActiveRecord::Base
delegate :name, :username, :email, to: :user, prefix: true delegate :name, :username, :email, to: :user, prefix: true
def human_group_access def human_access
UsersGroup.group_access_roles.index(self.group_access) UsersGroup.group_access_roles.index(self.group_access)
end end
end end
...@@ -129,9 +129,7 @@ class UsersProject < ActiveRecord::Base ...@@ -129,9 +129,7 @@ class UsersProject < ActiveRecord::Base
Project.access_options.key(self.project_access) Project.access_options.key(self.project_access)
end end
def repo_access_human alias_method :human_access, :project_access_human
self.class.access_roles.invert[self.project_access]
end
def skip_git? def skip_git?
!!@skip_git !!@skip_git
......
...@@ -43,7 +43,7 @@ class SystemHooksService ...@@ -43,7 +43,7 @@ class SystemHooksService
project_id: model.project_id, project_id: model.project_id,
user_name: model.user.name, user_name: model.user.name,
user_email: model.user.email, user_email: model.user.email,
project_access: model.repo_access_human project_access: model.project_access_human
}) })
end end
end end
......
= form_for @team_member, as: :team_member, url: team_members_group_path(@group) do |f| = form_for @team_member, as: :team_member, url: team_members_group_path(@group) do |f|
%fieldset %fieldset
%legend= "New Team member(s) for projects in #{@group.name}" %legend= "New Group member(s) for #{@group.name}"
%h6 1. Choose people you want in the team %h6 1. Choose people you want in the group
.clearfix .clearfix
= f.label :user_ids, "People" = f.label :user_ids, "People"
.input= users_select_tag(:user_ids, multiple: true) .input= users_select_tag(:user_ids, multiple: true)
......
= form_for @team_member, as: :team_member, url: project_team_members_path(@project, @team_member) do |f| = form_for @team_member, as: :team_member, url: project_team_members_path(@project, @team_member) do |f|
%fieldset %fieldset
%legend= "New Team member(s) for #{@project.name}" %legend= "New Project member(s) for #{@project.name}"
%h6 1. Choose people you want in the team %h6 1. Choose people you want in the project
.clearfix .clearfix
= f.label :user_ids, "People" = f.label :user_ids, "People"
.input= users_select_tag(:user_ids, multiple: true) .input= users_select_tag(:user_ids, multiple: true)
...@@ -14,5 +14,5 @@ ...@@ -14,5 +14,5 @@
.form-actions .form-actions
= hidden_field_tag :redirect_to, people_group_path(@group, project_id: @project.id) = hidden_field_tag :redirect_to, people_group_path(@group, project_id: @project.id)
= f.submit 'Add', class: "btn btn-save" = f.submit 'Add users into project', class: "btn btn-create"
%fieldset
%legend Group members:
%ul.nav.nav-pills.nav-stacked
%li{class: ("active" if params[:project_id].blank?)}
= link_to people_group_path(@group) do
#{@group.name} Group
%small.pull-right= @group.users.count
= form_tag people_group_path(@group), method: 'get' do = form_tag people_group_path(@group), method: 'get' do
%fieldset %fieldset
%legend Projects: %legend Project members:
%ul.nav.nav-pills.nav-stacked %ul.nav.nav-pills.nav-stacked
- @projects.each do |project| - @projects.each do |project|
%li{class: ("active" if params[:project_id] == project.id.to_s)} %li{class: ("active" if params[:project_id] == project.id.to_s)}
...@@ -10,7 +19,4 @@ ...@@ -10,7 +19,4 @@
- if @projects.blank? - if @projects.blank?
%p.nothing_here_message This group has no projects yet %p.nothing_here_message This group has no projects yet
%fieldset
%hr
= link_to "Reset", people_group_path(@group), class: 'btn pull-right'
...@@ -6,12 +6,18 @@ ...@@ -6,12 +6,18 @@
= render (@project ? "new_member" : "new_group_member") = render (@project ? "new_member" : "new_group_member")
.ui-box .ui-box
%h5.title %h5.title
#{@group.name} Team - if @project
%small #{@project.name} Project Members
(#{@users_groups.count}) %small
(#{@members.count})
- else
#{@group.name} Group Members
%small
(#{@members.count})
%ul.well-list %ul.well-list
- @users_groups.each do |users_group| - @members.each do |member|
- user = users_group.user - user = member.user
- next unless user
%li %li
= image_tag gravatar_icon(user.email, 16), class: "avatar s16" = image_tag gravatar_icon(user.email, 16), class: "avatar s16"
%strong= user.name %strong= user.name
...@@ -21,5 +27,5 @@ ...@@ -21,5 +27,5 @@
- if @group.owners.include?(user) - if @group.owners.include?(user)
%span.label.label-info Group Owner %span.label.label-info Group Owner
- else - else
= users_group.human_group_access = member.human_access
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment