Commit c8b92a4b authored by Sebastian Ziebell's avatar Sebastian Ziebell

Merge branch 'master' into fixes/api

parents c305eb31 ed3f4408
......@@ -9,8 +9,12 @@ class Admin::UsersController < Admin::ApplicationController
end
def show
@projects = Project.scoped
@projects = @projects.without_user(admin_user) if admin_user.authorized_projects.present?
# Projects user can be added to
@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
def team_update
......
......@@ -20,15 +20,15 @@ class Event < ActiveRecord::Base
default_scope where("author_id IS NOT NULL")
Created = 1
Updated = 2
Closed = 3
Reopened = 4
Pushed = 5
Commented = 6
Merged = 7
Joined = 8 # User joined project
Left = 9 # User left project
CREATED = 1
UPDATED = 2
CLOSED = 3
REOPENED = 4
PUSHED = 5
COMMENTED = 6
MERGED = 7
JOINED = 8 # User joined project
LEFT = 9 # User left project
delegate :name, :email, to: :author, prefix: true, allow_nil: true
delegate :title, to: :issue, prefix: true, allow_nil: true
......@@ -43,15 +43,15 @@ class Event < ActiveRecord::Base
# Scopes
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 }
class << self
def determine_action(record)
if [Issue, MergeRequest].include? record.class
Event::Created
Event::CREATED
elsif record.kind_of? Note
Event::Commented
Event::COMMENTED
end
end
end
......@@ -79,19 +79,19 @@ class Event < ActiveRecord::Base
end
def push?
action == self.class::Pushed && valid_push?
action == self.class::PUSHED && valid_push?
end
def merged?
action == self.class::Merged
action == self.class::MERGED
end
def closed?
action == self.class::Closed
action == self.class::CLOSED
end
def reopened?
action == self.class::Reopened
action == self.class::REOPENED
end
def milestone?
......@@ -111,11 +111,11 @@ class Event < ActiveRecord::Base
end
def joined?
action == Joined
action == JOINED
end
def left?
action == Left
action == LEFT
end
def membership_changed?
......
......@@ -133,11 +133,11 @@ class MergeRequest < ActiveRecord::Base
end
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
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
def commits
......@@ -184,7 +184,7 @@ class MergeRequest < ActiveRecord::Base
self.mark_as_merged!
Event.create(
project: self.project,
action: Event::Merged,
action: Event::MERGED,
target_id: self.id,
target_type: "MergeRequest",
author_id: user_id
......
......@@ -103,7 +103,7 @@ class Project < ActiveRecord::Base
end
def with_push
includes(:events).where('events.action = ?', Event::Pushed)
includes(:events).where('events.action = ?', Event::PUSHED)
end
def active
......@@ -336,7 +336,7 @@ class Project < ActiveRecord::Base
def observe_push(data)
Event.create(
project: self,
action: Event::Pushed,
action: Event::PUSHED,
data: data,
author_id: data[:user_id]
)
......
......@@ -138,7 +138,7 @@ class User < ActiveRecord::Base
end
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
......@@ -313,4 +313,8 @@ class User < ActiveRecord::Base
UserTeam.where(id: ids)
end
end
def owned_teams
UserTeam.where(owner_id: self.id)
end
end
......@@ -26,7 +26,7 @@ class ActivityObserver < ActiveRecord::Observer
project: record.project,
target_id: record.id,
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
)
end
......
......@@ -7,7 +7,7 @@ class UsersProjectObserver < ActiveRecord::Observer
def after_create(users_project)
Event.create(
project_id: users_project.project.id,
action: Event::Joined,
action: Event::JOINED,
author_id: users_project.user.id
)
end
......@@ -15,7 +15,7 @@ class UsersProjectObserver < ActiveRecord::Observer
def after_destroy(users_project)
Event.create(
project_id: users_project.project.id,
action: Event::Left,
action: Event::LEFT,
author_id: users_project.user.id
)
end
......
......@@ -3,56 +3,60 @@
= link_to 'New User', new_admin_user_path, class: "btn btn-small pull-right"
%br
= form_tag admin_users_path, method: :get, class: 'form-inline' do
= text_field_tag :name, params[:name], class: "xlarge"
= submit_tag "Search", class: "btn submit btn-primary"
%ul.nav.nav-tabs
%li{class: "#{'active' unless params[:filter]}"}
= link_to admin_users_path do
Active
%span.badge= User.active.count
%li{class: "#{'active' if params[:filter] == "admins"}"}
= link_to admin_users_path(filter: "admins") do
Admins
%span.badge= User.admins.count
%li{class: "#{'active' if params[:filter] == "blocked"}"}
= link_to admin_users_path(filter: "blocked") do
Blocked
%span.badge= User.blocked.count
%li{class: "#{'active' if params[:filter] == "wop"}"}
= link_to admin_users_path(filter: "wop") do
Without projects
%span.badge= User.without_projects.count
.row
.span3
.admin-filter
= form_tag admin_users_path, method: :get, class: 'form-inline' do
= search_field_tag :name, params[:name], placeholder: 'Name, email or username', class: 'search-text-input span2'
= button_tag type: 'submit', class: 'btn' do
%i.icon-search
%ul.nav.nav-pills.nav-stacked
%li{class: "#{'active' unless params[:filter]}"}
= link_to admin_users_path do
Active
%small.pull-right= User.active.count
%li{class: "#{'active' if params[:filter] == "admins"}"}
= link_to admin_users_path(filter: "admins") do
Admins
%small.pull-right= User.admins.count
%li{class: "#{'active' if params[:filter] == "blocked"}"}
= link_to admin_users_path(filter: "blocked") do
Blocked
%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
%thead
%tr
%th Admin
%th
Name
%i.icon-sort-down
%th Username
%th Email
%th Projects
%th Edit
%th.cred Danger Zone!
- @admin_users.each do |user|
%tr
%td= check_box_tag "admin", 1, user.admin, disabled: :disabled
%td= link_to user.name, [:admin, user]
%td= user.username
%td= user.email
%td= user.users_projects.count
%td= link_to 'Edit', edit_admin_user_path(user), id: "edit_#{dom_id(user)}", class: "btn btn-small"
%td.bgred
- if user == current_user
%span.cred It's you!
- else
- if user.blocked
= link_to 'Unblock', unblock_admin_user_path(user), method: :put, class: "btn btn-small success"
- else
= link_to 'Block', block_admin_user_path(user), confirm: 'USER WILL BE BLOCKED! Are you sure?', method: :put, class: "btn btn-small btn-remove"
= 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: "admin"
.span9
.ui-box
%h5.title
Users (#{@admin_users.total_count})
%ul.well-list
- @admin_users.each do |user|
%li
- if user.blocked?
%i.icon-lock.cred
- else
%i.icon-user.cgreen
= link_to user.name, [:admin, user]
- if user.admin?
%strong.cred (Admin)
- if user == current_user
%span.cred It's you!
.pull-right
%span.light
%i.icon-envelope
= mail_to user.email, user.email, class: 'light'
&nbsp;
= link_to 'Edit', edit_admin_user_path(user), id: "edit_#{dom_id(user)}", class: "btn btn-small"
- unless user == current_user
- if user.blocked
= link_to 'Unblock', unblock_admin_user_path(user), method: :put, class: "btn btn-small success"
- else
= link_to 'Block', block_admin_user_path(user), confirm: 'USER WILL BE BLOCKED! Are you sure?', method: :put, class: "btn btn-small btn-remove"
= link_to 'Destroy', [:admin, user], confirm: "USER #{user.name} WILL BE REMOVED! Are you sure?", method: :delete, class: "btn btn-small btn-remove"
%li.bottom
= paginate @admin_users, theme: "gitlab"
%h3.page_title
User: #{@admin_user.name}
- if @admin_user.blocked
%small Blocked
- if @admin_user.admin
%small Administrator
= link_to edit_admin_user_path(@admin_user), class: "btn pull-right" do
%i.icon-edit
Edit
%br
%table.zebra-striped
%thead
%tr
%th Profile
%th
%tr
%td
%b
Email:
%td
= @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
.row
.span6
%h3.page_title
= image_tag gravatar_icon(@admin_user.email, 90), class: "avatar s90"
= @admin_user.name
- if @admin_user.blocked
%span.cred (Blocked)
- if @admin_user.admin
%span.cred (Admin)
.pull-right
= link_to edit_admin_user_path(@admin_user), class: "btn pull-right" do
%i.icon-edit
Edit
%br
%small @#{@admin_user.username}
%br
%small member since #{@admin_user.created_at.stamp("Nov 12, 2031")}
.clearfix
%hr
%h5
Add User to Projects
%small
Read more about project permissions
%strong= link_to "here", help_permissions_path, class: "vlink"
%br
- if @admin_user.groups.present?
%h5 Owner of groups:
%br
%table.zebra-striped
%thead
%tr
%th Name
%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"
- @admin_user.groups.each do |group|
%tr
%td= link_to group.name, admin_group_path(group)
.form-actions
= submit_tag 'Add', class: "btn btn-create"
.pull-right
%br
- if @admin_user.owned_groups.present?
.ui-box
%h5.title Owned groups:
%ul.well-list
- @admin_user.groups.each do |group|
%li
%strong= link_to group.name, admin_group_path(group)
- if @admin_user.authorized_projects.present?
%h5 Authorized Projects:
%br
- if @admin_user.owned_teams.present?
.ui-box
%h5.title Owned teams:
%ul.well-list
- @admin_user.owned_teams.each do |team|
%li
%strong= link_to team.name, admin_team_path(team)
%table.zebra-striped
%thead
%tr
%th Name
%th Project Access
%th
%th
- @admin_user.tm_in_authorized_projects.each do |tm|
- project = tm.project
%tr
%td= link_to project.name_with_namespace, admin_project_path(project)
%td= tm.project_access_human
%td= link_to 'Edit Access', edit_admin_project_member_path(project, tm.user), class: "btn btn-small"
%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"
.span6
= render 'users/profile', user: @admin_user
.ui-box
%h5.title Projects (#{@projects.count})
%ul.well-list
- @projects.each do |project|
%li
= link_to admin_project_path(project), class: dom_class(project) do
- if project.namespace
= project.namespace.human_name
\/
%strong.well-title
= truncate(project.name, length: 45)
%span.pull-right.light
- if project.owner == @admin_user
%i.icon-wrench
- tm = project.team.get_tm(@admin_user.id)
- if tm
= 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
......@@ -26,7 +26,7 @@
= f.label :import_url do
%span Import existing repo
.input
= f.text_field :import_url, class: 'xlarge'
= f.text_field :import_url, class: 'xlarge', placeholder: 'https://github.com/randx/six.git'
.light
URL should be clonable
......
......@@ -4,20 +4,20 @@
%ul.well-list
%li
%strong Email
%span.pull-right= mail_to @user.email
- unless @user.skype.blank?
%span.pull-right= mail_to user.email
- unless user.skype.blank?
%li
%strong Skype
%span.pull-right= @user.skype
- unless @user.linkedin.blank?
%span.pull-right= user.skype
- unless user.linkedin.blank?
%li
%strong LinkedIn
%span.pull-right= @user.linkedin
- unless @user.twitter.blank?
%span.pull-right= user.linkedin
- unless user.twitter.blank?
%li
%strong Twitter
%span.pull-right= @user.twitter
- unless @user.bio.blank?
%span.pull-right= user.twitter
- unless user.bio.blank?
%li
%strong Bio
%span.pull-right= @user.bio
%span.pull-right= user.bio
......@@ -10,9 +10,9 @@
%strong.well-title
= truncate(project.name, length: 45)
%span.pull-right.light
- if project.owner == @user
- if project.owner == user
%i.icon-wrench
- tm = project.team.get_tm(@user.id)
- tm = project.team.get_tm(user.id)
- if tm
= tm.project_access_human
%p.light
......
......@@ -17,5 +17,5 @@
%h5 Recent events
= render @events
.span4
= render 'profile'
= render 'projects'
= render 'profile', user: @user
= render 'projects', user: @user
......@@ -2,7 +2,7 @@
# note that config/gitlab.yml web path should also be changed
# ENV['RAILS_RELATIVE_URL_ROOT'] = "/gitlab"
app_dir = "/home/git/gitlab/"
app_dir = File.expand_path '../../', __FILE__
worker_processes 2
working_directory app_dir
......
......@@ -33,7 +33,7 @@ class Dashboard < Spinach::FeatureSteps
Event.create(
project: project,
author_id: user.id,
action: Event::Joined
action: Event::JOINED
)
end
......@@ -47,7 +47,7 @@ class Dashboard < Spinach::FeatureSteps
Event.create(
project: project,
author_id: user.id,
action: Event::Left
action: Event::LEFT
)
end
......
......@@ -45,7 +45,7 @@ class EventFilters < Spinach::FeatureSteps
@event = Event.create(
project: @project,
action: Event::Pushed,
action: Event::PUSHED,
data: data,
author_id: @user.id
)
......@@ -56,7 +56,7 @@ class EventFilters < Spinach::FeatureSteps
Event.create(
project: @project,
author_id: user.id,
action: Event::Joined
action: Event::JOINED
)
end
......@@ -64,7 +64,7 @@ class EventFilters < Spinach::FeatureSteps
merge_request = create :merge_request, author: @user, project: @project
Event.create(
project: @project,
action: Event::Merged,
action: Event::MERGED,
target_id: merge_request.id,
target_type: "MergeRequest",
author_id: @user.id
......
......@@ -33,7 +33,7 @@ module SharedProject
@event = Event.create(
project: @project,
action: Event::Pushed,
action: Event::PUSHED,
data: data,
author_id: @user.id
)
......
......@@ -37,15 +37,15 @@ class EventFilter
filter = params.dup
actions = []
actions << Event::Pushed if filter.include? 'push'
actions << Event::Merged if filter.include? 'merged'
actions << Event::PUSHED if filter.include? 'push'
actions << Event::MERGED if filter.include? 'merged'
if filter.include? 'team'
actions << Event::Joined
actions << Event::Left
actions << Event::JOINED
actions << Event::LEFT
end
actions << Event::Commented if filter.include? 'comments'
actions << Event::COMMENTED if filter.include? 'comments'
events = events.where(action: actions)
end
......
......@@ -123,7 +123,7 @@ FactoryGirl.define do
factory :event do
factory :closed_issue_event do
project
action { Event::Closed }
action { Event::CLOSED }
target factory: :closed_issue
author factory: :user
end
......
......@@ -52,7 +52,7 @@ describe Event do
@event = Event.create(
project: project,
action: Event::Pushed,
action: Event::PUSHED,
data: data,
author_id: @user.id
)
......
......@@ -19,7 +19,7 @@ describe Project, "Hooks" do
event.should_not be_nil
event.project.should == project
event.action.should == Event::Pushed
event.action.should == Event::PUSHED
event.data.should == data
end
end
......
......@@ -17,7 +17,7 @@ describe ActivityObserver do
end
it_should_be_valid_event
it { @event.action.should == Event::Created }
it { @event.action.should == Event::CREATED }
it { @event.target.should == @merge_request }
end
......@@ -30,7 +30,7 @@ describe ActivityObserver do
end
it_should_be_valid_event
it { @event.action.should == Event::Created }
it { @event.action.should == Event::CREATED }
it { @event.target.should == @issue }
end
......@@ -44,7 +44,7 @@ describe ActivityObserver do
end
it_should_be_valid_event
it { @event.action.should == Event::Commented }
it { @event.action.should == Event::COMMENTED }
it { @event.target.should == @note }
end
end
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