Skip to content
Snippets Groups Projects
Commit 439f399b authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets
Browse files

Remove all team resources except models. Move models to deprecated directory

parent 670aaaeb
No related branches found
No related tags found
No related merge requests found
Showing
with 0 additions and 1391 deletions
%h3.page_title
Team Members
(#{@members.count})
%small
Read more about project permissions
%strong= link_to "here", help_permissions_path, class: "vlink"
- if can? current_user, :manage_user_team, @team
%span.pull-right
= link_to new_team_member_path(@team), class: "btn btn-primary small grouped", title: "New Team Member" do
New Team Member
%hr
.row
.span3
%ul.nav.nav-pills.nav-stacked
%li{class: ("active" if !params[:type])}
= link_to team_members_path(@team, type: nil) do
All
%li{class: ("active" if params[:type] == 'masters')}
= link_to team_members_path(@team, type: 'masters') do
Masters
%li{class: ("active" if params[:type] == 'developers')}
= link_to team_members_path(@team, type: 'developers') do
Developers
%li{class: ("active" if params[:type] == 'reporters')}
= link_to team_members_path(@team, type: 'reporters') do
Reporters
%li{class: ("active" if params[:type] == 'guests')}
= link_to team_members_path(@team, type: 'guests') do
Guests
.span9
.clearfix
%div.team-table
= render "teams/members/team", team: @team
%h3.page_title
Team: #{@team.name}
%hr
= form_tag team_members_path(@team), id: "team_members", class: "bulk_import", method: :post do
%h6 1. Choose people you want in the team
.clearfix
= label_tag :user_ids, "People"
.input
= users_select_tag(:user_ids, multiple: true)
%h6 2. Set access level for them
.clearfix
= label_tag :project_access, "Project Access"
.input= select_tag :default_project_access, options_for_select(Project.access_options), class: "project-access-select chosen"
.clearfix
= label_tag :group_admin do
%span Team Admin?
.input= check_box_tag :group_admin
.actions
= submit_tag 'Add users', class: "btn btn-create", id: :add_members_to_team
= link_to "Cancel", team_members_path(@team), class: "btn btn-cancel"
%h3.page_title
Merge Requests
%small (authored by or assigned to Team members)
%small.pull-right #{@merge_requests.total_count} merge requests
%hr
.row
.span3
= render 'filter', entity: 'merge_request'
.span9
- if @merge_requests.any?
- @merge_requests.group_by(&:project).each do |group|
.ui-box
- @project = group[0]
%h5.title
= link_to_project @project
%ul.well-list
- group[1].each do |merge_request|
= render(partial: 'merge_requests/merge_request', locals: {merge_request: merge_request})
%hr
= paginate @merge_requests, theme: "gitlab"
- else
%h3.nothing_here_message Nothing to show here
= form_for @team, url: teams_path do |f|
- if @team.errors.any?
.alert.alert-error
%span= @team.errors.full_messages.first
.clearfix
= f.label :name do
Team name is
.input
= f.text_field :name, placeholder: "Ex. Ruby Developers", class: "xxlarge left"
.clearfix.team-description-holder
= f.label :description, "Details"
.input
= f.text_area :description, maxlength: 250, class: "xxlarge js-gfm-input", rows: 4
.clearfix
.input
%ul
%li All created teams are public (users can view who enter into team and which project are assigned for this team)
%li People within a team see only projects they have access to
%li You will be able to assign existing projects for team
.form-actions
= f.submit 'Create team', class: "btn btn-create"
- if current_user.can_create_group?
.clearfix
.input.light
Need a group for several dependent projects?
= link_to new_group_path, class: "btn btn-tiny" do
Create a group
- if current_user.can_create_project?
.clearfix
.input.light
Want to create a project?
= link_to new_project_path, class: "btn btn-tiny" do
Create a project
= form_tag team_project_path(@team, @project), method: :put do
-if @project.errors.any?
.alert.alert-error
%ul
- @project.errors.full_messages.each do |msg|
%li= msg
.clearfix
%label Max access for Team members:
.input
= select_tag :greatest_project_access, options_for_select(UserTeam.access_roles, @team.max_project_access(@project)), class: "project-access-select chosen span3"
%br
.actions
= submit_tag 'Save', class: "btn btn-save"
= link_to 'Cancel', :back, class: "btn btn-cancel"
%h3.page_title
Edit max access in #{link_to @project.name_with_namespace, @project} for #{link_to(@team.name, team_path(@team))} team
%hr
= render 'form'
xml.instruct!
xml.feed "xmlns" => "http://www.w3.org/2005/Atom", "xmlns:media" => "http://search.yahoo.com/mrss/" do
xml.title "Team feed - #{@team.name}"
xml.link :href => team_url(@team, :atom), :rel => "self", :type => "application/atom+xml"
xml.link :href => team_url(@team), :rel => "alternate", :type => "text/html"
xml.id projects_url
xml.updated @events.maximum(:updated_at).strftime("%Y-%m-%dT%H:%M:%SZ") if @events.any?
@events.each do |event|
if event.proper?
xml.entry do
event_link = event_feed_url(event)
event_title = event_feed_title(event)
xml.id "tag:#{request.host},#{event.created_at.strftime("%Y-%m-%d")}:#{event.id}"
xml.link :href => event_link
xml.title truncate(event_title, :length => 80)
xml.updated event.created_at.strftime("%Y-%m-%dT%H:%M:%SZ")
xml.media :thumbnail, :width => "40", :height => "40", :url => gravatar_icon(event.author_email)
xml.author do |author|
xml.name event.author_name
xml.email event.author_email
end
xml.summary event_title
end
end
end
end
.dashboard
.activities.span8
= link_to dashboard_path, class: 'btn btn-tiny' do
← To dashboard
 
%span.cgray Events and projects are filtered in scope of team
%hr
- if @events.any?
.content_list
- else
%p.nothing_here_message Projects activity will be displayed here
.loading.hide
.side.span4
- if @team.description.present?
.description-block
= @team.description
= render "projects", projects: @projects
.prepend-top-20
= link_to team_path(@team, { format: :atom, private_token: current_user.private_token }), title: "Feed" do
%strong
%i.icon-rss
News Feed
%hr
= render 'shared/promo'
:plain
Pager.append(#{@events.count}, "#{escape_javascript(render(@events))}");
Loading
Loading
@@ -155,20 +155,6 @@ Gitlab::Application.routes.draw do
resources :users_groups, only: [:create, :update, :destroy]
end
 
#
# Teams Area
#
resources :teams, constraints: {id: /(?:[^.]|\.(?!atom$))+/, format: /atom/} do
member do
get :issues
get :merge_requests
end
scope module: :teams do
resources :members, only: [:index, :new, :create, :edit, :update, :destroy]
resources :projects, only: [:index, :new, :create, :edit, :update, :destroy], constraints: { id: /[a-zA-Z.0-9_\-\/]+/ }
end
end
resources :projects, constraints: { id: /[^\/]+/ }, only: [:new, :create]
 
devise_for :users, controllers: { omniauth_callbacks: :omniauth_callbacks, registrations: :registrations }
Loading
Loading
@@ -307,18 +293,6 @@ Gitlab::Application.routes.draw do
end
end
 
scope module: :projects do
resources :teams, only: [] do
collection do
get :available
post :assign
end
member do
delete :resign
end
end
end
resources :notes, only: [:index, :create, :destroy] do
collection do
post :preview
Loading
Loading
class Userteams < Spinach::FeatureSteps
include SharedAuthentication
include SharedPaths
include SharedProject
include Select2Helper
When 'I do not have teams with me' do
UserTeam.with_member(current_user).destroy_all
end
Then 'I should see dashboard page without teams info block' do
page.has_no_css?(".teams-box").must_equal true
end
When 'I have teams with my membership' do
team = create :user_team, owner: current_user
team.add_member(current_user, UserTeam.access_roles["Master"], true)
end
Then 'I should see dashboard page with teams information block' do
page.should have_css(".teams-box")
end
When 'exist user teams' do
team = create :user_team
team.add_member(current_user, UserTeam.access_roles["Master"], true)
end
And 'I click on "All teams" link' do
click_link("All Teams")
end
Then 'I should see "All teams" page' do
current_path.should == teams_path
end
And 'I should see exist teams in teams list' do
team = UserTeam.last
find_in_list(".teams_list tr", team).must_equal true
end
When 'I click to "New team" link' do
click_link("New Team")
end
And 'I submit form with new team info' do
fill_in 'name', with: 'gitlab'
fill_in 'user_team_description', with: 'team description'
click_button 'Create team'
end
And 'I should see newly created team' do
page.should have_content "gitlab"
page.should have_content "team description"
end
Then 'I should be redirected to new team page' do
team = UserTeam.last
current_path.should == team_path(team)
end
When 'I have teams with projects and members' do
team = create :user_team, owner: current_user
@project = create :project
team.add_member(current_user, UserTeam.access_roles["Master"], true)
team.assign_to_project(@project, UserTeam.access_roles["Master"])
@event = create(:closed_issue_event, project: @project)
end
When 'I visit team page' do
visit team_path(UserTeam.last)
end
Then 'I should see projects list' do
within(".side .ui-box") do
page.should have_content(@project.name)
end
end
And 'project from team has issues assigned to me' do
team = UserTeam.last
team.projects.each do |project|
project.issues << create(:issue, assignee: current_user)
end
end
When 'I visit team issues page' do
team = UserTeam.last
visit issues_team_path(team)
end
Then 'I should see issues from this team assigned to me' do
team = UserTeam.last
team.projects.each do |project|
project.issues.assigned_to(current_user).each do |issue|
page.should have_content issue.title
end
end
end
Given 'I have team with projects and members' do
team = create :user_team, owner: current_user
project = create :project
user = create :user
team.add_member(current_user, UserTeam.access_roles["Master"], true)
team.add_member(user, UserTeam.access_roles["Developer"], false)
team.assign_to_project(project, UserTeam.access_roles["Master"])
end
Given 'project from team has issues assigned to teams members' do
team = UserTeam.last
team.projects.each do |project|
team.members.each do |member|
project.issues << create(:issue, assignee: member)
end
end
end
Then 'I should see issues from this team assigned to teams members' do
team = UserTeam.last
team.projects.each do |project|
team.members.each do |member|
project.issues.assigned_to(member).each do |issue|
page.should have_content issue.title
end
end
end
end
Given 'project from team has merge requests assigned to me' do
team = UserTeam.last
team.projects.each do |project|
create(:merge_request, assignee: current_user, project: project)
end
end
When 'I visit team merge requests page' do
team = UserTeam.last
visit merge_requests_team_path(team)
end
Then 'I should see merge requests from this team assigned to me' do
team = UserTeam.last
team.projects.each do |project|
project.merge_requests.each do |merge_request|
page.should have_content merge_request.title
end
end
end
Given 'project from team has merge requests assigned to team members' do
team = UserTeam.last
team.projects.each do |project|
member = team.members.sample
create(:merge_request, assignee: member, project: project)
end
end
Given 'I have new user "John"' do
create :user, name: "John"
end
When 'I visit team people page' do
team = UserTeam.last
visit team_members_path(team)
end
And 'I select user "John" from list with role "Reporter"' do
user = User.find_by_name("John")
select2(user.id, from: "#user_ids", multiple: true)
within "#team_members" do
select "Reporter", from: "default_project_access"
end
click_button "Add"
end
Then 'I should see user "John" in team list' do
user = User.find_by_name("John")
team_members_list = find(".team-table")
team_members_list.should have_content user.name
end
And 'I have my own project without teams' do
@project = create :project, namespace: current_user.namespace
end
And 'I visit my team page' do
team = UserTeam.where(owner_id: current_user.id).last
visit team_path(team)
end
When 'I click on link "Assign Project"' do
click_link "Assign Project"
end
Then 'I should see form with my own project in available projects list' do
projects_select = find("#project_ids")
projects_select.should have_content(@project.name)
end
When 'I submit form with selected project and max access' do
within "#assign_projects" do
select @project.name_with_namespace, from: "project_ids"
select "Reporter", from: "greatest_project_access"
end
click_button "Add"
end
Then 'I should see my own project in team projects list' do
projects = find(".projects-table")
projects.should have_content(@project.name)
end
When 'I click link "New Team Member"' do
click_link "New Team Member"
end
protected
def current_team
@user_team ||= UserTeam.first
end
def project
current_team.projects.first
end
def assigned_to_user key, user
project.send(key).where(assignee_id: user)
end
def find_in_list(selector, item)
members_list = all(selector)
entered = false
members_list.each do |member_item|
entered = true if member_item.has_content?(item.name)
end
entered
end
end
Feature: UserTeams
Background:
Given I sign in as a user
And I own project "Shop"
And project "Shop" has push event
Scenario: I should see teams info block
When I have teams with my membership
And I visit dashboard page
Then I should see dashboard page with teams information block
Scenario: I should can create new team
When I have teams with my membership
And I visit dashboard page
When I click to "New team" link
And I submit form with new team info
Then I should be redirected to new team page
Then I should see newly created team
Scenario: I should see team dashboard list
When I have teams with projects and members
When I visit team page
Then I should see projects list
Scenario: I should see team issues list
Given I have team with projects and members
And project from team has issues assigned to me
When I visit team issues page
Then I should see issues from this team assigned to me
Scenario: I should see teams members issues list
Given I have team with projects and members
Given project from team has issues assigned to teams members
When I visit team issues page
Then I should see issues from this team assigned to teams members
Scenario: I should see team merge requests list
Given I have team with projects and members
Given project from team has merge requests assigned to me
When I visit team merge requests page
Then I should see merge requests from this team assigned to me
Scenario: I should see teams members merge requests list
Given I have team with projects and members
Given project from team has merge requests assigned to team members
When I visit team merge requests page
Then I should see merge requests from this team assigned to me
@javascript
Scenario: I should add user to projects in Team
Given I have team with projects and members
Given I have new user "John"
When I visit team people page
When I click link "New Team Member"
And I select user "John" from list with role "Reporter"
Then I should see user "John" in team list
Scenario: I should assign my team to my own project
Given I have team with projects and members
And I have my own project without teams
And I visit my team page
When I click on link "Assign Project"
Then I should see form with my own project in available projects list
When I submit form with selected project and max access
Then I should see my own project in team projects list
Loading
Loading
@@ -35,7 +35,6 @@ module API
mount Notes
mount Internal
mount SystemHooks
mount UserTeams
mount ProjectSnippets
mount DeployKeys
mount ProjectHooks
Loading
Loading
Loading
Loading
@@ -99,10 +99,6 @@ module API
expose :id, :title, :key, :created_at
end
 
class UserTeam < Grape::Entity
expose :id, :name, :path, :owner_id
end
class MergeRequest < Grape::Entity
expose :id, :target_branch, :source_branch, :project_id, :title, :state
expose :author, :assignee, using: Entities::UserBasic
Loading
Loading
module API
# user_teams API
class UserTeams < Grape::API
before { authenticate! }
resource :user_teams do
helpers do
def handle_team_member_errors(errors)
if errors[:permission].any?
render_api_error!(errors[:permission], 422)
end
not_found!
end
def validate_access_level?(level)
[UsersProject::GUEST, UsersProject::REPORTER, UsersProject::DEVELOPER, UsersProject::MASTER].include? level.to_i
end
end
# Get a user_teams list
#
# Example Request:
# GET /user_teams
get do
if current_user.admin
@user_teams = paginate UserTeam
else
@user_teams = paginate current_user.user_teams
end
present @user_teams, with: Entities::UserTeam
end
# Create user_team. Available only for admin
#
# Parameters:
# name (required) - The name of the user_team
# path (required) - The path of the user_team
# Example Request:
# POST /user_teams
post do
authenticated_as_admin!
required_attributes! [:name, :path]
attrs = attributes_for_keys [:name, :path]
@user_team = UserTeam.new(attrs)
@user_team.owner = current_user
if @user_team.save
present @user_team, with: Entities::UserTeam
else
not_found!
end
end
# Get a single user_team
#
# Parameters:
# id (required) - The ID of a user_team
# Example Request:
# GET /user_teams/:id
get ":id" do
@user_team = UserTeam.find(params[:id])
if current_user.admin or current_user.user_teams.include? @user_team
present @user_team, with: Entities::UserTeam
else
not_found!
end
end
# Get user_team members
#
# Parameters:
# id (required) - The ID of a user_team
# Example Request:
# GET /user_teams/:id/members
get ":id/members" do
@user_team = UserTeam.find(params[:id])
if current_user.admin or current_user.user_teams.include? @user_team
@members = paginate @user_team.members
present @members, with: Entities::TeamMember, user_team: @user_team
else
not_found!
end
end
# Add a new user_team member
#
# Parameters:
# id (required) - The ID of a user_team
# user_id (required) - The ID of a user
# access_level (required) - Project access level
# Example Request:
# POST /user_teams/:id/members
post ":id/members" do
authenticated_as_admin!
required_attributes! [:user_id, :access_level]
if not validate_access_level?(params[:access_level])
render_api_error!("Wrong access level", 422)
end
@user_team = UserTeam.find(params[:id])
if @user_team
team_member = @user_team.user_team_user_relationships.find_by_user_id(params[:user_id])
# Not existing member
if team_member.nil?
@user_team.add_member(params[:user_id], params[:access_level], false)
team_member = @user_team.user_team_user_relationships.find_by_user_id(params[:user_id])
if team_member.nil?
render_api_error!("Error creating membership", 500)
else
@member = team_member.user
present @member, with: Entities::TeamMember, user_team: @user_team
end
else
render_api_error!("Already exists", 409)
end
else
not_found!
end
end
# Get a single team member from user_team
#
# Parameters:
# id (required) - The ID of a user_team
# user_id (required) - The ID of a team member
# Example Request:
# GET /user_teams/:id/members/:user_id
get ":id/members/:user_id" do
@user_team = UserTeam.find(params[:id])
if current_user.admin or current_user.user_teams.include? @user_team
team_member = @user_team.user_team_user_relationships.find_by_user_id(params[:user_id])
unless team_member.nil?
present team_member.user, with: Entities::TeamMember, user_team: @user_team
else
not_found!
end
else
not_found!
end
end
# Remove a team member from user_team
#
# Parameters:
# id (required) - The ID of a user_team
# user_id (required) - The ID of a team member
# Example Request:
# DELETE /user_teams/:id/members/:user_id
delete ":id/members/:user_id" do
authenticated_as_admin!
@user_team = UserTeam.find(params[:id])
if @user_team
team_member = @user_team.user_team_user_relationships.find_by_user_id(params[:user_id])
unless team_member.nil?
team_member.destroy
else
not_found!
end
else
not_found!
end
end
# Get to user_team assigned projects
#
# Parameters:
# id (required) - The ID of a user_team
# Example Request:
# GET /user_teams/:id/projects
get ":id/projects" do
@user_team = UserTeam.find(params[:id])
if current_user.admin or current_user.user_teams.include? @user_team
@projects = paginate @user_team.projects
present @projects, with: Entities::TeamProject, user_team: @user_team
else
not_found!
end
end
# Add a new user_team project
#
# Parameters:
# id (required) - The ID of a user_team
# project_id (required) - The ID of a project
# greatest_access_level (required) - Project access level
# Example Request:
# POST /user_teams/:id/projects
post ":id/projects" do
authenticated_as_admin!
required_attributes! [:project_id, :greatest_access_level]
if not validate_access_level?(params[:greatest_access_level])
render_api_error!("Wrong greatest_access_level", 422)
end
@user_team = UserTeam.find(params[:id])
if @user_team
team_project = @user_team.user_team_project_relationships.find_by_project_id(params[:project_id])
# No existing project
if team_project.nil?
@user_team.assign_to_projects([params[:project_id]], params[:greatest_access_level])
team_project = @user_team.user_team_project_relationships.find_by_project_id(params[:project_id])
if team_project.nil?
render_api_error!("Error creating project assignment", 500)
else
@project = team_project.project
present @project, with: Entities::TeamProject, user_team: @user_team
end
else
render_api_error!("Already exists", 409)
end
else
not_found!
end
end
# Show a single team project from user_team
#
# Parameters:
# id (required) - The ID of a user_team
# project_id (required) - The ID of a project assigned to the team
# Example Request:
# GET /user_teams/:id/projects/:project_id
get ":id/projects/:project_id" do
@user_team = UserTeam.find(params[:id])
if current_user.admin or current_user.user_teams.include? @user_team
team_project = @user_team.user_team_project_relationships.find_by_project_id(params[:project_id])
unless team_project.nil?
present team_project.project, with: Entities::TeamProject, user_team: @user_team
else
not_found!
end
else
not_found!
end
end
# Remove a team project from user_team
#
# Parameters:
# id (required) - The ID of a user_team
# project_id (required) - The ID of a project assigned to the team
# Example Request:
# DELETE /user_teams/:id/projects/:project_id
delete ":id/projects/:project_id" do
authenticated_as_admin!
@user_team = UserTeam.find(params[:id])
if @user_team
team_project = @user_team.user_team_project_relationships.find_by_project_id(params[:project_id])
unless team_project.nil?
team_project.destroy
else
not_found!
end
else
not_found!
end
end
end
end
end
# UserTeamManager class
#
# Used for manage User teams with project repositories
module Gitlab
class UserTeamManager
class << self
def assign(team, project, access)
project = Project.find(project) unless project.is_a? Project
searched_project = team.user_team_project_relationships.find_by_project_id(project.id)
unless searched_project.present?
team.user_team_project_relationships.create(project_id: project.id, greatest_access: access)
update_team_users_access_in_project(team, project, :added)
end
end
def resign(team, project)
project = Project.find(project) unless project.is_a? Project
team.user_team_project_relationships.with_project(project).destroy_all
update_team_users_access_in_project(team, project, :updated)
end
def update_team_user_membership(team, member, options)
updates = {}
if options[:default_projects_access].present?
default_projects_access = options[:default_projects_access].to_s
if default_projects_access != team.default_projects_access(member).to_s
updates[:permission] = default_projects_access
end
end
if options[:group_admin].present?
group_admin = options[:group_admin].to_s == "1" ? true : false
if group_admin != team.admin?(member)
updates[:group_admin] = group_admin
end
end
return true if updates.blank?
user_team_relationship = team.user_team_user_relationships.find_by_user_id(member)
return false unless user_team_relationship.update_attributes(updates)
rebuild_project_permissions_to_member(team, member) if updates[:permission]
true
end
def update_project_greates_access(team, project, permission)
project_relation = team.user_team_project_relationships.find_by_project_id(project)
if permission != team.max_project_access(project)
if project_relation.update_attributes(greatest_access: permission)
update_team_users_access_in_project(team, project, :updated)
true
else
false
end
else
true
end
end
def rebuild_project_permissions_to_member(team, member)
team.projects.each do |project|
update_team_user_access_in_project(team, member, project, :updated)
end
end
def update_team_users_access_in_project(team, project, action)
members = team.members
members.each do |member|
update_team_user_access_in_project(team, member, project, action)
end
end
def update_team_user_access_in_project(team, user, project, action)
granted_access = max_teams_member_permission_in_project(user, project, action)
project_team_user = UsersProject.find_by_user_id_and_project_id(user.id, project.id)
if granted_access.zero?
project_team_user.destroy if project_team_user.present?
return
end
if project_team_user.present?
project_team_user.update_attributes(project_access: granted_access)
else
project.team << [user, granted_access]
end
end
def max_teams_member_permission_in_project(user, project, action = nil, teams = nil)
result_access = 0
teams ||= project.user_teams.with_member(user)
if action && (action == :added)
result_access = project.users_projects.with_user(user).first.project_access if project.users_projects.with_user(user).any?
end
if teams.any?
teams.each do |team|
granted_access = max_team_member_permission_in_project(team, user, project)
result_access = [granted_access, result_access].max
end
end
result_access
end
def max_team_member_permission_in_project(team, user, project)
member_access = team.default_projects_access(user)
team_access = team.user_team_project_relationships.find_by_project_id(project.id).greatest_access
[team_access, member_access].min
end
def add_member_into_team(team, user, access, admin)
user = User.find(user) unless user.is_a? User
team.user_team_user_relationships.create(user_id: user.id, permission: access, group_admin: admin)
team.projects.each do |project|
update_team_user_access_in_project(team, user, project, :added)
end
end
def remove_member_from_team(team, user)
user = User.find(user) unless user.is_a? User
team.user_team_user_relationships.with_user(user).destroy_all
other_teams = []
team.projects.each do |project|
other_teams << project.user_teams.with_member(user)
end
other_teams.uniq
unless other_teams.any?
UsersProject.in_projects(team.projects).with_user(user).destroy_all
end
end
end
end
end
# == Schema Information
#
# Table name: user_team_project_relationships
#
# id :integer not null, primary key
# project_id :integer
# user_team_id :integer
# greatest_access :integer
# created_at :datetime not null
# updated_at :datetime not null
#
require 'spec_helper'
describe UserTeamProjectRelationship do
pending "add some examples to (or delete) #{__FILE__}"
end
# == Schema Information
#
# Table name: user_teams
#
# id :integer not null, primary key
# name :string(255)
# path :string(255)
# owner_id :integer
# created_at :datetime not null
# updated_at :datetime not null
# description :string(255) default(""), not null
#
require 'spec_helper'
describe UserTeam do
let(:team) { FactoryGirl.create :user_team }
context ".add_member" do
let(:user) { FactoryGirl.create :user }
it "should work" do
team.add_member(user, UsersProject::DEVELOPER, false)
team.members.should include(user)
end
end
context ".remove_member" do
let(:user) { FactoryGirl.create :user }
before { team.add_member(user, UsersProject::DEVELOPER, false) }
it "should work" do
team.remove_member(user)
team.members.should_not include(user)
end
end
end
# == Schema Information
#
# Table name: user_team_user_relationships
#
# id :integer not null, primary key
# user_id :integer
# user_team_id :integer
# group_admin :boolean
# permission :integer
# created_at :datetime not null
# updated_at :datetime not null
#
require 'spec_helper'
describe UserTeamUserRelationship do
pending "add some examples to (or delete) #{__FILE__}"
end
require 'spec_helper'
describe API::API do
include ApiHelpers
# Create test objects
let(:user1) { create(:user) }
let(:user2) { create(:user) }
let(:admin) { create(:admin) }
let!(:group1) { create(:group, owner: user1) }
let!(:group2) { create(:group, owner: user2) }
let(:user_team1) { create(:user_team, owner: user1) }
let(:user_team2) { create(:user_team, owner: user2) }
let!(:project1) { create(:project, creator_id: admin.id) }
let!(:project2) { create(:project, creator_id: admin.id) }
before {
# Add members to teams
user_team1.add_member(user1, UsersProject::MASTER, false)
user_team2.add_member(user2, UsersProject::MASTER, false)
# Add projects to teams
user_team1.assign_to_projects([project1.id], UsersProject::MASTER)
user_team2.assign_to_projects([project2.id], UsersProject::MASTER)
}
describe "GET /user_teams" do
context "when unauthenticated" do
it "should return authentication error" do
get api("/user_teams")
response.status.should == 401
end
end
context "when authenticated as user" do
it "normal user: should return an array of user_teams of user1" do
get api("/user_teams", user1)
response.status.should == 200
json_response.should be_an Array
json_response.length.should == 1
json_response.first['name'].should == user_team1.name
end
end
context "when authenticated as admin" do
it "admin: should return an array of all user_teams" do
get api("/user_teams", admin)
response.status.should == 200
json_response.should be_an Array
json_response.length.should == 2
end
end
end
describe "GET /user_teams/:id" do
context "when authenticated as user" do
it "should return one of user1's user_teams" do
get api("/user_teams/#{user_team1.id}", user1)
response.status.should == 200
json_response['name'] == user_team1.name
end
it "should not return a non existing team" do
get api("/user_teams/1328", user1)
response.status.should == 404
end
it "should not return a user_team not attached to user1" do
get api("/user_teams/#{user_team2.id}", user1)
response.status.should == 404
end
end
context "when authenticated as admin" do
it "should return any existing user_team" do
get api("/user_teams/#{user_team2.id}", admin)
response.status.should == 200
json_response['name'].should == user_team2.name
end
it "should not return a non existing user_team" do
get api("/user_teams/1328", admin)
response.status.should == 404
end
end
end
describe "POST /user_teams" do
context "when authenticated as user" do
it "should not create user_team" do
count_before=UserTeam.count
post api("/user_teams", user1), attributes_for(:user_team)
response.status.should == 403
UserTeam.count.should == count_before
end
end
context "when authenticated as admin" do
it "should create user_team" do
count_before=UserTeam.count
post api("/user_teams", admin), attributes_for(:user_team)
response.status.should == 201
UserTeam.count.should == count_before + 1
end
it "should not create user_team, duplicate" do
post api("/user_teams", admin), {:name => "Duplicate Test", :path => user_team2.path}
response.status.should == 404
end
it "should return 400 bad request error if name not given" do
post api("/user_teams", admin), {:path => user_team2.path}
response.status.should == 400
end
it "should return 400 bad request error if path not given" do
post api("/user_teams", admin), {:name => 'test'}
response.status.should == 400
end
end
end
# Members
describe "GET /user_teams/:id/members" do
context "when authenticated as user" do
it "should return user1 as member of user1's user_teams" do
get api("/user_teams/#{user_team1.id}/members", user1)
response.status.should == 200
json_response.first['name'].should == user1.name
json_response.first['access_level'].should == UsersProject::MASTER
end
end
context "when authenticated as admin" do
it "should return member of any existing user_team" do
get api("/user_teams/#{user_team2.id}/members", admin)
response.status.should == 200
json_response.first['name'].should == user2.name
json_response.first['access_level'].should == UsersProject::MASTER
end
end
end
describe "POST /user_teams/:id/members" do
context "when authenticated as user" do
it "should not add user2 as member of user_team1" do
post api("/user_teams/#{user_team1.id}/members", user1), user_id: user2.id, access_level: UsersProject::MASTER
response.status.should == 403
end
end
context "when authenticated as admin" do
it "should return ok and add new member" do
count_before=user_team1.user_team_user_relationships.count
post api("/user_teams/#{user_team1.id}/members", admin), user_id: user2.id, access_level: UsersProject::MASTER
response.status.should == 201
json_response['name'].should == user2.name
json_response['access_level'].should == UsersProject::MASTER
user_team1.user_team_user_relationships.count.should == count_before + 1
end
it "should return ok if member already exists" do
post api("/user_teams/#{user_team2.id}/members", admin), user_id: user2.id, access_level: UsersProject::MASTER
response.status.should == 409
end
it "should return a 400 error when user id is not given" do
post api("/user_teams/#{user_team2.id}/members", admin), access_level: UsersProject::MASTER
response.status.should == 400
end
it "should return a 400 error when access level is not given" do
post api("/user_teams/#{user_team2.id}/members", admin), user_id: user2.id
response.status.should == 400
end
it "should return a 422 error when access level is not known" do
post api("/user_teams/#{user_team2.id}/members", admin), user_id: user1.id, access_level: 1234
response.status.should == 422
end
end
end
# Get single member
describe "GET /user_teams/:id/members/:user_id" do
context "when authenticated as member" do
it "should show user1's membership of user_team1" do
get api("/user_teams/#{user_team1.id}/members/#{user1.id}", user1)
response.status.should == 200
json_response['name'].should == user1.name
json_response['access_level'].should == UsersProject::MASTER
end
it "should show that user2 is not member of user_team1" do
get api("/user_teams/#{user_team1.id}/members/#{user2.id}", user1)
response.status.should == 404
end
end
context "when authenticated as non-member" do
it "should not show user1's membership of user_team1" do
get api("/user_teams/#{user_team1.id}/members/#{user1.id}", user2)
response.status.should == 404
end
end
context "when authenticated as admin" do
it "should show user1's membership of user_team1" do
get api("/user_teams/#{user_team1.id}/members/#{user1.id}", admin)
response.status.should == 200
json_response['name'].should == user1.name
json_response['access_level'].should == UsersProject::MASTER
end
it "should return a 404 error when user id is not known" do
get api("/user_teams/#{user_team2.id}/members/1328", admin)
response.status.should == 404
end
end
end
describe "DELETE /user_teams/:id/members/:user_id" do
context "when authenticated as user" do
it "should not delete user1's membership of user_team1" do
delete api("/user_teams/#{user_team1.id}/members/#{user1.id}", user1)
response.status.should == 403
end
end
context "when authenticated as admin" do
it "should delete user1's membership of user_team1" do
count_before=user_team1.user_team_user_relationships.count
delete api("/user_teams/#{user_team1.id}/members/#{user1.id}", admin)
response.status.should == 200
user_team1.user_team_user_relationships.count.should == count_before - 1
end
it "should return a 404 error when user id is not known" do
delete api("/user_teams/#{user_team2.id}/members/1328", admin)
response.status.should == 404
end
end
end
# Projects
describe "GET /user_teams/:id/projects" do
context "when authenticated as user" do
it "should return project1 as assigned to user_team1 as member user1" do
get api("/user_teams/#{user_team1.id}/projects", user1)
response.status.should == 200
json_response.first['name'].should == project1.name
json_response.length.should == user_team1.user_team_project_relationships.count
end
end
context "when authenticated as admin" do
it "should return project2 as assigned to user_team2 as non-member, but admin" do
get api("/user_teams/#{user_team2.id}/projects", admin)
response.status.should == 200
json_response.first['name'].should == project2.name
json_response.first['greatest_access_level'].should == UsersProject::MASTER
end
end
end
describe "POST /user_teams/:id/projects" do
context "when authenticated as admin" do
it "should return ok and add new project" do
count_before=user_team1.user_team_project_relationships.count
post api("/user_teams/#{user_team1.id}/projects", admin),
project_id: project2.id,
greatest_access_level: UsersProject::MASTER
response.status.should == 201
json_response['name'].should == project2.name
json_response['greatest_access_level'].should == UsersProject::MASTER
user_team1.user_team_project_relationships.count.should == count_before + 1
end
it "should return ok if project already exists" do
post api("/user_teams/#{user_team2.id}/projects", admin),
project_id: project2.id,
greatest_access_level: UsersProject::MASTER
response.status.should == 409
end
it "should return a 400 error when project id is not given" do
post api("/user_teams/#{user_team2.id}/projects", admin), greatest_access_level: UsersProject::MASTER
response.status.should == 400
end
it "should return a 400 error when access level is not given" do
post api("/user_teams/#{user_team2.id}/projects", admin), project_id: project2.id
response.status.should == 400
end
it "should return a 422 error when access level is not known" do
post api("/user_teams/#{user_team2.id}/projects", admin),
project_id: project2.id,
greatest_access_level: 1234
response.status.should == 422
end
end
end
describe "GET /user_teams/:id/projects/:project_id" do
context "when authenticated as member" do
it "should show project1's assignment to user_team1" do
get api("/user_teams/#{user_team1.id}/projects/#{project1.id}", user1)
response.status.should == 200
json_response['name'].should == project1.name
json_response['greatest_access_level'].should == UsersProject::MASTER
end
it "should show project2's is not assigned to user_team1" do
get api("/user_teams/#{user_team1.id}/projects/#{project2.id}", user1)
response.status.should == 404
end
end
context "when authenticated as non-member" do
it "should not show project1's assignment to user_team1" do
get api("/user_teams/#{user_team1.id}/projects/#{project1.id}", user2)
response.status.should == 404
end
end
context "when authenticated as admin" do
it "should show project1's assignment to user_team1" do
get api("/user_teams/#{user_team1.id}/projects/#{project1.id}", admin)
response.status.should == 200
json_response['name'].should == project1.name
json_response['greatest_access_level'].should == UsersProject::MASTER
end
it "should return a 404 error when project id is not known" do
get api("/user_teams/#{user_team2.id}/projects/1328", admin)
response.status.should == 404
end
end
end
describe "DELETE /user_teams/:id/projects/:project_id" do
context "when authenticated as user" do
it "should not delete project1's assignment to user_team2" do
delete api("/user_teams/#{user_team2.id}/projects/#{project1.id}", user1)
response.status.should == 403
end
end
context "when authenticated as admin" do
it "should delete project1's assignment to user_team1" do
count_before=user_team1.user_team_project_relationships.count
delete api("/user_teams/#{user_team1.id}/projects/#{project1.id}", admin)
response.status.should == 200
user_team1.user_team_project_relationships.count.should == count_before - 1
end
it "should return a 404 error when project id is not known" do
delete api("/user_teams/#{user_team2.id}/projects/1328", admin)
response.status.should == 404
end
end
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment