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

REpostiry, Team models

parent e6c0673e
No related branches found
No related tags found
No related merge requests found
class Team
attr_accessor :project
def initialize(project)
@project = project
@roles = UsersProject.roles_hash
end
def add_user(user, access)
add_users_ids([user.id], access)
end
def add_users(users, access)
add_users_ids(users.map(&:id), access)
end
def add_users_ids(users_ids, access)
UsersProject.add_users_into_projects(
[project.id],
user_ids,
access
)
end
# Remove all users from project team
def truncate
UsersProject.truncate_team(project)
end
def members
project.users_projects
end
def guests
members.guests.map(&:user)
end
def reporters
members.reporters.map(&:user)
end
def developers
members.developers.map(&:user)
end
def masters
members.masters.map(&:user)
end
end
class Tree
include Linguist::BlobHelper
attr_accessor :path, :tree, :project, :ref
attr_accessor :path, :tree, :ref
 
delegate :contents, :basename, :name, :data, :mime_type,
:mode, :size, :text?, :colorize, to: :tree
 
def initialize(raw_tree, project, ref = nil, path = nil)
@project, @ref, @path = project, ref, path
def initialize(raw_tree, ref = nil, path = nil)
@ref, @path = ref, path
@tree = if path.present?
raw_tree / path
else
Loading
Loading
Loading
Loading
@@ -42,7 +42,21 @@ class UsersProject < ActiveRecord::Base
scope :in_project, ->(project) { where(project_id: project.id) }
 
class << self
def add_users_into_projects(project_ids, user_ids, project_access)
# Add users to project teams with passed access option
#
# access can be an integer representing a access code
# or symbol like :master representing role
#
def add_users_into_projects(project_ids, user_ids, access)
project_access = if @roles.has_key?(access)
@roles[access]
elsif @roles.values.include?(access)
access
else
raise "Non valid access"
end
UsersProject.transaction do
project_ids.each do |project_id|
user_ids.each do |user_id|
Loading
Loading
@@ -141,6 +155,15 @@ class UsersProject < ActiveRecord::Base
add_users_into_projects(project_ids, [user.id], project_access)
end
 
def roles_hash
{
guest: GUEST,
reporter: REPORTER,
developer: DEVELOPER,
master: MASTER
}
end
def access_roles
{
"Guest" => GUEST,
Loading
Loading
Loading
Loading
@@ -2,19 +2,19 @@
%li= render partial: 'shared/ref_switcher', locals: {destination: 'commits'}
 
= nav_link(controller: [:commit, :commits]) do
= link_to 'Commits', project_commits_path(@project, @project.root_ref)
= link_to 'Commits', project_commits_path(@project, @repository.root_ref)
= nav_link(controller: :compare) do
= link_to 'Compare', project_compare_index_path(@project)
 
= nav_link(html_options: {class: branches_tab_class}) do
= link_to project_repository_path(@project) do
Branches
%span.badge= @project.branches.length
%span.badge= @repository.branches.length
 
= nav_link(controller: :repositories, action: :tags) do
= link_to tags_project_repository_path(@project) do
Tags
%span.badge= @project.tags.length
%span.badge= @repository.tags.length
 
= nav_link(controller: :repositories, action: :stats) do
= link_to stats_project_repository_path(@project) do
Loading
Loading
Loading
Loading
@@ -14,9 +14,9 @@
- if @project.repo_exists?
- if can? current_user, :download_code, @project
= nav_link(controller: %w(tree blob blame)) do
= link_to 'Files', project_tree_path(@project, @ref || @project.root_ref)
= link_to 'Files', project_tree_path(@project, @ref || @repository.root_ref)
= nav_link(controller: %w(commit commits compare repositories protected_branches)) do
= link_to "Commits", project_commits_path(@project, @ref || @project.root_ref)
= link_to "Commits", project_commits_path(@project, @ref || @repository.root_ref)
= nav_link(path: 'projects#graph') do
= link_to "Network", graph_project_path(@project)
 
Loading
Loading
Loading
Loading
@@ -8,7 +8,7 @@
- else
%i.icon-unlock
%strong= truncate(branch.name, length: 60)
- if branch.name == @project.root_ref
- if branch.name == @repository.root_ref
%span.label default
%td
= link_to project_commit_path(@project, commit.id), class: 'commit_short_id' do
Loading
Loading
Loading
Loading
@@ -7,7 +7,7 @@
%b Total commits:
%span= @stats.commits_count
%p
%b Total files in #{@project.root_ref}:
%b Total files in #{@repository.root_ref}:
%span= @stats.files_count
%p
%b Authors:
Loading
Loading
Loading
Loading
@@ -3,9 +3,13 @@
%span.arrow
= link_to project_tree_path(@project, @ref) do
= @project.name
- tree.breadcrumbs(6) do |link|
- tree.breadcrumbs(6) do |title, path|
\/
%li= link
%li
- if path
= link_to truncate(title, length: 40), project_tree_path(@project, path)
- else
= link_to title, '#'
 
.clear
%div.tree_progress
Loading
Loading
@@ -26,7 +30,7 @@
%tr.tree-item
%td.tree-item-file-name
= image_tag "file_empty.png", size: '16x16'
= link_to "..", tree.up_dir_path
= link_to "..", project_tree_path(@project, tree.up_dir_path)
%td
%td
%td
Loading
Loading
Loading
Loading
@@ -68,7 +68,7 @@ module ExtractsPath
id = input
id += '/' unless id.ends_with?('/')
 
valid_refs = @project.ref_names
valid_refs = @project.repository.ref_names
valid_refs.select! { |v| id.start_with?("#{v}/") }
 
if valid_refs.length != 1
Loading
Loading
@@ -114,9 +114,9 @@ module ExtractsPath
 
@id = File.join(@ref, @path)
 
@commit = CommitDecorator.decorate(@project.commit(@ref))
@commit = CommitDecorator.decorate(@project.repository.commit(@ref))
 
@tree = Tree.new(@commit.tree, @project, @ref, @path)
@tree = Tree.new(@commit.tree, @ref, @path)
@tree = TreeDecorator.new(@tree)
 
raise InvalidPathError if @tree.invalid?
Loading
Loading
Loading
Loading
@@ -4,7 +4,6 @@
#
# id :integer not null, primary key
# note :text
# noteable_id :string(255)
# noteable_type :string(255)
# author_id :integer
# created_at :datetime not null
Loading
Loading
@@ -12,6 +11,8 @@
# project_id :integer
# attachment :string(255)
# line_code :string(255)
# commit_id :string(255)
# noteable_id :integer
#
 
require 'spec_helper'
Loading
Loading
Loading
Loading
@@ -9,7 +9,7 @@
# created_at :datetime not null
# updated_at :datetime not null
# private_flag :boolean default(TRUE), not null
# owner_id :integer
# creator_id :integer
# default_branch :string(255)
# issues_enabled :boolean default(TRUE), not null
# wall_enabled :boolean default(TRUE), not null
Loading
Loading
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