Merge branch 'master' into fixes/api

This commit is contained in:
Sebastian Ziebell 2013-02-14 17:02:16 +01:00
commit c8b92a4be2
22 changed files with 201 additions and 233 deletions

View file

@ -9,8 +9,12 @@ class Admin::UsersController < Admin::ApplicationController
end end
def show def show
@projects = Project.scoped # Projects user can be added to
@projects = @projects.without_user(admin_user) if admin_user.authorized_projects.present? @not_in_projects = Project.scoped
@not_in_projects = @not_in_projects.without_user(admin_user) if admin_user.authorized_projects.present?
# Projects he already own or joined
@projects = admin_user.authorized_projects.where('projects.id in (?)', admin_user.authorized_projects.map(&:id))
end end
def team_update def team_update

View file

@ -20,15 +20,15 @@ class Event < ActiveRecord::Base
default_scope where("author_id IS NOT NULL") default_scope where("author_id IS NOT NULL")
Created = 1 CREATED = 1
Updated = 2 UPDATED = 2
Closed = 3 CLOSED = 3
Reopened = 4 REOPENED = 4
Pushed = 5 PUSHED = 5
Commented = 6 COMMENTED = 6
Merged = 7 MERGED = 7
Joined = 8 # User joined project JOINED = 8 # User joined project
Left = 9 # User left project LEFT = 9 # User left project
delegate :name, :email, to: :author, prefix: true, allow_nil: true delegate :name, :email, to: :author, prefix: true, allow_nil: true
delegate :title, to: :issue, prefix: true, allow_nil: true delegate :title, to: :issue, prefix: true, allow_nil: true
@ -43,15 +43,15 @@ class Event < ActiveRecord::Base
# Scopes # Scopes
scope :recent, -> { order("created_at DESC") } scope :recent, -> { order("created_at DESC") }
scope :code_push, -> { where(action: Pushed) } scope :code_push, -> { where(action: PUSHED) }
scope :in_projects, ->(project_ids) { where(project_id: project_ids).recent } scope :in_projects, ->(project_ids) { where(project_id: project_ids).recent }
class << self class << self
def determine_action(record) def determine_action(record)
if [Issue, MergeRequest].include? record.class if [Issue, MergeRequest].include? record.class
Event::Created Event::CREATED
elsif record.kind_of? Note elsif record.kind_of? Note
Event::Commented Event::COMMENTED
end end
end end
end end
@ -79,19 +79,19 @@ class Event < ActiveRecord::Base
end end
def push? def push?
action == self.class::Pushed && valid_push? action == self.class::PUSHED && valid_push?
end end
def merged? def merged?
action == self.class::Merged action == self.class::MERGED
end end
def closed? def closed?
action == self.class::Closed action == self.class::CLOSED
end end
def reopened? def reopened?
action == self.class::Reopened action == self.class::REOPENED
end end
def milestone? def milestone?
@ -111,11 +111,11 @@ class Event < ActiveRecord::Base
end end
def joined? def joined?
action == Joined action == JOINED
end end
def left? def left?
action == Left action == LEFT
end end
def membership_changed? def membership_changed?

View file

@ -133,11 +133,11 @@ class MergeRequest < ActiveRecord::Base
end end
def merge_event def merge_event
self.project.events.where(target_id: self.id, target_type: "MergeRequest", action: Event::Merged).last self.project.events.where(target_id: self.id, target_type: "MergeRequest", action: Event::MERGED).last
end end
def closed_event def closed_event
self.project.events.where(target_id: self.id, target_type: "MergeRequest", action: Event::Closed).last self.project.events.where(target_id: self.id, target_type: "MergeRequest", action: Event::CLOSED).last
end end
def commits def commits
@ -184,7 +184,7 @@ class MergeRequest < ActiveRecord::Base
self.mark_as_merged! self.mark_as_merged!
Event.create( Event.create(
project: self.project, project: self.project,
action: Event::Merged, action: Event::MERGED,
target_id: self.id, target_id: self.id,
target_type: "MergeRequest", target_type: "MergeRequest",
author_id: user_id author_id: user_id

View file

@ -103,7 +103,7 @@ class Project < ActiveRecord::Base
end end
def with_push def with_push
includes(:events).where('events.action = ?', Event::Pushed) includes(:events).where('events.action = ?', Event::PUSHED)
end end
def active def active
@ -336,7 +336,7 @@ class Project < ActiveRecord::Base
def observe_push(data) def observe_push(data)
Event.create( Event.create(
project: self, project: self,
action: Event::Pushed, action: Event::PUSHED,
data: data, data: data,
author_id: data[:user_id] author_id: data[:user_id]
) )

View file

@ -138,7 +138,7 @@ class User < ActiveRecord::Base
end end
def search query def search query
where("name LIKE :query or email LIKE :query", query: "%#{query}%") where("name LIKE :query OR email LIKE :query OR username LIKE :query", query: "%#{query}%")
end end
end end
@ -313,4 +313,8 @@ class User < ActiveRecord::Base
UserTeam.where(id: ids) UserTeam.where(id: ids)
end end
end end
def owned_teams
UserTeam.where(owner_id: self.id)
end
end end

View file

@ -26,7 +26,7 @@ class ActivityObserver < ActiveRecord::Observer
project: record.project, project: record.project,
target_id: record.id, target_id: record.id,
target_type: record.class.name, target_type: record.class.name,
action: (record.closed ? Event::Closed : Event::Reopened), action: (record.closed ? Event::CLOSED : Event::REOPENED),
author_id: record.author_id_of_changes author_id: record.author_id_of_changes
) )
end end

View file

@ -7,7 +7,7 @@ class UsersProjectObserver < ActiveRecord::Observer
def after_create(users_project) def after_create(users_project)
Event.create( Event.create(
project_id: users_project.project.id, project_id: users_project.project.id,
action: Event::Joined, action: Event::JOINED,
author_id: users_project.user.id author_id: users_project.user.id
) )
end end
@ -15,7 +15,7 @@ class UsersProjectObserver < ActiveRecord::Observer
def after_destroy(users_project) def after_destroy(users_project)
Event.create( Event.create(
project_id: users_project.project.id, project_id: users_project.project.id,
action: Event::Left, action: Event::LEFT,
author_id: users_project.user.id author_id: users_project.user.id
) )
end end

View file

@ -3,56 +3,60 @@
= link_to 'New User', new_admin_user_path, class: "btn btn-small pull-right" = link_to 'New User', new_admin_user_path, class: "btn btn-small pull-right"
%br %br
= form_tag admin_users_path, method: :get, class: 'form-inline' do .row
= text_field_tag :name, params[:name], class: "xlarge" .span3
= submit_tag "Search", class: "btn submit btn-primary" .admin-filter
%ul.nav.nav-tabs = form_tag admin_users_path, method: :get, class: 'form-inline' do
%li{class: "#{'active' unless params[:filter]}"} = search_field_tag :name, params[:name], placeholder: 'Name, email or username', class: 'search-text-input span2'
= link_to admin_users_path do = button_tag type: 'submit', class: 'btn' do
Active %i.icon-search
%span.badge= User.active.count %ul.nav.nav-pills.nav-stacked
%li{class: "#{'active' if params[:filter] == "admins"}"} %li{class: "#{'active' unless params[:filter]}"}
= link_to admin_users_path(filter: "admins") do = link_to admin_users_path do
Admins Active
%span.badge= User.admins.count %small.pull-right= User.active.count
%li{class: "#{'active' if params[:filter] == "blocked"}"} %li{class: "#{'active' if params[:filter] == "admins"}"}
= link_to admin_users_path(filter: "blocked") do = link_to admin_users_path(filter: "admins") do
Blocked Admins
%span.badge= User.blocked.count %small.pull-right= User.admins.count
%li{class: "#{'active' if params[:filter] == "wop"}"} %li{class: "#{'active' if params[:filter] == "blocked"}"}
= link_to admin_users_path(filter: "wop") do = link_to admin_users_path(filter: "blocked") do
Without projects Blocked
%span.badge= User.without_projects.count %small.pull-right= User.blocked.count
%li{class: "#{'active' if params[:filter] == "wop"}"}
= link_to admin_users_path(filter: "wop") do
Without projects
%small.pull-right= User.without_projects.count
%hr
= link_to 'Reset', admin_users_path, class: "btn btn-cancel"
%table .span9
%thead .ui-box
%tr %h5.title
%th Admin Users (#{@admin_users.total_count})
%th %ul.well-list
Name - @admin_users.each do |user|
%i.icon-sort-down %li
%th Username - if user.blocked?
%th Email %i.icon-lock.cred
%th Projects - else
%th Edit %i.icon-user.cgreen
%th.cred Danger Zone! = link_to user.name, [:admin, user]
- if user.admin?
- @admin_users.each do |user| %strong.cred (Admin)
%tr - if user == current_user
%td= check_box_tag "admin", 1, user.admin, disabled: :disabled %span.cred It's you!
%td= link_to user.name, [:admin, user] .pull-right
%td= user.username %span.light
%td= user.email %i.icon-envelope
%td= user.users_projects.count = mail_to user.email, user.email, class: 'light'
%td= link_to 'Edit', edit_admin_user_path(user), id: "edit_#{dom_id(user)}", class: "btn btn-small" &nbsp;
%td.bgred = link_to 'Edit', edit_admin_user_path(user), id: "edit_#{dom_id(user)}", class: "btn btn-small"
- if user == current_user - unless user == current_user
%span.cred It's you! - if user.blocked
- else = link_to 'Unblock', unblock_admin_user_path(user), method: :put, class: "btn btn-small success"
- if user.blocked - else
= link_to 'Unblock', unblock_admin_user_path(user), method: :put, class: "btn btn-small success" = link_to 'Block', block_admin_user_path(user), confirm: 'USER WILL BE BLOCKED! Are you sure?', method: :put, class: "btn btn-small btn-remove"
- else = link_to 'Destroy', [:admin, user], confirm: "USER #{user.name} WILL BE REMOVED! Are you sure?", method: :delete, class: "btn btn-small btn-remove"
= link_to 'Block', block_admin_user_path(user), confirm: 'USER WILL BE BLOCKED! Are you sure?', method: :put, class: "btn btn-small btn-remove" %li.bottom
= link_to 'Destroy', [:admin, user], confirm: "USER #{user.name} WILL BE REMOVED! Are you sure?", method: :delete, class: "btn btn-small btn-remove" = paginate @admin_users, theme: "gitlab"
= paginate @admin_users, theme: "admin"

View file

@ -1,127 +1,83 @@
%h3.page_title .row
User: #{@admin_user.name} .span6
- if @admin_user.blocked %h3.page_title
%small Blocked = image_tag gravatar_icon(@admin_user.email, 90), class: "avatar s90"
- if @admin_user.admin = @admin_user.name
%small Administrator - if @admin_user.blocked
= link_to edit_admin_user_path(@admin_user), class: "btn pull-right" do %span.cred (Blocked)
%i.icon-edit - if @admin_user.admin
Edit %span.cred (Admin)
.pull-right
%br = link_to edit_admin_user_path(@admin_user), class: "btn pull-right" do
%i.icon-edit
%table.zebra-striped Edit
%thead %br
%tr %small @#{@admin_user.username}
%th Profile %br
%th %small member since #{@admin_user.created_at.stamp("Nov 12, 2031")}
%tr .clearfix
%td %hr
%b %h5
Email: Add User to Projects
%td %small
= @admin_user.email
%tr
%td
%b
Username:
%td
= @admin_user.username
%tr
%td
%b
Admin:
%td= check_box_tag "admin", 1, @admin_user.admin, disabled: :disabled
%tr
%td
%b
Blocked:
%td= check_box_tag "blocked", 1, @admin_user.blocked, disabled: :disabled
%tr
%td
%b
Created at:
%td
= @admin_user.created_at.stamp("March 1, 1999")
%tr
%td
%b
Projects limit:
%td
= @admin_user.projects_limit
- unless @admin_user.skype.empty?
%tr
%td
%b
Skype:
%td
= @admin_user.skype
- unless @admin_user.linkedin.empty?
%tr
%td
%b
Linkedin:
%td
= @admin_user.linkedin
- unless @admin_user.twitter.empty?
%tr
%td
%b
Twitter:
%td
= @admin_user.twitter
%br
%h5 Add User to Projects
%br
= form_tag team_update_admin_user_path(@admin_user), class: "bulk_import", method: :put do
%table
%thead
%tr
%th Projects
%th Project Access:
%tr
%td= select_tag :project_ids, options_from_collection_for_select(@projects , :id, :name_with_namespace), multiple: true, data: {placeholder: 'Select projects'}, class: 'chosen span5'
%td= select_tag :project_access, options_for_select(Project.access_options), class: "project-access-select chosen span3"
%tr
%td= submit_tag 'Add', class: "btn btn-primary"
%td
Read more about project permissions Read more about project permissions
%strong= link_to "here", help_permissions_path, class: "vlink" %strong= link_to "here", help_permissions_path, class: "vlink"
%br %br
= form_tag team_update_admin_user_path(@admin_user), class: "bulk_import", method: :put do
.control-group
= label_tag :project_ids, "Projects", class: 'control-label'
.controls
= select_tag :project_ids, options_from_collection_for_select(@not_in_projects , :id, :name_with_namespace), multiple: true, data: {placeholder: 'Select projects'}, class: 'chosen span3'
.control-group
= label_tag :project_access, "Project Access", class: 'control-label'
.controls
= select_tag :project_access, options_for_select(Project.access_options), class: "project-access-select chosen span3"
- if @admin_user.groups.present? .form-actions
%h5 Owner of groups: = submit_tag 'Add', class: "btn btn-create"
%br .pull-right
%br
%table.zebra-striped - if @admin_user.owned_groups.present?
%thead .ui-box
%tr %h5.title Owned groups:
%th Name %ul.well-list
- @admin_user.groups.each do |group|
%li
%strong= link_to group.name, admin_group_path(group)
- @admin_user.groups.each do |group| - if @admin_user.owned_teams.present?
%tr .ui-box
%td= link_to group.name, admin_group_path(group) %h5.title Owned teams:
%ul.well-list
- @admin_user.owned_teams.each do |team|
%li
%strong= link_to team.name, admin_team_path(team)
- if @admin_user.authorized_projects.present? .span6
%h5 Authorized Projects: = render 'users/profile', user: @admin_user
%br .ui-box
%h5.title Projects (#{@projects.count})
%table.zebra-striped %ul.well-list
%thead - @projects.each do |project|
%tr %li
%th Name = link_to admin_project_path(project), class: dom_class(project) do
%th Project Access - if project.namespace
%th = project.namespace.human_name
%th \/
%strong.well-title
- @admin_user.tm_in_authorized_projects.each do |tm| = truncate(project.name, length: 45)
- project = tm.project %span.pull-right.light
%tr - if project.owner == @admin_user
%td= link_to project.name_with_namespace, admin_project_path(project) %i.icon-wrench
%td= tm.project_access_human - tm = project.team.get_tm(@admin_user.id)
%td= link_to 'Edit Access', edit_admin_project_member_path(project, tm.user), class: "btn btn-small" - if tm
%td= link_to 'Remove from team', admin_project_member_path(project, tm.user), confirm: 'Are you sure?', method: :delete, class: "btn btn-small btn-remove" = tm.project_access_human
= link_to edit_admin_project_member_path(project, tm.user), class: "btn btn-small" do
%i.icon-edit
= link_to admin_project_member_path(project, tm.user), confirm: 'Are you sure?', method: :delete, class: "btn btn-small btn-remove" do
%i.icon-remove
%p.light
%i.icon-wrench
&ndash; user is a project owner

View file

@ -26,7 +26,7 @@
= f.label :import_url do = f.label :import_url do
%span Import existing repo %span Import existing repo
.input .input
= f.text_field :import_url, class: 'xlarge' = f.text_field :import_url, class: 'xlarge', placeholder: 'https://github.com/randx/six.git'
.light .light
URL should be clonable URL should be clonable

View file

@ -4,20 +4,20 @@
%ul.well-list %ul.well-list
%li %li
%strong Email %strong Email
%span.pull-right= mail_to @user.email %span.pull-right= mail_to user.email
- unless @user.skype.blank? - unless user.skype.blank?
%li %li
%strong Skype %strong Skype
%span.pull-right= @user.skype %span.pull-right= user.skype
- unless @user.linkedin.blank? - unless user.linkedin.blank?
%li %li
%strong LinkedIn %strong LinkedIn
%span.pull-right= @user.linkedin %span.pull-right= user.linkedin
- unless @user.twitter.blank? - unless user.twitter.blank?
%li %li
%strong Twitter %strong Twitter
%span.pull-right= @user.twitter %span.pull-right= user.twitter
- unless @user.bio.blank? - unless user.bio.blank?
%li %li
%strong Bio %strong Bio
%span.pull-right= @user.bio %span.pull-right= user.bio

View file

@ -10,9 +10,9 @@
%strong.well-title %strong.well-title
= truncate(project.name, length: 45) = truncate(project.name, length: 45)
%span.pull-right.light %span.pull-right.light
- if project.owner == @user - if project.owner == user
%i.icon-wrench %i.icon-wrench
- tm = project.team.get_tm(@user.id) - tm = project.team.get_tm(user.id)
- if tm - if tm
= tm.project_access_human = tm.project_access_human
%p.light %p.light

View file

@ -17,5 +17,5 @@
%h5 Recent events %h5 Recent events
= render @events = render @events
.span4 .span4
= render 'profile' = render 'profile', user: @user
= render 'projects' = render 'projects', user: @user

View file

@ -2,7 +2,7 @@
# note that config/gitlab.yml web path should also be changed # note that config/gitlab.yml web path should also be changed
# ENV['RAILS_RELATIVE_URL_ROOT'] = "/gitlab" # ENV['RAILS_RELATIVE_URL_ROOT'] = "/gitlab"
app_dir = "/home/git/gitlab/" app_dir = File.expand_path '../../', __FILE__
worker_processes 2 worker_processes 2
working_directory app_dir working_directory app_dir

View file

@ -33,7 +33,7 @@ class Dashboard < Spinach::FeatureSteps
Event.create( Event.create(
project: project, project: project,
author_id: user.id, author_id: user.id,
action: Event::Joined action: Event::JOINED
) )
end end
@ -47,7 +47,7 @@ class Dashboard < Spinach::FeatureSteps
Event.create( Event.create(
project: project, project: project,
author_id: user.id, author_id: user.id,
action: Event::Left action: Event::LEFT
) )
end end

View file

@ -45,7 +45,7 @@ class EventFilters < Spinach::FeatureSteps
@event = Event.create( @event = Event.create(
project: @project, project: @project,
action: Event::Pushed, action: Event::PUSHED,
data: data, data: data,
author_id: @user.id author_id: @user.id
) )
@ -56,7 +56,7 @@ class EventFilters < Spinach::FeatureSteps
Event.create( Event.create(
project: @project, project: @project,
author_id: user.id, author_id: user.id,
action: Event::Joined action: Event::JOINED
) )
end end
@ -64,7 +64,7 @@ class EventFilters < Spinach::FeatureSteps
merge_request = create :merge_request, author: @user, project: @project merge_request = create :merge_request, author: @user, project: @project
Event.create( Event.create(
project: @project, project: @project,
action: Event::Merged, action: Event::MERGED,
target_id: merge_request.id, target_id: merge_request.id,
target_type: "MergeRequest", target_type: "MergeRequest",
author_id: @user.id author_id: @user.id

View file

@ -33,7 +33,7 @@ module SharedProject
@event = Event.create( @event = Event.create(
project: @project, project: @project,
action: Event::Pushed, action: Event::PUSHED,
data: data, data: data,
author_id: @user.id author_id: @user.id
) )

View file

@ -37,15 +37,15 @@ class EventFilter
filter = params.dup filter = params.dup
actions = [] actions = []
actions << Event::Pushed if filter.include? 'push' actions << Event::PUSHED if filter.include? 'push'
actions << Event::Merged if filter.include? 'merged' actions << Event::MERGED if filter.include? 'merged'
if filter.include? 'team' if filter.include? 'team'
actions << Event::Joined actions << Event::JOINED
actions << Event::Left actions << Event::LEFT
end end
actions << Event::Commented if filter.include? 'comments' actions << Event::COMMENTED if filter.include? 'comments'
events = events.where(action: actions) events = events.where(action: actions)
end end

View file

@ -123,7 +123,7 @@ FactoryGirl.define do
factory :event do factory :event do
factory :closed_issue_event do factory :closed_issue_event do
project project
action { Event::Closed } action { Event::CLOSED }
target factory: :closed_issue target factory: :closed_issue
author factory: :user author factory: :user
end end

View file

@ -52,7 +52,7 @@ describe Event do
@event = Event.create( @event = Event.create(
project: project, project: project,
action: Event::Pushed, action: Event::PUSHED,
data: data, data: data,
author_id: @user.id author_id: @user.id
) )

View file

@ -19,7 +19,7 @@ describe Project, "Hooks" do
event.should_not be_nil event.should_not be_nil
event.project.should == project event.project.should == project
event.action.should == Event::Pushed event.action.should == Event::PUSHED
event.data.should == data event.data.should == data
end end
end end

View file

@ -17,7 +17,7 @@ describe ActivityObserver do
end end
it_should_be_valid_event it_should_be_valid_event
it { @event.action.should == Event::Created } it { @event.action.should == Event::CREATED }
it { @event.target.should == @merge_request } it { @event.target.should == @merge_request }
end end
@ -30,7 +30,7 @@ describe ActivityObserver do
end end
it_should_be_valid_event it_should_be_valid_event
it { @event.action.should == Event::Created } it { @event.action.should == Event::CREATED }
it { @event.target.should == @issue } it { @event.target.should == @issue }
end end
@ -44,7 +44,7 @@ describe ActivityObserver do
end end
it_should_be_valid_event it_should_be_valid_event
it { @event.action.should == Event::Commented } it { @event.action.should == Event::COMMENTED }
it { @event.target.should == @note } it { @event.target.should == @note }
end end
end end