Huge code clean up

This commit is contained in:
Wedge 2016-03-20 12:24:23 +03:00
parent ad77e882af
commit c33fd582ed
722 changed files with 99 additions and 53110 deletions

25
Gemfile
View File

@ -7,11 +7,6 @@ gem 'pg'
gem 'schema_plus' gem 'schema_plus'
######## ########
gem 'devise' gem 'devise'
gem 'omniauth'
gem 'omniauth-facebook'
gem 'omniauth-google-oauth2'
gem 'omniauth-github'
# gem 'omniauth-openid', '~> 1.0.1'
gem 'pundit' gem 'pundit'
gem 'ancestry' gem 'ancestry'
@ -26,23 +21,9 @@ gem 'highline', '~> 1.6.20'
gem 'state_machines-activerecord' gem 'state_machines-activerecord'
gem 'redis-rails' gem 'redis-rails'
gem 'grack', git: 'git://github.com/rosa-abf/grack.git', require: 'git_http'
gem 'grit', git: 'git://github.com/rosa-abf/grit.git', tag: '2.6.17'
gem 'charlock_holmes' gem 'charlock_holmes'
gem 'github-linguist', '3.1.5', require: 'linguist'
gem 'diff-display'
# Wiki
gem 'gollum-lib', '~> 3.0'
gem 'redcarpet', '~> 3.3'
gem 'creole'
gem 'rdiscount'
# gem 'org-ruby'
gem 'RedCloth'
gem 'wikicloth'
gem 'newrelic_rpm' gem 'newrelic_rpm'
gem 'whenever', require: false
gem 'jbuilder' gem 'jbuilder'
gem 'rails3-jquery-autocomplete' gem 'rails3-jquery-autocomplete'
@ -65,7 +46,6 @@ gem 'ohm-expire', '~> 0.1.3'
gem 'ffi' gem 'ffi'
gem 'attr_encrypted' gem 'attr_encrypted'
gem 'gemoji'
# AngularJS related stuff # AngularJS related stuff
gem 'underscore-rails' gem 'underscore-rails'
@ -85,7 +65,6 @@ gem 'sass-rails'
gem 'coffee-rails' gem 'coffee-rails'
gem 'bootstrap-sass' gem 'bootstrap-sass'
gem 'font-awesome-rails' gem 'font-awesome-rails'
gem 'zeroclipboard-rails'
gem 'compass-rails' gem 'compass-rails'
gem 'uglifier' gem 'uglifier'
@ -93,8 +72,6 @@ gem 'therubyracer', platforms: [:mri, :rbx]
gem 'therubyrhino', platforms: :jruby gem 'therubyrhino', platforms: :jruby
gem 'sitemap_generator' gem 'sitemap_generator'
gem 'codemirror-rails', '~> 4.5'
source 'http://rails-assets.org' do source 'http://rails-assets.org' do
gem 'rails-assets-notifyjs' gem 'rails-assets-notifyjs'
end end
@ -108,7 +85,6 @@ gem 'faraday-http-cache'
group :production do group :production do
gem 'airbrake' gem 'airbrake'
#gem 'bluepill', '~> 0.0.60', require: false
gem 'puma' gem 'puma'
end end
@ -127,7 +103,6 @@ group :development do
gem 'binding_of_caller' gem 'binding_of_caller'
gem 'meta_request' gem 'meta_request'
gem 'localeapp' gem 'localeapp'
gem 'skype'
#gem 'ruby-dbus' if RUBY_PLATFORM =~ /linux/i # Error at deploy #gem 'ruby-dbus' if RUBY_PLATFORM =~ /linux/i # Error at deploy
gem 'rack-mini-profiler', require: false gem 'rack-mini-profiler', require: false
end end

View File

@ -26,27 +26,10 @@ GIT
ransack (~> 1.3) ransack (~> 1.3)
sass-rails sass-rails
GIT
remote: git://github.com/rosa-abf/grack.git
revision: 020be3fef3fb308b9d214252522aa5945bf6584a
specs:
grack (0.2.0)
GIT
remote: git://github.com/rosa-abf/grit.git
revision: b733f0ceefb44b18a9dec8f509ba5493dab59e4e
tag: 2.6.17
specs:
grit (2.5.0)
diff-lcs (~> 1.1)
mime-types (~> 1.15)
posix-spawn (~> 0.3.6)
GEM GEM
remote: http://rubygems.org/ remote: http://rubygems.org/
remote: http://rails-assets.org/ remote: http://rails-assets.org/
specs: specs:
RedCloth (4.2.9)
actionmailer (4.2.2) actionmailer (4.2.2)
actionpack (= 4.2.2) actionpack (= 4.2.2)
actionview (= 4.2.2) actionview (= 4.2.2)
@ -127,7 +110,6 @@ GEM
net-ssh-gateway (>= 1.1.0) net-ssh-gateway (>= 1.1.0)
capistrano_colors (0.5.5) capistrano_colors (0.5.5)
charlock_holmes (0.7.3) charlock_holmes (0.7.3)
chronic (0.10.2)
chunky_png (1.3.4) chunky_png (1.3.4)
climate_control (0.0.3) climate_control (0.0.3)
activesupport (>= 3.0) activesupport (>= 3.0)
@ -161,7 +143,6 @@ GEM
sprockets (< 2.13) sprockets (< 2.13)
crack (0.4.2) crack (0.4.2)
safe_yaml (~> 1.0.0) safe_yaml (~> 1.0.0)
creole (0.5.0)
daemons (1.2.2) daemons (1.2.2)
debug_inspector (0.0.2) debug_inspector (0.0.2)
descendants_tracker (0.0.4) descendants_tracker (0.0.4)
@ -173,16 +154,13 @@ GEM
responders responders
thread_safe (~> 0.1) thread_safe (~> 0.1)
warden (~> 1.2.3) warden (~> 1.2.3)
diff-display (0.0.1)
diff-lcs (1.2.5) diff-lcs (1.2.5)
domain_name (0.5.24) domain_name (0.5.24)
unf (>= 0.0.5, < 1.0.0) unf (>= 0.0.5, < 1.0.0)
encryptor (1.3.0) encryptor (1.3.0)
erubis (2.7.0) erubis (2.7.0)
escape_utils (1.0.1)
eventmachine (1.0.5) eventmachine (1.0.5)
execjs (2.5.2) execjs (2.5.2)
expression_parser (0.9.0)
factory_girl (4.5.0) factory_girl (4.5.0)
activesupport (>= 3.0.0) activesupport (>= 3.0.0)
factory_girl_rails (4.5.0) factory_girl_rails (4.5.0)
@ -200,15 +178,6 @@ GEM
formtastic_i18n (0.4.1) formtastic_i18n (0.4.1)
friendly_id (5.1.0) friendly_id (5.1.0)
activerecord (>= 4.0.0) activerecord (>= 4.0.0)
gemoji (2.1.0)
github-linguist (3.1.5)
charlock_holmes (~> 0.7.3)
escape_utils (~> 1.0.1)
mime-types (~> 1.19)
pygments.rb (~> 0.6.0)
rugged (~> 0.21.0)
github-markup (1.1.2)
posix-spawn (~> 0.3.8)
github_api (0.13.0) github_api (0.13.0)
addressable (~> 2.3) addressable (~> 2.3)
descendants_tracker (~> 0.0.4) descendants_tracker (~> 0.0.4)
@ -217,21 +186,9 @@ GEM
multi_json (>= 1.7.5, < 2.0) multi_json (>= 1.7.5, < 2.0)
nokogiri (~> 1.6.6) nokogiri (~> 1.6.6)
oauth2 oauth2
gitlab-grit (2.6.12)
charlock_holmes (~> 0.6)
diff-lcs (~> 1.1)
mime-types (~> 1.15)
posix-spawn (~> 0.3)
gli (2.13.1) gli (2.13.1)
globalid (0.3.5) globalid (0.3.5)
activesupport (>= 4.1.0) activesupport (>= 4.1.0)
gollum-lib (3.0.0)
github-markup (~> 1.1.0)
gitlab-grit (~> 2.6.5)
nokogiri (~> 1.6.1)
rouge (~> 1.3.3)
sanitize (~> 2.1.0)
stringex (~> 2.5.1)
haml (4.0.6) haml (4.0.6)
tilt tilt
haml-rails (0.9.0) haml-rails (0.9.0)
@ -252,7 +209,6 @@ GEM
haml (~> 4.0.0) haml (~> 4.0.0)
nokogiri (~> 1.6.0) nokogiri (~> 1.6.0)
ruby_parser (~> 3.5) ruby_parser (~> 3.5)
htmlentities (4.3.3)
http-cookie (1.0.2) http-cookie (1.0.2)
domain_name (~> 0.5) domain_name (~> 0.5)
i18n (0.7.0) i18n (0.7.0)
@ -349,20 +305,6 @@ GEM
scrivener (~> 0.0.3) scrivener (~> 0.0.3)
ohm-expire (0.1.3.2) ohm-expire (0.1.3.2)
ohm (>= 0.1.5) ohm (>= 0.1.5)
omniauth (1.2.2)
hashie (>= 1.2, < 4)
rack (~> 1.0)
omniauth-facebook (2.0.1)
omniauth-oauth2 (~> 1.2)
omniauth-github (1.1.2)
omniauth (~> 1.0)
omniauth-oauth2 (~> 1.1)
omniauth-google-oauth2 (0.2.6)
omniauth (> 1.0)
omniauth-oauth2 (~> 1.1)
omniauth-oauth2 (1.3.0)
oauth2 (~> 1.0)
omniauth (~> 1.2)
orm_adapter (0.5.0) orm_adapter (0.5.0)
paperclip (4.3.0) paperclip (4.3.0)
activemodel (>= 3.2.0) activemodel (>= 3.2.0)
@ -373,14 +315,10 @@ GEM
pg (0.18.2) pg (0.18.2)
polyamorous (1.2.0) polyamorous (1.2.0)
activerecord (>= 3.0) activerecord (>= 3.0)
posix-spawn (0.3.11)
puma (2.11.3) puma (2.11.3)
rack (>= 1.1, < 2.0) rack (>= 1.1, < 2.0)
pundit (1.0.1) pundit (1.0.1)
activesupport (>= 3.0.0) activesupport (>= 3.0.0)
pygments.rb (0.6.3)
posix-spawn (~> 0.3.6)
yajl-ruby (~> 1.2.0)
rack (1.6.2) rack (1.6.2)
rack-contrib (1.2.0) rack-contrib (1.2.0)
rack (>= 0.9.1) rack (>= 0.9.1)
@ -433,8 +371,6 @@ GEM
rb-fsevent (0.9.5) rb-fsevent (0.9.5)
rb-inotify (0.9.5) rb-inotify (0.9.5)
ffi (>= 0.5.0) ffi (>= 0.5.0)
rdiscount (2.1.8)
redcarpet (3.3.2)
redis (3.0.7) redis (3.0.7)
redis-actionpack (4.0.0) redis-actionpack (4.0.0)
actionpack (~> 4) actionpack (~> 4)
@ -478,7 +414,6 @@ GEM
http-cookie (>= 1.0.2, < 2.0) http-cookie (>= 1.0.2, < 2.0)
mime-types (>= 1.16, < 3.0) mime-types (>= 1.16, < 3.0)
netrc (~> 0.7) netrc (~> 0.7)
rouge (1.3.4)
rr (1.1.2) rr (1.1.2)
rspec-core (3.2.3) rspec-core (3.2.3)
rspec-support (~> 3.2.0) rspec-support (~> 3.2.0)
@ -504,14 +439,11 @@ GEM
sexp_processor (~> 4.1) sexp_processor (~> 4.1)
rufus-scheduler (2.0.24) rufus-scheduler (2.0.24)
tzinfo (>= 0.3.22) tzinfo (>= 0.3.22)
rugged (0.21.0)
russian (0.6.0) russian (0.6.0)
i18n (>= 0.5.0) i18n (>= 0.5.0)
rvm-capistrano (1.5.6) rvm-capistrano (1.5.6)
capistrano (~> 2.15.4) capistrano (~> 2.15.4)
safe_yaml (1.0.4) safe_yaml (1.0.4)
sanitize (2.1.0)
nokogiri (>= 1.4.4)
sass (3.4.14) sass (3.4.14)
sass-rails (5.0.1) sass-rails (5.0.1)
railties (>= 4.0.0, < 5.0) railties (>= 4.0.0, < 5.0)
@ -593,8 +525,6 @@ GEM
skinny (0.2.3) skinny (0.2.3)
eventmachine (~> 1.0.0) eventmachine (~> 1.0.0)
thin (~> 1.5.0) thin (~> 1.5.0)
skype (0.2.8)
tmp_cache
slim (3.0.6) slim (3.0.6)
temple (~> 0.7.3) temple (~> 0.7.3)
tilt (>= 1.3.3, < 2.1) tilt (>= 1.3.3, < 2.1)
@ -616,7 +546,6 @@ GEM
state_machines-activerecord (0.2.0) state_machines-activerecord (0.2.0)
activerecord (~> 4.1) activerecord (~> 4.1)
state_machines-activemodel (~> 0.1.0) state_machines-activemodel (~> 0.1.0)
stringex (2.5.2)
temple (0.7.5) temple (0.7.5)
test_after_commit (0.4.1) test_after_commit (0.4.1)
activerecord (>= 3.2) activerecord (>= 3.2)
@ -634,9 +563,6 @@ GEM
activesupport activesupport
i18n i18n
timecop (0.7.4) timecop (0.7.4)
tmp_cache (0.1.1)
twitter-text (1.12.0)
unf (~> 0.1.0)
tzinfo (1.2.2) tzinfo (1.2.2)
thread_safe (~> 0.1) thread_safe (~> 0.1)
uglifier (2.7.1) uglifier (2.7.1)
@ -654,25 +580,13 @@ GEM
webmock (1.21.0) webmock (1.21.0)
addressable (>= 2.3.6) addressable (>= 2.3.6)
crack (>= 0.3.2) crack (>= 0.3.2)
whenever (0.9.4)
chronic (>= 0.6.3)
wikicloth (0.8.3)
builder
expression_parser
htmlentities
nokogiri
twitter-text
will_paginate (3.0.7) will_paginate (3.0.7)
ya2yaml (0.31) ya2yaml (0.31)
yajl-ruby (1.2.1)
zeroclipboard-rails (0.1.0)
railties (>= 3.1)
PLATFORMS PLATFORMS
ruby ruby
DEPENDENCIES DEPENDENCIES
RedCloth
activeadmin! activeadmin!
airbrake airbrake
ancestry ancestry
@ -691,20 +605,13 @@ DEPENDENCIES
codemirror-rails (~> 4.5) codemirror-rails (~> 4.5)
coffee-rails coffee-rails
compass-rails compass-rails
creole
devise devise
diff-display
factory_girl_rails factory_girl_rails
faraday-http-cache faraday-http-cache
ffi ffi
font-awesome-rails font-awesome-rails
friendly_id friendly_id
gemoji
github-linguist (= 3.1.5)
github_api github_api
gollum-lib (~> 3.0)
grack!
grit!
haml-rails haml-rails
highline (~> 1.6.20) highline (~> 1.6.20)
hirb hirb
@ -723,10 +630,6 @@ DEPENDENCIES
ngmin-rails ngmin-rails
ohm (~> 1.3.2) ohm (~> 1.3.2)
ohm-expire (~> 0.1.3) ohm-expire (~> 0.1.3)
omniauth
omniauth-facebook
omniauth-github
omniauth-google-oauth2
paperclip paperclip
perform_later! perform_later!
pg pg
@ -740,8 +643,6 @@ DEPENDENCIES
rails3-generators rails3-generators
rails3-jquery-autocomplete rails3-jquery-autocomplete
rake rake
rdiscount
redcarpet (~> 3.3)
redis-rails redis-rails
redis-semaphore redis-semaphore
resque resque
@ -761,7 +662,6 @@ DEPENDENCIES
shoulda-matchers shoulda-matchers
simple_form (= 3.1.0.rc2) simple_form (= 3.1.0.rc2)
sitemap_generator sitemap_generator
skype
slim slim
soundmanager-rails soundmanager-rails
sprockets sprockets
@ -774,10 +674,7 @@ DEPENDENCIES
uglifier uglifier
underscore-rails underscore-rails
webmock webmock
whenever
wikicloth
will_paginate will_paginate
zeroclipboard-rails
BUNDLED WITH BUNDLED WITH
1.11.2 1.11.2

View File

@ -5,6 +5,5 @@ require File.expand_path('../config/application', __FILE__)
require 'rake' require 'rake'
require 'resque/tasks' require 'resque/tasks'
require 'resque_scheduler/tasks' require 'resque_scheduler/tasks'
load 'tasks/emoji.rake'
Rosa::Application.load_tasks Rosa::Application.load_tasks

View File

@ -1,72 +0,0 @@
ActiveAdmin.register BuildScript do
permit_params :project_name, :treeish, :commit, :sha1, :status
menu priority: 4
filter :project_name, as: :string
controller do
def scoped_collection
BuildScript.includes(:project)
end
end
index do
column(:project) do |bs|
link_to(bs.project.name_with_owner, project_path(bs.project))
end
column :treeish
column :commit
column :sha1
column(:status, sortable: :status) do |bs|
status_tag(bs.status, build_script_status_color(bs))
end
column :updated_at
actions
end
show do
attributes_table do
row :id
row(:project) do |bs|
link_to(bs.project.name_with_owner, project_path(bs.project))
end
row :treeish
row :commit
row :sha1
row(:status, sortable: :status) do |bs|
status_tag(bs.status, build_script_status_color(bs))
end
row :created_at
row :updated_at
end
end
form do |f|
f.inputs do
f.input :project_name
f.input :treeish
f.input :commit
f.input :sha1
f.input :status, as: :select, include_blank: false, collection: BuildScript::STATUSES
end
f.actions
end
sidebar 'Actions', only: :show do
%w(enable disable update_archive).each do |state|
div do
link_to state.humanize, force_admin_build_script_path(resource, state: state), method: :patch
end if resource.send("can_#{state}?")
end
end
member_action :force, method: :patch do
resource.send(params[:state])
flash[:notice] = 'Updated successfully'
redirect_to admin_build_script_path(resource)
end
end

View File

@ -1,92 +0,0 @@
ActiveAdmin.register NodeInstruction do
permit_params :instruction, :user_id, :output, :status
menu priority: 3
controller do
def scoped_collection
NodeInstruction.includes(:user)
end
end
filter :user_uname, as: :string
filter :status, as: :select, collection: NodeInstruction::STATUSES
filter :updated_at
index do
column :id
column :user
column(:status, sortable: :status) do |ni|
status_tag(ni.status, status_color(ni))
end
column :updated_at
actions
end
form do |f|
f.inputs do
f.input :user, as: :select, include_blank: false, collection: User.system.map { |u| [u.uname, u.id] }
f.input :status, as: :select, include_blank: false, collection: NodeInstruction::STATUSES
f.input :instruction, as: :text
end
f.actions
end
show do
attributes_table do
row :id
row :user
row(:status, sortable: :status) do |ni|
status_tag(ni.status, status_color(ni))
end
row :created_at
row :updated_at
row :instruction
row(:output) do |ni|
ni.output.to_s.lines.join('<br/>').html_safe
end
end
end
sidebar 'Actions', only: :show do
%w(disable ready restart restart_failed).each do |state|
div do
link_to state.humanize, force_admin_node_instruction_path(resource, state: state), method: :patch
end if resource.send("can_#{state}?")
end
end
sidebar 'Actions', only: :index do
locked = NodeInstruction.all_locked?
span(class: "status_tag #{locked ? 'red' : 'green'}") do
if locked
link_to 'Unlock instructions', unlock_all_admin_node_instructions_path, method: :post
else
link_to 'Lock instructions', lock_all_admin_node_instructions_path, method: :post
end
end
end
collection_action :lock_all, method: :post do
NodeInstruction.lock_all
flash[:notice] = 'Locked successfully'
redirect_to admin_node_instructions_path
end
collection_action :unlock_all, method: :post do
NodeInstruction.unlock_all
flash[:notice] = 'Unlocked successfully'
redirect_to admin_node_instructions_path
end
member_action :force, method: :patch do
resource.send(params[:state])
flash[:notice] = 'Updated successfully'
redirect_to admin_node_instruction_path(resource)
end
end

View File

@ -1,20 +0,0 @@
ActiveAdmin.register RegisterRequest do
menu parent: 'Misc'
index do
column :id
column :name
column('User') do |request|
user = User.find_by(email: request.email) if request.approved
link_to(user.uname, admin_user_path(user)) if user
end
column :interest
column :more
column :created_at
actions
end
end

View File

@ -1,3 +0,0 @@
def build_script_status_color(bs)
bs.active? ? :green : :red
end

View File

@ -1,12 +0,0 @@
def status_color(ni)
case
when ni.ready?
:green
when ni.disabled?
nil
when ni.failed?
:red
else
:orange
end
end

View File

@ -1,16 +1,10 @@
RosaABF.controller 'BuildListController', ['$scope', '$http', '$timeout', 'SoundNotificationsHelper', ($scope, $http, $timeout, SoundNotificationsHelper) -> RosaABF.controller 'BuildListController', ['$scope', '$http', '$timeout', 'SoundNotificationsHelper', ($scope, $http, $timeout, SoundNotificationsHelper) ->
$scope.advisoriable_types = null
$scope.id = $('#build_list_id').val() $scope.id = $('#build_list_id').val()
$scope.build_list = null $scope.build_list = null
$scope.subject = {} # See: shared/build_results $scope.subject = {} # See: shared/build_results
$scope.attach_advisory = 'no'
# Statuses: advisory_not_found, server_error, continue_input # Statuses: advisory_not_found, server_error, continue_input
$scope.search_status = 'continue_input'
$scope.term = '' $scope.term = ''
$scope.advisory = null
$scope.update_type_errors = null
$scope.getBuildList = -> $scope.getBuildList = ->
$http.get Routes.build_list_path($scope.id, {format: 'json'}) $http.get Routes.build_list_path($scope.id, {format: 'json'})
@ -21,7 +15,6 @@ RosaABF.controller 'BuildListController', ['$scope', '$http', '$timeout', 'Sound
$scope.build_list = $scope.subject = build_list $scope.build_list = $scope.subject = build_list
$scope.canRefresh = -> $scope.canRefresh = ->
return false if $scope.attach_advisory != 'no'
return true unless $scope.build_list return true unless $scope.build_list
show_dependent_projects = _.find $scope.build_list.packages, (p) -> show_dependent_projects = _.find $scope.build_list.packages, (p) ->
@ -42,14 +35,6 @@ RosaABF.controller 'BuildListController', ['$scope', '$http', '$timeout', 'Sound
else else
false false
# if (!(
# $scope.build_list.status == <%=BuildList::BUILD_PUBLISHED%> ||
# $scope.build_list.status == <%=BuildList::REJECTED_PUBLISH%> ||
# $scope.build_list.status == <%=BuildList::FAILED_PUBLISH%> ||
# $scope.build_list.status == <%=BuildList::BUILD_CANCELED%> ||
# $scope.build_list.status == <%=BuildList::BUILD_ERROR%>
# )) { return true; }
$scope.cancelRefresh = null $scope.cancelRefresh = null
$scope.refresh = -> $scope.refresh = ->
if $scope.canRefresh() if $scope.canRefresh()
@ -57,51 +42,4 @@ RosaABF.controller 'BuildListController', ['$scope', '$http', '$timeout', 'Sound
$scope.cancelRefresh = $timeout($scope.refresh, 10000) $scope.cancelRefresh = $timeout($scope.refresh, 10000)
$scope.refresh() $scope.refresh()
$scope.search = ->
params =
query: $scope.term
bl_type: $scope.build_list.update_type
format: 'json'
$http.get Routes.search_advisories_path(params)
.success (results) ->
$scope.search_status = 'continue_input'
$scope.advisory = results
$('#attach_advisory').find('.advisory_id').val($scope.advisory.advisory_id)
.error (data, status, headers, config) ->
$scope.search_status = status == 404 ? 'advisory_not_found' : 'server_error'
$scope.advisory = null
$('#attach_advisory').find('.advisory_id').val('')
$scope.updateTypeChanged = ->
if _.contains($scope.advisoriable_types, $scope.build_list.update_type)
if $scope.advisory || $scope.term.length > 0
$scope.search()
else
$scope.attach_advisory = 'no'
$scope.updateUpdateType()
$scope.attachAdvisoryChanged = ->
unless _.contains($scope.advisoriable_types, $scope.build_list.update_type)
$scope.build_list.update_type = $scope.advisoriable_types[0]
$scope.updateUpdateType()
$('#build_list_update_type .nonadvisoriable').attr('disabled', ($scope.attach_advisory != 'no'))
true
$scope.updateUpdateType = ->
params =
update_type: $scope.build_list.update_type
format: 'json'
$http.put Routes.update_type_build_list_path($scope.id), params
.success (results) ->
$scope.update_type_errors = null
$timeout ->
$('#build_list_update_type').effect('highlight', {}, 1000)
, 100
.error (data, status, headers, config) ->
$scope.update_type_errors = data.message
] ]

View File

@ -1,45 +0,0 @@
commentService = ($http) ->
getPath = (kind, project, commentable, id) ->
if commentable.kind is 'issue' or commentable.kind is 'pull'
if kind is 'remove' or kind is 'update'
return Routes.project_issue_comment_path(project, commentable.id, id)
else if kind is 'add'
return Routes.project_issue_comments_path(project, commentable.id)
else if commentable.kind is 'commit'
if kind is 'remove' or kind is 'update'
return Routes.project_commit_comment_path(project, commentable.id, id)
else if kind is 'add'
return Routes.project_commit_comments_path(project, commentable.id)
{
add: (project, commentable, body) ->
path = getPath('add', project, commentable)
params = { comment: { body: body }}
$http.post(path, params)
addInline: (project, commentable, body, params) ->
path = getPath('add', project, commentable)
params = {
comment: { body: body },
in_reply: params.in_reply,
line: params.line,
path: params.path
}
$http.post(path, params)
update: (project, commentable, id) ->
path = getPath('update', project, commentable, id)
params = { comment: { body: $('#comment-'+id+'-body').val() }}
$http.patch(path, params)
remove: (project, commentable, id) ->
path = getPath('remove', project, commentable, id)
$http.delete(path)
}
angular
.module("RosaABF")
.factory "Comment", commentService
commentService.$inject = ['$http']

View File

@ -1,218 +0,0 @@
CommentsController = (Comment, Preview, confirmMessage, $scope, compileHTML, $rootScope) ->
inlineCommentParams = {}
list = null
new_inline_form = $('.new_inline_comment_form.hidden')
setInlineCommentParams = (params) ->
inlineCommentParams = params
findInlineComments = ($event, params) ->
if params.in_reply
$('#comment'+params.in_reply).parents('tr').find('td .line-comment:last')
else
$($event.target).parents('tr')
insertCommentForm = (line_comments, form) ->
if inlineCommentParams.in_reply
new_form = compileHTML.run($scope, form)
line_comments.append(new_form)
else
if line_comments.hasClass('line-comments')
new_form = form
new_form = compileHTML.run($scope, new_form)
line_comments.find('td.line-comments:last').append(new_form)
else
new_form = "<tr class='line-comments'><td class='line_numbers' colspan='2'></td>" +
"<td>" + form + "</td></tr>"
new_form = compileHTML.run($scope, new_form)
line_comments.after(new_form)
true
vm = this
vm.isDisabledNewInlineCommentButton = ->
vm.processing || vm.new_inline_body is '' || !vm.new_inline_body
vm.isDisabledNewCommentButton = ->
vm.processing || vm.new_body is '' || !vm.new_body
vm.previewBody = (id) ->
if id is 'new-comment'
body = vm.new_body
else if id is 'new-inline-comment'
body = vm.new_inline_body
else
body = $('#'+id+'-body').val()
if body is '' or !body
vm.preview_body = ''
return false
if body is Preview.old_text
return false
return false if vm.processing
vm.processing = true
Preview.old_text = ''
promise = Preview.get_preview(vm.project, body)
promise.success( (response) ->
vm.preview_body = response.html
Preview.old_text = body
).error( (response) ->
vm.preview_body = 'Error :('
)
vm.processing = false
false
vm.toggleEditForm = (id)->
$('.open-comment').addClass('hidden')
form = $('.open-comment.comment-'+id)
if form.length is 1
form.removeClass('hidden')
########## Maybe Chrome 43 bug? don't show text in the textarea :(
textarea = form.find('.form-group textarea')
tmp = textarea.val()
textarea.val('')
textarea.val(tmp)
##########
true
else
false
vm.closeEditForm = (id)->
$('.open-comment.comment-'+id).addClass('hidden')
false
vm.add = ($event)->
$event.preventDefault()
$event.stopPropagation()
vm.processing = true
Comment.add(vm.project, vm.commentable, vm.new_body)
.success (data) ->
element = compileHTML.run($scope, data.html)
list.append(element)
vm.new_body = ''
location.hash = "#comment" + data.id;
vm.processing = false
$.notify(data.message, 'success')
.error (data) ->
$.notify(data.message, 'error')
vm.processing = false
false
vm.remove = (id) ->
return false unless confirmMessage.show()
vm.processing = true
Comment.remove(vm.project, vm.commentable, id)
.success (data)->
parent = $('#comment'+id+',#diff-comment'+id).parents('tr.line-comments')
if parent.find('.line-comment').length is 1
# there is only one line comment, remove all line
parent.remove()
else
$('#comment'+id+',#diff-comment'+id+',#update-comment'+id).remove()
$.notify(data.message, 'success')
vm.processing = false
.error (data)->
$.notify(data.message, 'error')
vm.processing = false
false
vm.update = (id) ->
vm.processing = true
Comment.update(vm.project, vm.commentable, id)
.success (data) ->
form = $('#comment'+id+ ' .md_and_cm.cm-s-default').html(data.body)
$.notify(data.message, 'success')
vm.processing = false
form = $('.open-comment.comment-'+id)
if form.length is 1
form.addClass('hidden')
return true
else
return false
.error (data) ->
$.notify(data.message, 'error')
vm.processing = false
vm.showInlineForm = ($event, params = {}) ->
line_comments = findInlineComments($event, params)
return false if line_comments.count is 0
vm.new_inline_body = null
vm.hideInlineForm()
setInlineCommentParams(params)
insertCommentForm(line_comments, new_inline_form.html())
tmp = line_comments.find('#new_inline_comment')
$('table.table #new_inline_comment').addClass('cloned')
true
vm.hideInlineForm = (is_new_comment = false)->
parent = $('#new_inline_comment.cloned').parents('tr.line-comments')
if !is_new_comment and parent.find('.line-comment').length is 1
# there is only one line comment, remove all line
parent.remove()
else
$('#new_inline_comment.cloned').remove()
inlineCommentParams = {}
false
vm.hideInlineCommentButton = (params = {}) ->
_.isEqual(inlineCommentParams, params)
vm.addInline = ($event) ->
line_comments = findInlineComments($event, inlineCommentParams)
return false if line_comments.count is 0
vm.processing = true
promise = Comment.addInline(vm.project, vm.commentable, vm.new_inline_body, inlineCommentParams)
promise.then (response) ->
vm.hideInlineForm(true)
insertCommentForm(line_comments, response.data.html)
vm.new_inline_body = ''
location.hash = "#comment" + response.data.id;
vm.processing = false
false
$rootScope.$on "compile_html", (event, args) ->
html = compileHTML.run($scope, args.html)
args.element.html(html)
true
vm.init = (project, commentable = {}) ->
vm.project = project
vm.commentable = commentable
vm.processing = false
vm.k = 10
if commentable.kind is 'issue' or commentable.kind is 'commit'
list = $('#comments_list')
else if commentable.kind is 'pull'
list = $('#pull-activity')
else
list = $()
true
true
angular
.module("RosaABF")
.controller "CommentsController", CommentsController
CommentsController.$inject = [
'Comment'
'Preview'
'confirmMessage'
'$scope'
'compileHTML'
'$rootScope'
]

View File

@ -1,9 +1,5 @@
ActivityController = ($scope, $http, $timeout, $q, $filter, $location, ActivityFilter) -> ActivityController = ($scope, $http, $timeout, $q, $filter, $location, ActivityFilter) ->
getIssuesTab = (kind)->
return vm.tracker_tab if kind is 'tracker'
return vm.pull_requests_tab if kind is 'pull_requests'
calculateChangeDate = (feed)-> calculateChangeDate = (feed)->
prev_date = null prev_date = null
_.each(feed, (event)-> _.each(feed, (event)->
@ -27,12 +23,8 @@ ActivityController = ($scope, $http, $timeout, $q, $filter, $location, ActivityF
vm.processing = false vm.processing = false
vm.activity_tab = vm.activity_tab =
filter: 'all' filter: 'build'
all: {}
code: {}
tracker: {}
build: {} build: {}
wiki: {}
owner_filter: null owner_filter: null
project_name_filter: null project_name_filter: null
owner_uname_filter_tmp: null owner_uname_filter_tmp: null
@ -41,29 +33,6 @@ ActivityController = ($scope, $http, $timeout, $q, $filter, $location, ActivityF
vm.own_activity_tab = $.extend({}, vm.activity_tab) vm.own_activity_tab = $.extend({}, vm.activity_tab)
vm.current_activity_tab = vm.activity_tab vm.current_activity_tab = vm.activity_tab
vm.tracker_tab =
content: []
filter:
all: true
assigned: false
created: false
name: 'all'
all_count: 0
assigned_count: 0
created_count: 0
closed_count: 0
sort:
sort: 'updated'
direction: 'desc'
updated_class: 'fa-chevron-up'
status: 'open'
pagination:
page: 1
total_count: 0
vm.pull_requests_tab = $.extend({}, vm.tracker_tab)
vm.init = (active_tab)-> vm.init = (active_tab)->
switch active_tab switch active_tab
when 'activity' when 'activity'
@ -72,10 +41,6 @@ ActivityController = ($scope, $http, $timeout, $q, $filter, $location, ActivityF
when 'own_activity' when 'own_activity'
vm.own_activity_tab.active = true vm.own_activity_tab.active = true
vm.current_activity_tab = vm.own_activity_tab vm.current_activity_tab = vm.own_activity_tab
when 'issues'
vm.tracker_tab.active = true
when active_tab is 'pull_requests'
vm.pull_requests_tab.active = true
true true
vm.getContent = (tab)-> vm.getContent = (tab)->
@ -83,8 +48,6 @@ ActivityController = ($scope, $http, $timeout, $q, $filter, $location, ActivityF
when 'activity' when 'activity'
vm.activity_tab.active = true vm.activity_tab.active = true
vm.own_activity_tab.active = false vm.own_activity_tab.active = false
vm.tracker_tab.active = false
vm.pull_requests_tab.active = false
vm.current_activity_tab = vm.activity_tab vm.current_activity_tab = vm.activity_tab
vm.getActivityContent() vm.getActivityContent()
if $location.path() isnt '/' if $location.path() isnt '/'
@ -93,37 +56,14 @@ ActivityController = ($scope, $http, $timeout, $q, $filter, $location, ActivityF
when 'own_activity' when 'own_activity'
vm.activity_tab.active = false vm.activity_tab.active = false
vm.own_activity_tab.active = true vm.own_activity_tab.active = true
vm.tracker_tab.active = false
vm.pull_requests_tab.active = false
vm.current_activity_tab = vm.own_activity_tab vm.current_activity_tab = vm.own_activity_tab
vm.getActivityContent() vm.getActivityContent()
if $location.path() isnt '/own_activity' if $location.path() isnt '/own_activity'
$location.path('/own_activity').replace() $location.path('/own_activity').replace()
when 'tracker'
vm.activity_tab.active = false
vm.own_activity_tab.active = false
vm.tracker_tab.active = true
vm.pull_requests_tab.active = false
vm.getIssuesContent()
if $location.path() isnt '/issues'
$location.path('/issues').replace()
when 'pull_requests'
vm.activity_tab.active = false
vm.own_activity_tab.active = false
vm.tracker_tab.active = false
vm.pull_requests_tab.active = true
vm.getIssuesContent()
if $location.path() isnt '/pull_requests'
$location.path('/pull_requests').replace()
vm.getTimeLinefaClass = (content)-> vm.getTimeLinefaClass = (content)->
template = switch content.kind template = switch content.kind
when 'build_list_notification' then 'btn-success fa-gear' when 'build_list_notification' then 'btn-success fa-gear'
when 'new_comment_notification', 'new_comment_commit_notification' then 'btn-warning fa-comment'
when 'git_new_push_notification' then 'bg-primary fa-sign-in'
when 'new_issue_notification' then 'btn-warning fa-check-square-o'
else 'btn-warning fa-question' else 'btn-warning fa-question'
template template
@ -142,15 +82,9 @@ ActivityController = ($scope, $http, $timeout, $q, $filter, $location, ActivityF
cur_tab.feed.push.apply(cur_tab.feed, res.data.feed) cur_tab.feed.push.apply(cur_tab.feed, res.data.feed)
cur_tab.next_page_link = res.data.next_page_link cur_tab.next_page_link = res.data.next_page_link
vm.changeActivityFilter = (filter)->
return if vm.current_activity_tab.filter is filter
vm.current_activity_tab.filter = filter
vm.getActivityContent()
vm.getActivityContent = ()-> vm.getActivityContent = ()->
vm.processing = true vm.processing = true
options = options =
filter: vm.current_activity_tab.filter
owner_filter: vm.current_activity_tab.owner_filter owner_filter: vm.current_activity_tab.owner_filter
project_name_filter: vm.current_activity_tab.project_name_filter project_name_filter: vm.current_activity_tab.project_name_filter
format: 'json' format: 'json'
@ -168,67 +102,6 @@ ActivityController = ($scope, $http, $timeout, $q, $filter, $location, ActivityF
vm.processing = false vm.processing = false
true true
vm.setIssuesFilter = (kind, issues_filter)->
filter = getIssuesTab(kind).filter
filter.all = false
filter.assigned = false
filter.created = false
filter[issues_filter] = true
filter.name = issues_filter
vm.getIssuesContent()
vm.getIssuesContent = ()->
if vm.tracker_tab.active
tab = vm.tracker_tab
path = Routes.issues_path(
filter: tab.filter.name
sort: tab.sort.sort
direction: tab.sort.direction
status: tab.status
page: tab.pagination.page
format: 'json')
else if vm.pull_requests_tab.active
tab = vm.pull_requests_tab
path = Routes.pull_requests_path(
filter: tab.filter.name
sort: tab.sort.sort
direction: tab.sort.direction
status: tab.status
page: tab.pagination.page
format: 'json')
$http.get(path).then (res)->
tab.content = res.data.content
tab.filter.all_count = res.data.all_count
tab.filter.assigned_count = res.data.assigned_count
tab.filter.created_count = res.data.created_count
tab.filter.closed_count = res.data.closed_count
tab.filter.open_count = res.data.open_count
tab.pagination.page = res.data.page
tab.pagination.total_items = parseInt(res.data.issues_count, 10)
vm.setIssuesSort = (kind, issues_sort)->
tab = getIssuesTab(kind)
if tab.sort.direction is 'desc'
tab.sort = { sort: issues_sort, direction: 'asc' }
sort_class = 'fa-chevron-down'
else
tab.sort = { sort: issues_sort, direction: 'desc' }
sort_class = 'fa-chevron-up'
tab.sort[issues_sort+'_class'] = sort_class
vm.getIssuesContent()
vm.setIssuesStatus = (kind, issues_status)->
tab = getIssuesTab(kind)
tab.status = issues_status
tab.pagination.page = 1
vm.getIssuesContent()
vm.selectPage = (kind, page)->
vm.getIssuesContent()
vm.getOwnersList = (value)-> vm.getOwnersList = (value)->
return [] if value.length < 1 return [] if value.length < 1
ActivityFilter.get_owners(value) ActivityFilter.get_owners(value)

View File

@ -1,25 +0,0 @@
RosaABF.controller('AdvisoryCtrl', ['$scope', '$http', function($scope, $http) {
$scope.total_items = null;
$scope.page = null;
$scope.advisories = null;
$scope.q = null;
$scope.init = function(q) {
$scope.q = q;
};
$scope.getAdvisories = function() {
$http.get(Routes.advisories_path({format: 'json', page: $scope.page, q: $scope.q})).then(function(res) {
$scope.page = res.data.page;
$scope.total_items = res.data.advisories_count;
$scope.advisories = res.data.advisories;
});
};
$scope.goToPage = function(page) {
$scope.page = page;
$scope.getAdvisories();
};
$scope.getAdvisories();
}]);

View File

@ -1,70 +0,0 @@
RosaABF.controller('GitTreeCtrl', ['$scope', '$http', '$location', function($scope, $http, $location) {
$scope.project = null;
$scope.treeish = null;
$scope.root_path = null;
$scope.tree = null;
$scope.breadcrumb = null;
$scope.processing = false;
$scope.init = function(project, treeish, path) {
$scope.project = project;
$scope.treeish = treeish;
$scope.path = path;
};
$scope.refresh = function(more) {
var params = { format: 'json', path: $scope.path };
if(more) {
params.page = $scope.next_page;
$scope.load_more = true;
}
else {
$scope.processing = true;
}
$http.get(Routes.tree_path($scope.project, $scope.treeish, params)).then(function(res) {
$scope.path = res.data.path;
$scope.root_path = res.data.root_path;
$scope.breadcrumb = res.data.breadcrumb;
$scope.next_page = res.data.next_page;
if(more) {
$scope.tree.push.apply($scope.tree, res.data.tree);
$scope.load_more = false;
}
else {
$scope.tree = res.data.tree;
$scope.processing = false;
}
});
};
$scope.$on('$locationChangeSuccess', function(event) {
path = typeof $location.search()['path'] !== 'undefined' ? $location.search()['path'] : false;
if(path) {
$scope.path = path;
}
$scope.refresh();
});
$scope.getTree = function($event, path, more) {
if($scope.processing && $event) {
return $event.preventDefault();
}
more = typeof more !== 'undefined' ? more : false;
if(path && path !== '') { $scope.path = path; }
else { $scope.path = null; }
if(more) {
$scope.refresh(more);
}
else {
$location.search('path', $scope.path);
}
if($event) {
$event.preventDefault();
}
};
}]);

View File

@ -1,80 +0,0 @@
RosaABF.controller('ProjectBranchesController', ['$scope', '$http', 'ApiProject', function($scope, $http, ApiProject) {
$scope.singleton = ApiProject.singleton;
$scope.branches = [];
$scope.current_ref = null;
$scope.project_resource = null;
$scope.init = function(owner_uname, project_name, ref) {
$scope.current_ref = ref;
$scope.project_resource = ApiProject.resource.get(
{owner: owner_uname, project: project_name},
function(results) {
$scope.project = new Project(results.project);
$scope.getBranches();
}
);
}
$scope.getBranches = function() {
$scope.project_resource.$branches(
{owner: $scope.project.owner.uname, project: $scope.project.name},
function(results) {
$scope.branches = [];
_.each(results.refs_list, function(ref){
var result = new ProjectRef(ref);
if (result.ref == $scope.current_ref) {
$scope.branches.unshift(result);
} else {
$scope.branches.push(result);
}
});
$scope.updateBranchesCount();
}
);
}
$scope.updateBranchesCount = function() {
$scope.singleton.project.branches_count = $scope.branches.length;
}
$scope.create = function(branch) {
branch.ui_container = false;
$scope.project_resource.$create_branch(
{
owner: $scope.project.owner.uname,
project: $scope.project.name,
from_ref: branch.ref,
new_ref: branch.new_ref
}, function() { // on success
$scope.getBranches();
}, function () { // on error
$scope.getBranches();
}
);
}
$scope.destroy = function(branch) {
$scope.project_resource.$delete_branch(
{owner: $scope.project.owner.uname, project: $scope.project.name, ref: branch.ref},
function() { // on success
var i = $scope.branches.indexOf(branch);
if(i != -1) { $scope.branches.splice(i, 1); }
$scope.updateBranchesCount();
// Removes branch from "Current branch/tag:" select box
$('#branch_selector option').filter(function() {
return this.value.match('.*\/branches\/' + branch.ref + '$');
}).remove();
}, function () { // on error
$scope.getBranches();
}
);
}
}]);

View File

@ -1,12 +0,0 @@
RosaABF.controller('ProjectRepoBlockController', ['$scope', 'ApiProject', function($scope, ApiProject) {
$scope.clone_url = null;
$scope.singleton = ApiProject.singleton;
$scope.clone_url_protocol = 'ssh';
$scope.is_collapsed_git_help = true;
$scope.init = function(clone_url, branches) {
$scope.clone_url = clone_url;
$scope.singleton.project.branches_count = branches;
}
}]);

View File

@ -1,31 +0,0 @@
RosaABF.controller('ProjectTagsController', ['$scope', '$http', 'ApiProject', function($scope, $http, ApiProject) {
$scope.tags = [];
$scope.project_resource = null;
$scope.init = function(owner_uname, project_name) {
$scope.project_resource = ApiProject.resource.get(
{owner: owner_uname, project: project_name},
function(results) {
$scope.project = new Project(results.project);
$scope.getTags();
}
);
}
$scope.getTags = function() {
$scope.project_resource.$tags(
{owner: $scope.project.owner.uname, project: $scope.project.name},
function(results) {
$scope.tags = [];
_.each(results.refs_list, function(ref){
$scope.tags.push(new ProjectRef(ref));
});
}
);
}
}]);

View File

@ -1,72 +0,0 @@
issueService = ($http) ->
getFormParams = (kind, extra = {}) ->
if kind is 'title_body'
{
issue: {
title: $('#issue_title').val()
body: $('#issue-body').val()
}
}
else if kind is 'labels'
if extra.label.selected is false
is_destroy = '1'
else
is_destroy = '0'
{
issue: {
labelings_attributes:
[{
id: extra.label.labeling_id,
label_id: extra.label.id,
_destroy: is_destroy
}]
}
}
else if kind is 'assignee'
{
issue: {
assignee_id: extra.assignee.id
}
}
else if kind is 'status'
if extra.status.name isnt 'closed'
status = 'closed'
else
status = 'open'
{
issue: {
status: status
}
}
{
getIssues: (project, filter) ->
params = {
kind: filter.kind
filter: filter.name
sort: filter.sort
direction: filter.sort_direction
status: filter.status
labels: filter.labels
page: filter.page
}
path = Routes.project_issues_path(project, params)
$http.get(path)
getAssignees: (project, val) ->
path = Routes.search_collaborators_project_issues_path(project, {search_user: val})
$http.get(path)
update: (project, id, kind, extra = {}) ->
params = getFormParams(kind, extra)
path = Routes.project_issue_path(project, id)
$http.put(path, params)
}
angular
.module("RosaABF")
.factory "Issue", issueService
issueService.$inject = ['$http']

View File

@ -1,162 +0,0 @@
IssueController = (dataservice, $http, Issue, $rootScope, Preview, Label, confirmMessage) ->
updateIssueFromResponse = (response) ->
$('#issue_title_text').html(response.data.title)
$('#issue_body_text').html(response.data.body)
vm.assignee = response.data.assignee
vm.labels = response.data.labels
vm.status = response.data.status
updateStatusCLass()
getLabels = ->
promise = Label.get_labels(vm.project)
promise.then (response) ->
old_labels = vm.labels
vm.labels = response.data
_.each(vm.labels, (l) ->
_.each(old_labels, (ol) ->
if l.id is ol.id
l.selected = ol.selected
l.style = ol.style
l.selected_id = ol.selected_id
)
)
true
updateStatusCLass = ->
if vm.status.name is 'open' or vm.status.name is 'reopen'
vm.issue_status_class = 'btn-primary'
else
vm.issue_status_class = 'btn-danger'
vm = this
vm.previewBody = ->
body = $('#issue-body').val()
if body is '' or !body
vm.preview_body = ''
return false
if body is Preview.old_text
return false
return false if vm.processing
vm.processing = true
promise = Preview.get_preview(vm.project, body)
promise.success( (response) ->
vm.preview_body = response.html
Preview.old_text = body
).error( (response) ->
vm.preview_body = 'Error :('
)
vm.processing = false
false
vm.toggleLabel = (label) ->
if vm.action is 'show'
return false if vm.processing_issue_labels
vm.processing_issue_labels = true
label.selected = !label.selected
if label.selected
label.style = label.default_style
label.selected_id = label.id
else
label.selected_id = null
label.style = {}
if vm.action is 'show'
vm.updateIssue('labels', label: label)
true
vm.getAssignees = (val) ->
vm.processing_issue_assignee = true
promise = Issue.getAssignees(vm.project, val)
promise.then (response) ->
vm.processing_issue_assignee = false
response.data
vm.selectAssignee = (item, model, label) ->
if vm.action is 'show'
return false if vm.processing_issue_assignee
vm.processing_issue_assignee = true
vm.assignee = item
if vm.action is 'show'
vm.updateIssue('assignee', assignee: vm.assignee)
vm.toggle_manage_assignee = false
false
vm.removeAssignee = () ->
return false unless confirmMessage.show()
if vm.action is 'show'
return false if vm.processing_issue_assignee
vm.processing_issue_assignee = true
vm.assignee = {}
if vm.action is 'show'
vm.updateIssue('assignee', assignee: vm.assignee)
vm.toggle_manage_assignee = false
false
vm.updateStatus = ->
return false if vm.action isnt 'show'
return false if vm.processing_issue_status
vm.processing_issue_status = true
vm.updateIssue('status', status: vm.status)
false
vm.updateIssue = (kind, extra = {}) ->
promise = Issue.update(vm.project, vm.serial_id, kind, extra)
promise.then (response) ->
updateIssueFromResponse(response)
vm.edit = false if kind is 'title_body'
if vm.action is 'show' and vm.processing_issue_assignee
vm.processing_issue_assignee = false
if vm.action is 'show' and vm.processing_issue_labels
vm.processing_issue_labels = false
if vm.action is 'show' and vm.processing_issue_status
vm.processing_issue_status = false
false
$rootScope.$on "updateLabels", (event, args) ->
getLabels()
init = (dataservice) ->
vm.project = dataservice.project
vm.serial_id = dataservice.serial_id
vm.labels = dataservice.labels
vm.action = dataservice.action
vm.assignee = dataservice.assignee
vm.status = dataservice.status
vm.toggle_manage_assignee = false
vm.processing = false
vm.processing_issue_labels = false
vm.processing_issue_assignee = false
updateStatusCLass()
init(dataservice)
true
angular
.module("RosaABF")
.controller "IssueController", IssueController
IssueController.$inject = [
'IssueInitializer'
'$http'
'Issue'
'$rootScope'
'Preview'
'Label'
'confirmMessage'
]

View File

@ -1,109 +0,0 @@
IssuesController = (dataservice, $http, $location, Issue, $rootScope) ->
getIssues = () ->
prepareLabelsFilter()
promise = Issue.getIssues(vm.project, vm.filter)
promise.then (response) ->
vm.issues = response.data.issues
vm.filter.page = response.data.page
vm.filter.all_count = response.data.all_count
vm.filter.created_count = response.data.created_count
vm.filter.assigned_count = response.data.assigned_count
vm.filter.opened_count = response.data.opened_count
vm.filter.closed_count = response.data.closed_count
vm.filter.filtered_count = response.data.filtered_count
vm.labels = response.data.labels
true
setSortClass = ->
if vm.filter.sort_direction is 'asc'
sort_class = 'fa-chevron-down'
else
sort_class = 'fa-chevron-up'
if vm.filter.sort is 'updated'
vm.updated_class = sort_class
vm.submitted_class = null
else
vm.updated_class = null
vm.submitted_class = sort_class
prepareLabelsFilter = () ->
vm.filter.labels = []
_.each(vm.labels, (l) ->
vm.filter.labels.push(l.name) if l.selected
)
vm = this
vm.setIssuesFilter = (filter) ->
vm.filter.all = false
vm.filter.assigned = false
vm.filter.created = false
vm.filter[filter] = true
vm.filter.name = filter
getIssues()
vm.setIssuesSort = (issues_sort) ->
if vm.filter.sort_direction is 'desc'
vm.filter.sort_direction = 'asc'
else
vm.filter.sort_direction = 'desc'
vm.filter.sort = issues_sort
setSortClass()
getIssues()
vm.setIssuesStatus = (issues_status) ->
vm.filter.status = issues_status
vm.filter.page = 1
getIssues()
vm.goToPage = (page) ->
getIssues()
vm.toggleLabelFilter = (label) ->
label.selected = !label.selected
if label.selected
label.style = label.default_style
else
label.style = {}
getIssues()
vm.selectLabelFilter = (name) ->
label = null
_.each(vm.labels, (l) ->
l.selected = false
label = l if l.name is name
)
vm.toggleLabelFilter(label) if label
$rootScope.$on "updateLabels", (event, args) ->
getIssues()
init = (dataservice) ->
vm.project = dataservice.project
vm.filter = dataservice.filter
vm.labels = dataservice.labels
vm.filter[dataservice.filter.filter] = true
if vm.filter.status == "closed"
vm.filter.status_closed = true
else
vm.filter.status_open = true
setSortClass()
getIssues()
init(dataservice)
true
angular
.module("RosaABF")
.controller "IssuesController", IssuesController
IssuesController.$inject = ['IssuesInitializer', '$http', '$location', 'Issue', '$rootScope']

View File

@ -1,44 +0,0 @@
labelService = ($http) ->
{
default_colors: [
'0054a6'
'00a651'
'ed1c24'
'e65c00'
'9e005d'
'464646'
'8c6239'
]
add: (project, label) ->
params = {
name: label.name
color: label.color
}
path = Routes.create_label_project_issues_path(project, params)
$http.post(path)
update: (project, label) ->
params = {
name: label.name
color: label.color
}
path = Routes.project_issues_update_label_path(project, label.id, params)
$http.post(path)
remove: (project, label) ->
path = Routes.project_issues_delete_label_path(project, label.id)
$http.post(path)
get_labels: (project) ->
path = Routes.project_labels_path(project)
$http.get(path)
}
angular
.module("RosaABF")
.factory "Label", labelService
labelService.$inject = ['$http']

View File

@ -1,85 +0,0 @@
LabelsController = (dataservice, $http, Label, $rootScope, $scope, confirmMessage) ->
$scope.$watch (->
vm.label.color
), () ->
vm.label.color = vm.label.color.replace(/[^a-f0-9]/gmi,'') if vm.label.color
vm = this
vm.colorClass = (color) ->
if vm.label.color == color
'fa-check-circle'
else
'fa-circle'
vm.colorStyle = (color) ->
color: '#'+color
vm.colorPreviewStyle = () ->
color: '#FFF'
background: '#'+vm.label.color
vm.selectCurrentLabel = (l) ->
vm.label.id = l.id
vm.label.name = l.name
vm.label.color = l.color
vm.is_new_label = false
false
vm.saveLabel = () ->
return false unless vm.label.name && vm.label.color
if vm.is_new_label
promise = Label.add(vm.project, vm.label)
else
promise = Label.update(vm.project, vm.label)
promise.success( (data) ->
vm.labels = data
vm.errors = []
$rootScope.$broadcast('updateLabels')
).error( (data) ->
vm.errors = data
)
false
vm.removeLabel = (l) ->
return false unless confirmMessage.show()
promise = Label.remove(vm.project, l)
promise.success (data) ->
$rootScope.$broadcast('updateLabels')
false
init = (dataservice) ->
vm.project = dataservice.project
vm.labels = dataservice.labels
vm.is_collapsed_manage_block = true
vm.default_colors = Label.default_colors
vm.label = {
id: null
name: null
color: vm.default_colors[0]
}
vm.is_new_label = true
vm.processing = false
init(dataservice)
true
angular
.module("RosaABF")
.controller "LabelsController", LabelsController
LabelsController.$inject = [
'LabelsInitializer'
'$http'
'Label'
'$rootScope'
'$scope'
'confirmMessage'
]

View File

@ -1,30 +0,0 @@
var ProjectRef = function(atts) {
var self = this;
var initialSettings = atts || {};
//initial settings if passed in
for(var setting in initialSettings){
if(initialSettings.hasOwnProperty(setting))
self[setting] = initialSettings[setting];
};
//with some logic...
self.isTag = self.object.type == 'tag';
self.ui_container = false;
self.path = function(project) {
return Routes.tree_path(project.fullname, self.ref);
}
self.diff_path = function(project, current_ref) {
return Routes.diff_path(project.fullname, current_ref + '...' + self.ref);
}
self.archive_path = function(project, type) {
return Routes.archive_path(project.fullname, project.name + '-' + self.ref, {format: type});
}
//return the scope-safe instance
return self;
};

View File

@ -1,87 +0,0 @@
CollaboratorsController = (dataservice, Collaborator, $http, confirmMessage) ->
vm = this
vm.new_role = 'reader'
vm.isDisabledDeleteAllButton = ->
is_selected = true
result = _.select(vm.collaborators, (c) ->
is_selected = false if c.check_delete
)
is_selected
vm.getCollaborators = (val) ->
return [] if val.length <= 2
Collaborator.find(vm.name_with_owner, val)
vm.selectCollaborator = (item, model, label) ->
vm.selected_new_collaborator = item
false
vm.addCollaborator = ($event) ->
$event.preventDefault()
$event.stopPropagation()
Collaborator.add(vm.name_with_owner,
vm.selected_new_collaborator,
vm.new_role,
vm.project_id)
.success (data) ->
vm.collaborators.push data
$.notify(data.message, 'success')
.error (data) ->
$.notify(data.message, 'error')
vm.new_collaborator_uname = null
vm.selected_new_collaborator = null
false
vm.removeCollaborator = (member, need_confirm = true) ->
return false if need_confirm and !confirmMessage.show()
Collaborator.remove(vm.name_with_owner, member.id)
.success (data) ->
vm.collaborators = _.reject(vm.collaborators, (c) ->
c.id is member.id
)
$.notify(data.message, 'success')
.error (data) ->
$.notify(data.message, 'error')
false
vm.removeCollaborators = ->
return false unless confirmMessage.show()
_.each(vm.collaborators, (c) ->
vm.removeCollaborator(c, false) if c.check_delete
)
false
vm.updateCollaborator = (member) ->
return false unless confirmMessage.show()
Collaborator.update(vm.name_with_owner, member)
.success (data) ->
$.notify(data.message, 'success')
.error (data) ->
$.notify(data.message, 'error')
false
init = (dataservice) ->
vm.name_with_owner = dataservice.name_with_owner
vm.project_id = dataservice.project_id
vm.collaborators = dataservice.collaborators
init(dataservice)
return true
angular
.module("RosaABF")
.controller "CollaboratorsController", CollaboratorsController
CollaboratorsController.$inject = [
'CollaboratorsInitializer'
'Collaborator'
'$http'
'confirmMessage'
]

View File

@ -1,48 +0,0 @@
ApiPullRequestService = ($resource, $http) ->
getPath = (pull, kind) ->
name_with_owner = pull.owner+'/'+pull.project
switch kind
when 'activity' then params = { get_activity: true }
when 'diff' then params = { get_diff: true }
when 'commits' then params = { get_commits: true }
Routes.project_pull_request_path(name_with_owner, pull.serial_id, params)
PullRequestResource = $resource("/:owner/:project/pull_requests/:serial_id?format=json",
owner: "@pull_request.to_ref.project.owner_uname"
project: "@pull_request.to_ref.project.name"
serial_id: "@pull_request.number"
,
update:
method: "PUT"
isArray: false
merge:
url: "/:owner/:project/pull_requests/:serial_id/merge"
format: "json"
method: "PUT"
isArray: false
)
get_activity = (params) ->
path = getPath(params, 'activity')
$http.get(path)
get_diff = (params) ->
path = getPath(params, 'diff')
$http.get(path)
get_commits = (params) ->
path = getPath(params, 'commits')
$http.get(path)
resource: PullRequestResource
get_activity: get_activity
get_diff: get_diff
get_commits: get_commits
angular
.module("RosaABF")
.factory "ApiPullRequest", ApiPullRequestService
ApiPullRequestService.$inject = ['$resource', '$http']

View File

@ -1,179 +0,0 @@
PullRequestController = (dataservice, $http, ApiPullRequest, ApiProject, DateTimeFormatter,
compileHTML, $scope, $rootScope) ->
vm = this
vm.project_resource = null
vm.pull_params = null
vm.pull = null
vm.pull_resource = null
vm.merged_at = null
vm.closed_at = null
vm.branch = null
vm.can_delete_branch = false
activity = $('#pull-activity')
diff = $('#diff.tab-pane .content')
commits = $('#commits.tab-pane .content')
vm.active_tab = null
vm.processing = false
vm.is_pull_updated = false
vm.is_activity_updated = false
vm.is_diff_updated = false
vm.is_commits_updated = false
vm.getPullRequest = ->
vm.pull_resource = ApiPullRequest.resource.get(vm.pull_params, (results) ->
if vm.pull
vm.is_pull_updated = vm.pull.updated_at is results.pull_request.updated_at
else
vm.is_pull_updated = true
vm.pull = results.pull_request
vm.merged_at = DateTimeFormatter.utc(vm.pull.merged_at) if vm.pull.merged_at
vm.closed_at = DateTimeFormatter.utc(vm.pull.closed_at) if vm.pull.closed_at
)
# @param [from_ref] - sets only at first time
vm.getBranch = (from_ref) ->
vm.project_resource = ApiProject.resource.get(vm.pull_params) unless vm.project_resource
# Fix: at first load
# Cannot read property 'from_ref' of null
from_ref = vm.pull.from_ref.ref unless from_ref
vm.project_resource.$branches vm.pull_params, (results) ->
branch = null
_.each results.refs_list, (b) ->
if b.ref is from_ref
branch = new ProjectRef(b)
true
vm.branch = branch
vm.reopen = ->
return false if vm.processing
vm.processing = true
vm.pull_resource.$update
pull_request_action: "reopen"
, ->
vm.getPullRequest()
vm.processing = false
vm.close = ->
return false if vm.processing
vm.processing = true
vm.pull_resource.$update
pull_request_action: "close"
, ->
vm.getPullRequest()
vm.processing = false
vm.merge = ->
return false if vm.processing
vm.processing = true
vm.pull_resource.$merge ->
vm.getPullRequest()
vm.processing = false
vm.deleteBranch = ->
return false if vm.processing
vm.processing = true
vm.project_resource.$delete_branch vm.branch_params(), (-> # success
vm.branch = null
vm.processing = false
), -> # error
vm.getBranch()
vm.processing = false
vm.restoreBranch = ->
return false if vm.processing
vm.processing = true
vm.project_resource.$restore_branch vm.branch_params(), (-> # success
vm.getBranch()
vm.processing = false
), -> # error
vm.getBranch()
vm.processing = false
vm.branch_params = ->
owner: vm.pull_params.owner
project: vm.pull_params.project
ref: vm.pull.from_ref.ref
sha: vm.pull.from_ref.sha
vm.getActivity = ->
return if vm.is_pull_updated and vm.is_activity_updated
vm.processing = true
promise = ApiPullRequest.get_activity(vm.pull_params)
promise.then (response) ->
activity.html(null)
#html = compileHTML.run($scope, response.data)
#activity.html(html)
$rootScope.$broadcast('compile_html', { element: activity, html: response.data })
vm.processing = false
vm.is_activity_updated = true
false
vm.getDiff = ->
return if vm.is_pull_updated and vm.is_diff_updated
vm.processing = true
promise = ApiPullRequest.get_diff(vm.pull_params)
promise.then (response) ->
diff.html(null)
$rootScope.$broadcast('compile_html', { element: diff, html: response.data })
$('[data-toggle="tooltip"]').tooltip()
vm.processing = false
vm.is_diff_updated = true
false
vm.getCommits = ->
return if vm.is_pull_updated and vm.is_commits_updated
vm.processing = true
promise = ApiPullRequest.get_commits(vm.pull_params)
promise.then (response) ->
commits.html(null)
html = compileHTML.run($scope, response.data)
commits.html(html)
vm.processing = false
vm.is_commits_updated = true
false
init = (dataservice) ->
vm.pull_params = dataservice
vm.getPullRequest()
if location.href.match(/(.*)#diff(.*)/)
vm.active_tab = "diff"
vm.getDiff()
else if document.location.href.match(/(.*)#commits(.*)/)
vm.active_tab = "commits"
vm.getCommits()
else
vm.active_tab = 'discussion'
vm.getActivity()
$("#pull_tabs a[href=\"#" + vm.active_tab + "\"]").tab "show"
true
init(dataservice)
true
angular
.module("RosaABF")
.controller "PullRequestController", PullRequestController
PullRequestController.$inject = [
'PullInitializer'
'$http'
'ApiPullRequest'
'ApiProject'
'DateTimeFormatter'
'compileHTML'
'$scope'
'$rootScope'
]

View File

@ -1,49 +0,0 @@
collaboratorService = ($http) ->
{
find: (name_with_owner, val) ->
path = Routes.find_project_collaborators_path(
{
name_with_owner: name_with_owner,
term: val
}
)
$http.get(path).then (response) ->
response.data
add: (name_with_owner, selected, role, project_id) ->
path = Routes.project_collaborators_path(
{
name_with_owner: name_with_owner,
collaborator: {
actor_id: selected.actor_id
actor_type: selected.actor_type
role: role
project_id: project_id
}
}
)
$http.post(path)
remove: (name_with_owner, member_id) ->
path = Routes.project_collaborator_path(name_with_owner, member_id)
$http.delete(path)
update: (name_with_owner, member) ->
path = Routes.project_collaborator_path(
name_with_owner,
member.id,
{
collaborator: { role: member.role }
}
)
$http.put(path)
}
angular
.module("RosaABF")
.factory "Collaborator", collaboratorService
collaboratorService.$inject = ['$http']

View File

@ -1,15 +0,0 @@
previewService = ($http) ->
old_text = ''
{
old_text: old_text
get_preview: (name_with_owner, text, old_text) ->
return null if text is old_text
path = Routes.project_md_preview_path(name_with_owner)
$http.post(path, {text: text})
}
angular
.module("RosaABF")
.factory "Preview", previewService
previewService.$inject = ['$http']

View File

@ -1,48 +0,0 @@
RosaABF.factory("ApiProject", ['$resource', function($resource) {
var ProjectResource = $resource(
'/:owner/:project?format=json&info=true',
{owner: '@project.owner.uname', project: '@project.name'},
{
tags: {
url: '/:owner/:project/tags',
format: 'json',
method: 'GET',
isArray : false
},
branches: {
url: '/:owner/:project/branches',
format: 'json',
method: 'GET',
isArray : false
},
delete_branch: {
url: '/:owner/:project/branches/:ref',
format: 'json',
method: 'DELETE',
isArray : false
},
restore_branch: {
url: '/:owner/:project/branches/:ref', // ?sha=<sha>
format: 'json',
method: 'PUT',
isArray : false
},
create_branch: {
url: '/:owner/:project/branches', // ?new_ref=<new_ref>&from_ref=<from_ref>
format: 'json',
method: 'POST',
isArray : false
}
}
);
return {
resource : ProjectResource,
singleton : {
project : {
branches_count : 0
}
}
}
}]);

View File

@ -1,16 +0,0 @@
%i.img-circle.btn-danger.fa.fa-times
.timeline-item{ 'ng-cloak' => true }
%h3.timeline-header
%a{ 'ng-href' => "{{item.user.link}}" }
%img{ 'ng-src' => "{{item.user.image}}" }
{{item.user.uname}}
%span.time{ popover: "{{item.date | amDateFormat:'ddd, LLL'}}",
"popover-trigger" => "mouseenter", 'popover-append-to-body' => 'true' }
%span.glyphicon.glyphicon-time
%span {{item.date | amDateFormat:'HH:mm'}}
.clearfix
.timeline-body
%p
{{'notification.push.delete_branch' | i18n}}
{{ item.branch_name + ('notification.in_project' | i18n)}}
%a{ 'ng-href' => "{{item.project_link}}" } {{item.project_name_with_owner}}

View File

@ -1,28 +0,0 @@
%i.img-circle.bg-primary.fa.fa-sign-in
.timeline-item{ 'ng-cloak' => true }
%h3.timeline-header
%a{ 'ng-href' => "{{item.user.link}}" }
%img{ 'ng-src' => "{{item.user.image}}" }
{{item.user.uname}}
%span.time{ popover: "{{item.date | amDateFormat:'ddd, LLL'}}",
"popover-trigger" => "mouseenter", 'popover-append-to-body' => 'true' }
%span.glyphicon.glyphicon-time
%span {{item.date | amDateFormat:'HH:mm'}}
.clearfix
.timeline-body
%p
{{'notification.push.' + item.change_type + '_branch' | i18n}}
%a{ 'ng-href' => "{{item.branch_link}}" } {{item.branch_name}}
{{'notification.in_project' | i18n}}
%a{ 'ng-href' => "{{item.project_link}}" } {{item.project_name_with_owner}}
.timeline-footer
.row
.container-fluid{ 'ng-repeat' => 'commit in item.last_commits' }
.col-sm-3.col-md-2
%a{ 'ng-href' => "{{commit.link}}" } {{commit.hash}}
.col-sm-8.col-md-9{ 'ng-bind-html' => "commit.message" }
.clearfix
%br{ 'ng-if' => "item.other_commits" }
%a{ 'ng-if' => "item.other_commits", 'ng-href' => "{{item.other_commits_path}}" } {{item.other_commits}}

View File

@ -1,14 +0,0 @@
%i.img-circle.btn-danger.fa.fa-asterisk
.timeline-item{ 'ng-cloak' => true }
%h3.timeline-header
%span.time{ popover: "{{item.date | amDateFormat:'ddd, LLL'}}",
"popover-trigger" => "mouseenter", 'popover-append-to-body' => 'true' }
%span.glyphicon.glyphicon-time
%span {{item.date | amDateFormat:'HH:mm'}}
.clearfix
.timeline-body
%p
{{'notification.issue_assign' | i18n}}
%a{ 'ng-href' => "{{item.issue.link}}" } {{item.issue.title}}
{{ item.branch_name + ('notification.in_project' | i18n)}}
%a{ 'ng-href' => "{{item.project_link}}" } {{item.project_name_with_owner}}

View File

@ -1,26 +0,0 @@
%i.img-circle.btn-warning.fa.fa-comment
.timeline-item{ 'ng-cloak' => true }
%h3.timeline-header
%a{ 'ng-href' => "{{item.user.link}}" }
%img{ 'ng-src' => "{{item.user.image}}" }
{{item.user.uname}}
%span.time{ popover: "{{item.date | amDateFormat:'ddd, LLL'}}",
"popover-trigger" => "mouseenter", 'popover-append-to-body' => 'true' }
%span.glyphicon.glyphicon-time
%span {{item.date | amDateFormat:'HH:mm'}}
.clearfix
.timeline-body
%p
{{'notification.new_commit_comment.title' | i18n}}
.row
.col-sm-3.col-md-2
%a{ 'ng-href' => "{{item.commit.link}}" } {{item.commit.hash}}
.col-sm-8.col-md-9{ 'ng-bind-html' => "item.commit.message" }
.clearfix
%blockquote{ 'ng-bind-html' => "item.body" }
.timeline-footer
%a.btn.btn-primary.btn-xs{ 'ng-href' => "{{item.commit.link + '#comment' + item.commit.read_more}}" }
{{'read_more' | i18n}}

View File

@ -1,22 +0,0 @@
%i.img-circle.btn-warning.fa.fa-comment
.timeline-item{ 'ng-cloak' => true }
%h3.timeline-header
%a{ 'ng-href' => "{{item.user.link}}" }
%img{ 'ng-src' => "{{item.user.image}}" }
{{item.user.uname}}
%span.time{ popover: "{{item.date | amDateFormat:'ddd, LLL'}}",
"popover-trigger" => "mouseenter", 'popover-append-to-body' => 'true' }
%span.glyphicon.glyphicon-time
%span {{item.date | amDateFormat:'HH:mm'}}
.clearfix
.timeline-body
%p
%span{'ng-show' => 'item.issue.is_pull'} {{'notification.new_pull_comment.title' | i18n}}
%span{'ng-show' => '!item.issue.is_pull'} {{'notification.new_comment.title' | i18n}}
%a{ 'ng-href' => "{{item.issue.link}}" } {{item.issue.title}}
%blockquote{ 'ng-bind-html' => "item.body" }
.timeline-footer
%a.btn.btn-primary.btn-xs{ 'ng-href' => "{{item.issue.link + '#comment' + item.issue.read_more}}" }
{{'read_more' | i18n}}

View File

@ -1,18 +0,0 @@
%i.img-circle.btn-success.fa.fa-check
.timeline-item{ 'ng-cloak' => true }
%h3.timeline-header
%a{ 'ng-href' => "{{item.user.link}}" }
%img{ 'ng-src' => "{{item.user.image}}" }
{{item.user.uname}}
%span.time{ popover: "{{item.date | amDateFormat:'ddd, LLL'}}",
"popover-trigger" => "mouseenter", 'popover-append-to-body' => 'true' }
%span.glyphicon.glyphicon-time
%span {{item.date | amDateFormat:'HH:mm'}}
.clearfix
.timeline-body
%p
%span{'ng-show' => 'item.issue.is_pull'} {{'notification.new_pull' | i18n}}
%span{'ng-show' => '!item.issue.is_pull'} {{'notification.new_issue' | i18n}}
{{'notification.in_project' | i18n}}
%a{ 'ng-href' => "{{item.project_link}}" } {{item.project_name_with_owner}}
%a{ 'ng-href' => "{{item.issue.link}}" } {{item.issue.title}}

View File

@ -1,13 +0,0 @@
%i.img-circle.btn-success.fa.fa-user
.timeline-item{ 'ng-cloak' => true }
%h3.timeline-header
%span.time{ popover: "{{item.date | amDateFormat:'ddd, LLL'}}",
"popover-trigger" => "mouseenter", 'popover-append-to-body' => 'true' }
%span.glyphicon.glyphicon-time
%span {{item.date | amDateFormat:'HH:mm'}}
.clearfix
.timeline-body
%p
{{('notification.new_user.title' | i18n) + item.user_name}}
%p
{{'notification.new_user.content' | i18n}}

View File

@ -1,17 +0,0 @@
%i.img-circle.btn-warning.fa.fa-edit
.timeline-item{ 'ng-cloak' => true }
%h3.timeline-header
%a{ 'ng-href' => "{{item.user.link}}" }
%img{ 'ng-src' => "{{item.user.image}}" }
{{item.user.uname}}
%span.time{ popover: "{{item.date | amDateFormat:'ddd, LLL'}}",
"popover-trigger" => "mouseenter", 'popover-append-to-body' => 'true' }
%span.glyphicon.glyphicon-time
%span {{item.date | amDateFormat:'HH:mm'}}
.clearfix
.timeline-body
%p
{{'notification.wiki.new_commit' | i18n}}
%a{ 'ng-href' => "{{item.wiki_link}}" } wiki
{{'notification.in_project' | i18n}}
%a{ 'ng-href' => "{{item.project_link}}" } {{item.project_name_with_owner}}

View File

@ -1,44 +0,0 @@
$(document).ready(function() {
var dropbox = $("#droplist");
function loadMessages() {
$("#messages-new").fadeOut("slow");
$("#new-messages").delay(700).fadeIn("slow");
}
function loadOldMessages() {
$("#old-messages").fadeIn("slow");
}
$(document).click(function() {
var dl = dropbox.css("height");
var dl2 = dropbox.css("display");
if ((dl2 == "block")&&(dl == "91px")) {
dropbox.slideUp("slow");
}
});
$('.data-expander').on('click', function(e) {
var $button = $(e.target);
var id = "#content-" + $button.attr('id');
var $slider = $(id);
$slider.slideToggle("slow", function(){
$button.toggleClass('expanded collapsed');
});
});
function showActivity(elem) {
$("#activity-bottom"+elem).slideToggle("slow");
var img = document.getElementById("expand" + elem).className;
if (img == "expand-gray-down") {
document.getElementById("expand" + elem).className = "expand-gray-up";
} else {
document.getElementById("expand" + elem).className = "expand-gray-down";
}
}
$('div.information > div.user').on('click', function() {
dropbox.slideToggle("slow");
});
});

View File

@ -1,38 +0,0 @@
/*function deleteAdminMember() {
if (document.getElementById("niceCheckbox1-1").checked == true) {
$("#admin-table-members-row1").fadeOut("slow");
}
if (document.getElementById("niceCheckbox2-1").checked == true) {
$("#admin-table-members-row2").fadeOut("slow");
}
if (document.getElementById("niceCheckbox3-1").checked == true) {
$("#admin-table-members-row3").fadeOut("slow");
}
if (document.getElementById("niceCheckbox4-1").checked == true) {
$("#admin-table-members-row4").fadeOut("slow");
}
}*/
function saveAdminMember() {
$('#_method').attr('value', 'post');
$('form#members_form').submit();
}
function deleteAdminMember() {
$('#_method').attr('value', 'delete');
var delete_url = $('form#members_form').attr('delete_url');
$('form#members_form').attr('action', delete_url);
$('form#members_form').submit();
}
function saveAdminGroup() {
$('#groups_method').attr('value', 'post');
$('form#groups_form').submit();
}
function deleteAdminGroup() {
$('#groups_method').attr('value', 'delete');
var delete_url = $('form#groups_form').attr('delete_url');
$('form#groups_form').attr('action', delete_url);
$('form#groups_form').submit();
}

View File

@ -1,14 +0,0 @@
(function($) {
$.BlobEditor = function() {
$.BlobEditor.Placeholder.add($('#gollum-editor-edit-summary input'));
$('#gollum-editor form[name="blob-editor"]').submit(function( e ) {
e.preventDefault();
$.BlobEditor.Placeholder.clearAll();
//debug('submitting');
$(this).unbind('submit');
$(this).submit();
});
};
$.BlobEditor.Placeholder = $.GollumPlaceholder;
})(jQuery);

View File

@ -1,6 +0,0 @@
$(document).ready ->
$(document).on 'click', '#diff_header .panel-body li.list-group-item a', ->
href = $(this).attr('href')
$(".diff_data.collapse#"+href.slice(1)+"_content").collapse('show')
return

View File

@ -1,14 +0,0 @@
$(document).ready ->
$(document).on 'hide.bs.collapse', '.file .diff_data.collapse', ->
$(this).parent().find('.top button span.fa').removeClass('fa-chevron-down').addClass('fa-chevron-up')
$(document).on 'show.bs.collapse', '.file .diff_data.collapse', ->
$(this).parent().find('.top button span.fa').removeClass('fa-chevron-up').addClass('fa-chevron-down')
$(document).on 'hide.bs.collapse', '#diff_header #collapseList', ->
$(this).parent().find('.panel-title a span.fa').removeClass('fa-chevron-down').addClass('fa-chevron-up')
$(document).on 'show.bs.collapse', '#diff_header #collapseList', ->
$(this).parent().find('.panel-title a span.fa').removeClass('fa-chevron-up').addClass('fa-chevron-down')
return

View File

@ -1,21 +0,0 @@
function setCookie (name, value, expires, path, domain, secure) {
document.cookie = name + "=" + escape(value) +
((expires) ? "; expires=" + expires : "") +
((path) ? "; path=" + path : "") +
((domain) ? "; domain=" + domain : "") +
((secure) ? "; secure" : "");
}
$(document).ready(function() {
if ($(".alert").size()) {
$(".alert").alert()
}
$('#close-alert').click(function () {
var exdate=new Date();
exdate.setDate(exdate.getDate() + 365);
var expires="expires="+exdate.toUTCString();
setCookie("flash_notify_hash", FLASH_HASH_ID, expires);
});
});

View File

@ -1,19 +0,0 @@
$(document).ready(function() {
var fork_name = $('#fork_name');
var forks_path = $('#possible_forks_path');
fork_name.keyup(function(){
$.ajax({
type: 'GET',
url: forks_path.val(),
data: 'name=' + fork_name.val(),
success: function(data){
$('#forkModal .modal-body').html(data);
},
error: function(data){
alert('error'); // TODO remove
}
});
});
});

View File

@ -1,47 +0,0 @@
$(document).ready(function() {
jQuery(window).bind('hashchange', function(e) {
var hash = location.hash;
if (/^#(diff|discussion)-F[0-9]+(L|R)[0-9]+/.test(hash)) {
highlightDiff(hash);
} else if (/^#lc-[0-9]+/.test(hash)) {
highlightShow(hash);
}
});
// Since the event is only triggered when the hash changes, we need to trigger
// the event now, to handle the hash the page may have loaded with.
jQuery(window).trigger('hashchange');
});
function highlightShow(id) {
$('td.code span.highlight-line').removeClass('highlight-line');
var from = to = id.substring(4);
if (/[0-9]+\-lc-[0-9]+$/.test(from)) {
var index = to.indexOf('-');
to = to.substring(index + 2);
from = from.substring(0, index);
}
from = parseInt(from);
to = parseInt(to);
if (from && to) {
if (from > to) {
var x = to; to = from; from = x;
}
var el = $('#ln-' + from);
$(document).scrollTop( el.offset().top );
while (el.length > 0) {
$('td.code span#ln-'+from).addClass('highlight-line');
if (from == to) { return true; }
from += 1;
el = $('#ln-' + from);
}
}
}
function highlightDiff(id) {
$('.highlight-line').removeClass('highlight-line');
$(id).parent().find('td.code').addClass('highlight-line');
}

View File

@ -1,31 +0,0 @@
upd_action = $('#update_action').val()
form = $('#new_pull_request')
updatePull = ->
form.attr('action', upd_action)
.attr('method', 'get')
$('#update_pull').fadeIn('fast')
$('#create_pull').fadeOut('fast')
return
window.pullUpdateToProject = (data)->
ref = $('#to_ref');
ref.parent().load('/'+data.text+'/refs_list', {"selected": ref.val()})
updatePull()
return
$('select#to_ref, select#from_ref').on('change', updatePull)
$('#pull_tabs a').on 'click', (e) ->
href = $(this).attr('href')
if window.history and history.pushState
history.pushState '', '', href
history.replaceState '', '', href
else
location.hash = href
return
diff_tab = $('#pull_tabs a[href="#diff"]')
$('.link_to_full_changes').on 'click', ->
diff_tab.tab 'show'
return

View File

@ -1,37 +0,0 @@
//= require jquery
$(document).ready(function() {
var login_default = $('#login_default').val();
var pass_default = $('#password_default').val();
$('.registartion-input').on('keydown', function() {
var id = $(this).attr('id');
if(id == 'user_login' || id == 'user_password') { id = 'login_error'}
$('.error.'+id).fadeOut('slow');
}).on('focus', function() {
var id = $(this).attr('id');
if(id == 'user_login' && $(this).val() == login_default) { $(this).val('')}
else if(id == 'user_password' && $(this).val() == pass_default) { $(this).val('')}
$(this).addClass('registartion-input-focus').removeClass('registartion-input-error');
}).on('blur', function() {
var id = $(this).attr('id');
if(id == 'user_login' && $(this).val() == '') { $(this).val(login_default)}
else if(id == 'user_password' && $(this).val() == '') { $(this).val(pass_default)}
$(this).addClass('registartion-input-no-focus').removeClass('registartion-input-focus');
});
$('#niceCheckbox1').click(function() {
var el = $(this),
input = el.find('input[type="checkbox"]');
if(input.attr("checked")) {
el.css('backgroundPosition', '0 0');
input.removeAttr('checked');
} else {
el.css('backgroundPosition', '0 -18px');
input.attr('checked', true);
}
return true;
});
$('#recaptcha_response_field').val('');
});

View File

@ -8,7 +8,6 @@
//= require angular //= require angular
//= require angular-sanitize //= require angular-sanitize
//= require angular-ui-bootstrap-tpls //= require angular-ui-bootstrap-tpls
//= require ui-codemirror
//= require angular-i18n //= require angular-i18n
//= require angular-resource //= require angular-resource
@ -25,8 +24,6 @@
//= require underscore //= require underscore
//= require zeroclipboard
//= require notifyjs //= require notifyjs
//= require notifyjs/styles/bootstrap/notify-bootstrap //= require notifyjs/styles/bootstrap/notify-bootstrap
@ -34,33 +31,11 @@
//= require lib/bootstrap-typeahead //= require lib/bootstrap-typeahead
//= require lib/custom-bootstrap-typeahead //= require lib/custom-bootstrap-typeahead
//= require extra/highlight
//= require extra/pull
//= require extra/scroller //= require extra/scroller
//= require extra/fork
//= require extra/diff_chevrons
//= require extra/diff
//= require_self //= require_self
function setCookie (name, value, expires, path, domain, secure) {
document.cookie = name + "=" + escape(value) +
((expires) ? "; expires=" + expires : "") +
((path) ? "; path=" + path : "") +
((domain) ? "; domain=" + domain : "") +
((secure) ? "; secure" : "");
}
$(document).ready(function() { $(document).ready(function() {
$('.notify.alert button.close').click(function () {
var exdate=new Date();
exdate.setDate(exdate.getDate() + 365);
var expires="expires="+exdate.toUTCString();
setCookie("flash_notify_hash", FLASH_HASH_ID, expires);
});
var clip = new ZeroClipboard($("#copy_to_clipboard"));
$('.datetime_moment').each(function() { $('.datetime_moment').each(function() {
var mtime = moment($(this).attr('origin_datetime'), 'YYYY-MM-DD HH:mm Z'); var mtime = moment($(this).attr('origin_datetime'), 'YYYY-MM-DD HH:mm Z');
$(this).attr('title', mtime.utc().format('YYYY-MM-DD HH:mm:ss UTC')); $(this).attr('title', mtime.utc().format('YYYY-MM-DD HH:mm:ss UTC'));
@ -76,16 +51,4 @@ $(document).ready(function() {
updateTime(); updateTime();
setInterval( updateTime, 15000 ); setInterval( updateTime, 15000 );
// TODO refactoring
$('#branch_selector').change(function() {
var form = $('form#branch_changer');
form.attr('action', $(this).val());
form.submit();
});
$('#create_fork').click(function () {
$(this).button('loading');
});
$('[data-toggle="tooltip"]').tooltip();
}); });

View File

@ -1,12 +0,0 @@
//= require jquery
//= require jquery_ujs
//= require jquery-ui
//= require jquery-migrate-min
//= require pirobox_extended_min
//= require ./design/all
$(document).ready(function() {
$('div.information > div.profile > a').on('click', function(e) {
e.preventDefault();
});
});

View File

@ -158,20 +158,6 @@ table.table-borderless > thead > tr > th
padding-top: 5px padding-top: 5px
padding-bottom: 5px padding-bottom: 5px
.advisory_preview
td
padding-top: 0
padding-bottom: 0
margin-top: 0
margin-bottom: 0
h4
margin-top: 0
margin-bottom: 0
.advisory-description
margin-top: 0
.submenu .submenu
margin-bottom: 0 margin-bottom: 0

View File

@ -1,34 +0,0 @@
class AdvisoriesController < ApplicationController
before_action :authenticate_user!
skip_before_action :authenticate_user! if APP_CONFIG['anonymous_access']
def index
authorize :advisory
@advisories = Advisory.includes(:platforms, :projects).search(params[:q]).uniq
@advisories_count = @advisories.count
@advisories = @advisories.paginate(page: current_page, per_page: Advisory.per_page)
respond_to do |format|
format.html
format.json
format.atom
end
end
def show
authorize @advisory = Advisory.find_by(advisory_id: params[:id])
@packages_info = @advisory.fetch_packages_info
end
def search
authorize :advisory
@advisory = Advisory.by_update_type(params[:bl_type]).search_by_id(params[:query]).first
if @advisory.nil?
render nothing: true, status: 404
else
# respond_to do |format|
# format.json { render @advisory }
# end
render @advisory
end
end
end

View File

@ -1,52 +0,0 @@
class Api::V1::AdvisoriesController < Api::V1::BaseController
before_action :authenticate_user!
skip_before_action :authenticate_user!, only: %i(index show) if APP_CONFIG['anonymous_access']
before_action :load_advisory, only: %i(show update)
before_action :load_build_list, only: %i(create update)
def index
authorize :advisory
@advisories = Advisory.includes(:platforms, :projects).paginate(paginate_params)
end
def show
@packages_info = @advisory.fetch_packages_info
end
def create
authorize :advisory
if @build_list.can_attach_to_advisory? &&
@build_list.associate_and_create_advisory(advisory_params) &&
@build_list.save
render_json_response @build_list.advisory, 'Advisory has been created successfully'
else
render_validation_error @build_list.advisory, error_message(@build_list, 'Advisory has not been created')
end
end
def update
if @advisory && @build_list.can_attach_to_advisory? &&
@advisory.attach_build_list(@build_list) && @build_list.save
render_json_response @advisory, "Build list '#{@build_list.id}' has been attached to advisory successfully"
else
render_validation_error @advisory, error_message(@build_list, 'Build list has not been attached to advisory')
end
end
protected
def advisory_params
subject_params(Advisory)
end
def load_build_list
@build_list = BuildList.find params[:build_list_id]
authorize @build_list.save_to_platform, :local_admin_manage?
end
def load_advisory
@advisory = Advisory.find_by(advisory_id: params[:id]) if params[:id]
authorize @advisory if @advisory
end
end

View File

@ -1,112 +0,0 @@
class Api::V1::IssuesController < Api::V1::BaseController
include Api::V1::Issueable
before_action :authenticate_user!
skip_before_action :authenticate_user!, only: %i(index group_index show) if APP_CONFIG['anonymous_access']
before_action :load_group, only: :group_index
before_action :load_project
skip_before_action :load_project, only: %i(all_index user_index group_index)
before_action :load_issue, only: %i(show update index)
def index
@issues = @project.issues
render_issues_list
end
def all_index
authorize :issue, :index?
project_ids = get_all_project_ids membered_projects.pluck(:id)
@issues = Issue.where(project_id: project_ids)
render_issues_list
end
def user_index
authorize :issue, :index?
project_ids = get_all_project_ids current_user.projects.pluck(:id)
@issues = Issue.where(project_id: project_ids)
render_issues_list
end
def group_index
project_ids = @group.projects.pluck(:id)
project_ids = membered_projects.where(id: project_ids).pluck(:id)
@issues = Issue.where(project_id: project_ids)
render_issues_list
end
def show
if @issue.pull_request
redirect_to api_v1_project_pull_request_path(@project.id, @issue.serial_id)
else
respond_to :json
end
end
def create
@issue = @project.issues.new
@issue.assign_attributes subject_params(Issue, @issue)
@issue.user = current_user
create_subject @issue
end
def update
@issue.labelings.destroy_all if params[:update_labels] && policy(@project).write?
if params[:issue] && status = params[:issue].delete(:status)
@issue.set_close(current_user) if status == 'closed'
@issue.set_open if status == 'open'
end
update_subject @issue
end
private
def render_issues_list
@issues = @issues.preload(:user, :assignee, :labels, :project).without_pull_requests
if params[:status] == 'closed'
@issues = @issues.closed
else
@issues = @issues.opened
end
if action_name == 'index' && params[:assignee].present?
case params[:assignee]
when 'none'
@issues = @issues.where(assigned_id: nil)
when '*'
@issues = @issues.where('issues.assigned_id IS NOT NULL')
else
@issues = @issues.where('issues.assignees_issues.uname = ?', params[:assignee])
end
end
if %w[all_index user_index group_index].include?(action_name)
case params[:filter]
when 'created'
@issues = @issues.where(user_id: current_user)
when 'all'
else
@issues = @issues.where(assignee_id: current_user)
end
else
@issues.where('users.uname = ?', params[:creator]) if params[:creator].present?
end
if params[:labels].present?
labels = params[:labels].split(',').map(&:strip).select(&:present?)
@issues = @issues.where('labels.name IN (?)', labels)
end
sort = params[:sort] == 'updated' ? 'issues.updated_at' : 'issues.created_at'
direction = params[:direction] == 'asc' ? 'ASC' : 'DESC'
@issues = @issues.order("#{sort} #{direction}")
@issues = @issues.where('issues.created_at >= to_timestamp(?)', params[:since]) if params[:since] =~ /\A\d+\z/
@issues = @issues.paginate(paginate_params)
respond_to do |format|
format.json { render :index }
end
end
end

View File

@ -18,10 +18,6 @@ class Api::V1::ProjectsController < Api::V1::BaseController
def show def show
end end
def refs_list
@refs = @project.repo.branches + @project.repo.tags.select{ |t| t.commit }
end
def update def update
update_subject @project update_subject @project
end end

View File

@ -1,172 +0,0 @@
class Api::V1::PullRequestsController < Api::V1::BaseController
include Api::V1::Issueable
before_action :authenticate_user!
skip_before_action :authenticate_user!, only: %i(show index group_index commits files) if APP_CONFIG['anonymous_access']
before_action :load_group, only: %i(group_index)
before_action :load_project, except: %i(all_index user_index)
before_action :load_issue, only: %i(show index commits files merge update)
before_action :load_pull, only: %i(show index commits files merge update)
def index
@pulls = @project.pull_requests
@pulls_url = api_v1_project_pull_requests_path(@project, format: :json)
render_pulls_list
end
def all_index
authorize :pull_request, :index?
project_ids = get_all_project_ids membered_projects.pluck(:id)
@pulls = PullRequest.where('pull_requests.to_project_id IN (?)', project_ids)
@pulls_url = api_v1_pull_requests_path format: :json
render_pulls_list
end
def user_index
authorize :pull_request, :index?
project_ids = get_all_project_ids current_user.projects.pluck(:id)
@pulls = PullRequest.where('pull_requests.to_project_id IN (?)', project_ids)
@pulls_url = pull_requests_api_v1_user_path format: :json
render_pulls_list
end
def group_index
project_ids = @group.projects.pluck(:id)
project_ids = membered_projects.where(id: project_ids).pluck(:id)
@pulls = PullRequest.where(to_project_id: project_ids)
@pulls_url = pull_requests_api_v1_group_path
render_pulls_list
end
def show
redirect_to api_v1_project_issue_path(@project.id, @issue.serial_id) and return if @pull.nil?
end
def create
from_project = Project.find_by(id: pull_params[:from_project_id])
from_project ||= @project
authorize from_project, :show?
@pull = @project.pull_requests.build
@pull.build_issue title: pull_params[:title], body: pull_params[:body]
@pull.from_project = from_project
@pull.to_ref, @pull.from_ref = pull_params[:to_ref], pull_params[:from_ref]
@pull.issue.assignee_id = pull_params[:assignee_id] if policy(@project).write?
@pull.issue.user, @pull.issue.project = current_user, @project
@pull.issue.new_pull_request = true
render_validation_error(@pull, "#{@pull.class.name} has not been created") && return unless @pull.valid?
authorize @pull
@pull.save # set pull id
@pull.reload
@pull.check(false) # don't make event transaction
if @pull.already?
@pull.destroy
error_message = I18n.t('projects.pull_requests.up_to_date', to_ref: @pull.to_ref, from_ref: @pull.from_ref)
render_json_response(@pull, error_message, 422)
else
@pull.send(@pull.status == 'blocked' ? 'block' : @pull.status)
render_json_response @pull, "#{@pull.class.name} has been created successfully"
end
end
def update
@pull = @project.pull_requests.includes(:issue).where(issues: {serial_id: params[:id]}).first
authorize @pull
if pull_params.present?
attrs = subject_params(PullRequest)
attrs.merge!(assignee_id: pull_params[:assignee_id]) if policy(@project).write?
if action = %w(close reopen).find{ |s| s == pull_params[:status] }
if @pull.send("can_#{action}?")
@pull.set_user_and_time current_user
need_check = true if action == 'reopen' && @pull.valid?
end
end
end
class_name = @pull.class.name
if @pull.issue.update_attributes(attrs)
@pull.send(action) if action.present?
@pull.check if need_check
render_json_response @pull, "#{class_name} has been updated successfully"
else
render_validation_error @pull, "#{class_name} has not been updated"
end
end
def commits
authorize @pull
@commits = @pull.repo.commits_between(@pull.to_commit, @pull.from_commit).paginate(paginate_params)
end
def files
authorize @pull
@stats = @pull.diff_stats.zip(@pull.diff).paginate(paginate_params)
end
def merge
authorize @pull
class_name = @pull.class.name
if @pull.merge!(current_user)
render_json_response @pull, "#{class_name} has been merged successfully"
else
render_validation_error @pull, "#{class_name} has not been merged"
end
end
private
# Private: before_action hook which loads PullRequest.
def load_pull
@pull = @issue.pull_request
authorize @pull, :show? if @pull
end
def render_pulls_list
@pulls = @pulls.includes(issue: [:user, :assignee])
if params[:status] == 'closed'
@pulls = @pulls.closed_or_merged
else
@pulls = @pulls.not_closed_or_merged
end
if action_name == 'index' && params[:assignee].present?
case params[:assignee]
when 'none'
@pulls = @pulls.where('issues.assigned_id IS NULL')
when '*'
@pulls = @pulls.where('issues.assigned_id IS NOT NULL')
else
@pulls = @pulls.where('assignees_issues.uname = ?', params[:assignee])
end
end
if %w[all_index user_index group_index].include?(action_name)
case params[:filter]
when 'created'
@pulls = @pulls.where('issues.user_id = ?', current_user.id)
when 'all'
else
@pulls = @pulls.where('issues.assignee_id = ?', current_user.id)
end
else
@pulls.where('users.uname = ?', params[:creator]) if params[:creator].present?
end
sort = params[:sort] == 'updated' ? 'issues.updated_at' : 'issues.created_at'
direction = params[:direction] == 'asc' ? 'ASC' : 'DESC'
@pulls = @pulls.order("#{sort} #{direction}")
@pulls = @pulls.where('issues.created_at >= to_timestamp(?)', params[:since]) if params[:since] =~ /\A\d+\z/
@pulls = @pulls.paginate(paginate_params)
render :index
end
def pull_params
@pull_params ||= params[:pull_request] || {}
end
end

View File

@ -37,8 +37,6 @@ class ApplicationController < ActionController::Base
redirect_to forbidden_url, alert: t("flash.exception_message") redirect_to forbidden_url, alert: t("flash.exception_message")
end end
rescue_from Grit::NoSuchPathError, with: :not_found
def render_404 def render_404
render_error 404 render_error 404

View File

@ -2,20 +2,12 @@ class HomeController < ApplicationController
before_action :authenticate_user!, except: [:root] before_action :authenticate_user!, except: [:root]
skip_after_action :verify_authorized skip_after_action :verify_authorized
def root
respond_to do |format|
format.html { render 'pages/tour/abf-tour-project-description-1' }
end
end
def activity(is_my_activity = false) def activity(is_my_activity = false)
@filter = t('feed_menu').has_key?(params[:filter].try(:to_sym)) ? params[:filter].to_sym : :all #@filter = :build
@activity_feeds = current_user.activity_feeds @activity_feeds = current_user.activity_feeds
.by_project_name(params[:project_name_filter]) .by_project_name(params[:project_name_filter])
.by_owner_uname(params[:owner_filter]) .by_owner_uname(params[:owner_filter])
@activity_feeds = @activity_feeds.where(kind: "ActivityFeed::#{@filter.upcase}".constantize) unless @filter == :all #@activity_feeds = @activity_feeds.where(kind: "ActivityFeed::#{@filter.upcase}".constantize) unless @filter == :all
@activity_feeds = @activity_feeds.where(user_id: current_user) if @own_filter == :created
@activity_feeds = @activity_feeds.where.not(user_id: current_user) if @own_filter == :not_created
@activity_feeds = if is_my_activity @activity_feeds = if is_my_activity
@activity_feeds.where(creator_id: current_user) @activity_feeds.where(creator_id: current_user)

View File

@ -1,18 +1,6 @@
class PagesController < ApplicationController class PagesController < ApplicationController
skip_after_action :verify_authorized skip_after_action :verify_authorized
def tour_inside
@entries = case params[:id]
when 'builds'
%w(repo builds monitoring)
when 'sources'
%w(source history annotation edit)
when 'projects'
%w(control git tracker)
end
render "pages/tour/tour-inside"
end
def forbidden def forbidden
end end

View File

@ -2,7 +2,7 @@ class Platforms::PlatformsController < Platforms::BaseController
include FileStoreHelper include FileStoreHelper
before_action :authenticate_user! before_action :authenticate_user!
skip_before_action :authenticate_user!, only: [:advisories, :members, :show] if APP_CONFIG['anonymous_access'] skip_before_action :authenticate_user!, only: [:members, :show] if APP_CONFIG['anonymous_access']
def index def index
authorize :platform authorize :platform
@ -150,11 +150,6 @@ class Platforms::PlatformsController < Platforms::BaseController
redirect_to members_platform_url(@platform) redirect_to members_platform_url(@platform)
end end
def advisories
authorize @platform
@advisories = @platform.advisories.paginate(page: params[:page])
end
def clear def clear
authorize @platform authorize @platform
@platform.clear @platform.clear

View File

@ -1,6 +1,5 @@
class Projects::BaseController < ApplicationController class Projects::BaseController < ApplicationController
prepend_before_action :authenticate_user_and_find_project prepend_before_action :authenticate_user_and_find_project
before_action :init_statistics
protected protected
@ -16,11 +15,4 @@ class Projects::BaseController < ApplicationController
return if params[:name_with_owner].blank? return if params[:name_with_owner].blank?
authorize @project = Project.find_by_owner_and_name!(params[:name_with_owner]), :show? authorize @project = Project.find_by_owner_and_name!(params[:name_with_owner]), :show?
end end
def init_statistics
if @project
#@opened_issues_count = @project.issues.without_pull_requests.not_closed_or_merged.count
#@opened_pull_requests_count = @project.issues.joins(:pull_request).not_closed_or_merged.count
end
end
end end

View File

@ -93,28 +93,6 @@ class Projects::BuildListsController < Projects::BaseController
end end
def publish def publish
@build_list.update_type = params[:build_list][:update_type] if params[:build_list][:update_type].present?
if params[:attach_advisory].present? and params[:attach_advisory] != 'no' and !@build_list.advisory
unless @build_list.update_type.in? BuildList::RELEASE_UPDATE_TYPES
redirect_to :back, notice: t('layout.build_lists.publish_fail') and return
end
if params[:attach_advisory] == 'new'
# create new advisory
unless @build_list.associate_and_create_advisory(advisory_params)
redirect_to :back, notice: t('layout.build_lists.publish_fail') and return
end
else
# attach existing advisory
a = Advisory.find_by(advisory_id: params[:attach_advisory])
unless (a && a.attach_build_list(@build_list))
redirect_to :back, notice: t('layout.build_lists.publish_fail') and return
end
end
end
@build_list.publisher = current_user @build_list.publisher = current_user
do_and_back(:publish, 'publish_') do_and_back(:publish, 'publish_')
end end
@ -187,31 +165,12 @@ class Projects::BuildListsController < Projects::BaseController
render partial: 'build_lists_ajax', layout: false render partial: 'build_lists_ajax', layout: false
end end
def update_type
respond_to do |format|
format.html { render nothing: true }
format.json do
@build_list.update_type = params[:update_type]
if @build_list.save
render json: 'success', status: :ok
else
render json: { message: @build_list.errors.full_messages.join('. ') },
status: :unprocessable_entity
end
end
end
end
protected protected
def build_list_params def build_list_params
subject_params(BuildList) subject_params(BuildList)
end end
def advisory_params
permit_params(%i(build_list advisory), *policy(Advisory).permitted_attributes)
end
# Private: before_action hook which loads BuidList. # Private: before_action hook which loads BuidList.
def load_build_list def load_build_list
authorize @build_list = authorize @build_list =

View File

@ -1,78 +0,0 @@
class Projects::CollaboratorsController < Projects::BaseController
before_action :authenticate_user!
before_action :authorize_collaborators
before_action :find_users
before_action :find_groups
def index
@collaborators = Collaborator.find_by_project(@project)
end
def find
users = User.not_member_of(@project)
groups = Group.not_member_of(@project)
if params[:term].present?
users = users.search(params[:term]).first(5)
groups = groups.search(params[:term]).first(5)
end
@collaborators = (users | groups).map{|act| Collaborator.new(actor: act, project: @project)}
end
def create
@collaborator = Collaborator.new(collaborator_params)
@collaborator.project = @project
respond_to do |format|
if @collaborator.save
format.json { render partial: 'collaborator', locals: {collaborator: @collaborator, success: true} }
else
format.json { render json: {message:t('flash.collaborators.error_in_adding')}, status: 422 }
end
end
end
def update
cb = Collaborator.find(params[:id])
respond_to do |format|
if cb.update_attributes(params[:collaborator])
format.json { render json: {message:t('flash.collaborators.successfully_updated', uname: cb.actor.uname)} }
else
format.json { render json: {message:t('flash.collaborators.error_in_updating')}, status: 422 }
end
end
end
def destroy
cb = Collaborator.find(params[:id])
respond_to do |format|
if cb.present? && cb.destroy
format.json { render json: {message:t('flash.collaborators.successfully_removed', uname: cb.actor.uname)} }
else
format.json {
render json: {message:t('flash.collaborators.error_in_removing', uname: cb.try(:actor).try(:uname))},
status: 422
}
end
end
end
protected
def collaborator_params
subject_params(Collaborator)
end
def find_users
@users = @project.collaborators.order('uname')#User.all
@users = @users.without(@project.owner_id) if @project.owner_type == 'User'
end
def find_groups
@groups = @project.groups.order('uname')#Group.all
@groups = @groups.without(@project.owner_id) if @project.owner_type == 'Group'
end
def authorize_collaborators
authorize @project, :update?
end
end

View File

@ -1,65 +0,0 @@
class Projects::CommentsController < Projects::BaseController
before_action :authenticate_user!
before_action :find_commentable
before_action :find_or_build_comment
include CommentsHelper
def create
respond_to do |format|
if !@comment.set_additional_data params
format.json {
render json: {
message: I18n.t("flash.comment.save_error"),
error: @comment.errors.full_messages
}
}
elsif @comment.save
format.json {}
else
format.json { render json: { message: I18n.t("flash.comment.save_error") }, status: 422 }
end
end
end
def edit
end
def update
respond_to do |format|
if @comment.update_attributes(comment_params)
format.json { render json: {message:t('flash.comment.updated'), body: view_context.markdown(@comment.body)} }
else
format.json { render json: {message:t('flash.comment.error_in_updating')}, status: 422 }
end
end
end
def destroy
respond_to do |format|
if @comment.present? && @comment.destroy
format.json { render json: {message: I18n.t('flash.comment.destroyed')} }
else
format.json {
render json: {message: t('flash.comment.error_in_deleting')}, status: 422 }
end
end
end
protected
def comment_params
subject_params(Comment)
end
def find_commentable
@commentable = params[:issue_id].present? && @project.issues.find_by(serial_id: params[:issue_id]) ||
params[:commit_id].present? && @project.repo.commit(params[:commit_id])
end
def find_or_build_comment
@comment = params[:id].present? && Comment.where(automatic: false).find(params[:id]) ||
current_user.comments.build(comment_params) {|c| c.commentable = @commentable; c.project = @project}
authorize @comment
end
end

View File

@ -1,28 +0,0 @@
class Projects::CommitSubscribesController < Projects::BaseController
before_action :authenticate_user!
before_action :find_commit
def create
if Subscribe.subscribe_to_commit(@options)
flash[:notice] = I18n.t("flash.subscribe.commit.saved")
# TODO js
redirect_to commit_path(@project, @commit)
else
flash[:error] = I18n.t("flash.subscribe.saved_error")
redirect_to commit_path(@project, @commit)
end
end
def destroy
Subscribe.unsubscribe_from_commit(@options)
flash[:notice] = t("flash.subscribe.commit.destroyed")
redirect_to commit_path(@project, @commit)
end
protected
def find_commit
@commit = @project.repo.commit(params[:commit_id])
@options = {project_id: @project.id, subscribeable_id: @commit.id.hex, subscribeable_type: @commit.class.name, user_id: current_user.id}
end
end

View File

@ -1,22 +0,0 @@
class Projects::Git::BaseController < Projects::BaseController
before_action :authenticate_user!
if APP_CONFIG['anonymous_access']
skip_before_action :authenticate_user!, only: %i(show index blame raw archive diff tags branches)
before_action :authenticate_user, only: %i(show index blame raw archive diff tags branches)
end
before_action :set_treeish_and_path
before_action :set_branch_and_tree
protected
def set_treeish_and_path
@treeish, @path = params[:treeish].presence || @project.default_head, params[:path]
end
def set_branch_and_tree
@branch = @project.repo.branches.detect{|b| b.name == @treeish}
@tree = @project.repo.tree(@treeish)
# raise Grit::NoSuchPathError if @tree.blobs.blank?
end
end

View File

@ -1,38 +0,0 @@
class Projects::Git::BlobsController < Projects::Git::BaseController
before_action :set_blob
before_action -> {authorize @project, :write? }, only: [:edit, :update]
def show
end
def edit
end
def update
if @project.update_file(params[:path], params[:content].gsub("\r", ''),
message: params[:message].gsub("\r", ''), actor: current_user, head: @treeish)
flash[:notice] = t("flash.blob.successfully_updated", name: params[:path])
else
flash[:notice] = t("flash.blob.updating_error", name: params[:path])
end
redirect_to action: :show
end
def blame
@blame = Grit::Blob.blame(@project.repo, @commit.id, @path)
end
def raw
repo = Grit::GitRuby::Repository.new(@project.repo.path)
raw = repo.get_raw_object_by_sha1(@blob.id)
send_data raw.content, type: @blob.content_type, disposition: @blob.disposition
end
protected
def set_blob
@blob = @tree / @path or raise Grit::NoSuchPathError
redirect_to tree_path(@project, treeish: @treeish, path: @path) if @blob.is_a? Grit::Tree
@commit = @project.repo.log(@treeish, @path, max_count: 1).first
end
end

View File

@ -1,50 +0,0 @@
class Projects::Git::CommitsController < Projects::Git::BaseController
def index
if @path.present?
@commits = @project.repo.log(@treeish, @path)
else
@commits, @page, @last_page = @project.paginate_commits(@treeish, page: params[:page])
end
end
def show
@commit = @commentable = @project.repo.commit(params[:id]) || raise(ActiveRecord::RecordNotFound)
@comments = Comment.for_commit(@commit)
respond_to do |format|
format.html
format.diff { render text: (@commit.show.map(&:diff).join("\n") rescue ''), content_type: "text/plain" }
format.patch { render text: (@commit.to_patch rescue ''), content_type: "text/plain" }
end
end
def diff
res = params[:diff].split(/\A(.*)\.\.\.(.*)\z/).select {|e| e.present?}
if res[1].present?
params1 = res[0]
params2 = res[1] == 'HEAD' ? @project.resolve_default_branch : res.last
else # get only one parameter
params1 = @project.resolve_default_branch
params2 = res.first
end
params1.sub! 'HEAD', @project.resolve_default_branch
params2.sub! 'HEAD', @project.resolve_default_branch
ref1 = if @project.repo.branches_and_tags.include? params1
@project.repo.commits(params1).first
else
params1 # possible commit hash
end
@commit1 = @project.repo.commit(ref1) || raise(ActiveRecord::RecordNotFound)
ref = if @project.repo.branches_and_tags.include? params2
@project.repo.commits(params2).first
else
params2 # possible commit hash
end
@commit = @project.repo.commit(ref) || raise(ActiveRecord::RecordNotFound)
@common_ancestor = @project.repo.commit(@project.repo.git.merge_base({}, @commit1, @commit)) || @commit1
@stats = @project.repo.diff_stats @commit1.id, @commit.id
end
end

View File

@ -1,98 +0,0 @@
class Projects::Git::TreesController < Projects::Git::BaseController
skip_before_action :set_branch_and_tree, only: :archive
skip_before_action :set_treeish_and_path, only: :archive
before_action :redirect_to_project, only: :show
before_action :resolve_treeish, only: [:branch, :destroy]
# skip_authorize_resource :project, only: [:destroy, :restore_branch, :create]
before_action -> { authorize(@project, :show?) }, only: [:show, :archive, :tags, :branches]
def show
unless request.xhr?
render('empty') and return if @project.is_empty?
@tree = @tree / @path if @path.present?
@commit = @branch.present? ? @branch.commit() : @project.repo.log(@treeish, @path, max_count: 1).first
raise Grit::NoSuchPathError unless @commit
else
@tree = @tree / @path if @path.present?
end
end
def archive
format, @treeish = params[:format], params[:treeish]
raise Grit::NoSuchPathError unless @treeish =~ /^#{@project.name}-/ &&
@treeish !~ /[\s]+/ &&
format =~ /\A(zip|tar\.gz)\z/
@treeish.gsub!(/^#{@project.name}-/, '')
sha1 = @project.build_scripts.by_active.by_treeish(@treeish).first.try(:sha1)
unless sha1
@commit = @project.repo.commits(@treeish, 1).first
raise Grit::NoSuchPathError unless @commit
tag = @project.repo.tags.find{ |t| t.name == @treeish }
sha1 = @project.get_project_tag_sha1(tag, format) if tag
end
if sha1.present?
redirect_to "#{APP_CONFIG['file_store_url']}/api/v1/file_stores/#{sha1}"
else
archive = @project.archive_by_treeish_and_format @treeish, format
send_file archive[:path], disposition: 'attachment', type: "application/#{format == 'zip' ? 'zip' : 'x-tar-gz'}", filename: archive[:fullname]
end
end
def tags
if request.xhr?
@refs = @project.repo.tags.select{ |t| t.commit }.sort_by(&:name).reverse
render :refs_list
else
respond_to do |format|
format.json { render nothing: true, status: 422 }
format.html
end
end
end
def restore_branch
authorize @project, :write?
status = @project.create_branch(@treeish, params[:sha], current_user) ? 200 : 422
render nothing: true, status: status
end
def create
authorize @project, :write?
status = @project.create_branch(params[:new_ref], params[:from_ref], current_user) ? 200 : 422
render nothing: true, status: status
end
def destroy
authorize @project, :write?
status = @branch && @project.delete_branch(@branch, current_user) ? 200 : 422
render nothing: true, status: status
end
def branches
if request.xhr?
@refs = @project.repo.branches.sort_by(&:name)
render :refs_list
else
respond_to do |format|
format.json { render nothing: true, status: 422 }
format.html
end
end
end
protected
def resolve_treeish
raise Grit::NoSuchPathError if params[:treeish] != @branch.try(:name)
end
def redirect_to_project
if params[:treeish] == @project.resolve_default_branch && params[:path].blank? && !request.xhr?
redirect_to @project
end
end
end

View File

@ -1,56 +0,0 @@
class Projects::HooksController < Projects::BaseController
before_action :authenticate_user!
before_action -> { authorize @project, :update? }
before_action :load_hook, except: %i(index new create)
def index
@name = params[:name]
@hooks = @project.hooks.for_name(@name).order('name asc, created_at desc')
render(:show) if @name.present?
end
def new
@hook = @project.hooks.build
end
def edit
end
def create
authorize @hook = @project.hooks.build(hook_params)
if @hook.save
redirect_to project_hooks_path(@project, name: @hook.name), notice: t('flash.hook.created')
else
flash[:error] = t('flash.hook.save_error')
flash[:warning] = @hook.errors.full_messages.join('. ')
render :new
end
end
def update
if @hook.update_attributes(hook_params)
redirect_to project_hooks_path(@project, name: @hook.name), notice: t('flash.hook.updated')
else
flash[:error] = t('flash.hook.save_error')
flash[:warning] = @hook.errors.full_messages.join('. ')
render :edit
end
end
def destroy
@hook.destroy
redirect_to project_hooks_path(@project, name: @hook.name)
end
private
def hook_params
subject_params(Hook)
end
# Private: before_action hook which loads Hook.
def load_hook
authorize @hook = @project.hooks.find(params[:id])
end
end

View File

@ -1,176 +0,0 @@
class Projects::IssuesController < Projects::BaseController
before_action :authenticate_user!
skip_before_action :authenticate_user!, only: [:index, :show] if APP_CONFIG['anonymous_access']
before_action :load_issue, only: %i(show edit update destroy)
before_action :load_and_authorize_label, only: %i(create_label update_label destroy_label)
before_action :find_collaborators, only: :search_collaborators
layout false, only: [:update, :search_collaborators]
def index
params[:kind] = params[:kind] == 'pull_requests' ? 'pull_requests' : 'issues'
raise Pundit::NotAuthorizedError if !@project.has_issues? && params[:kind] == 'issues'
params[:filter] = params[:filter].in?(['created', 'assigned']) ? params[:filter] : 'all'
params[:sort] = params[:sort] == 'submitted' ? 'submitted' : 'updated'
params[:direction] = params[:direction] == 'asc' ? :asc : :desc
params[:status] = params[:status] == 'closed' ? :closed : :open
if !params[:labels].is_a?(Array) || params[:labels].blank?
params[:labels] = []
end
respond_to do |format|
format.html { render 'index' }
format.json do
all_issues =
if params[:kind] == 'pull_requests'
@project.issues.joins(:pull_request)
else
@project.issues.without_pull_requests
end
@all_issues = all_issues
if current_user
@created_issues = all_issues.where(user_id: current_user)
@assigned_issues = all_issues.where(assignee_id: current_user)
end
case params[:filter]
when 'created'
@issues = @created_issues
when 'assigned'
@issues = @assigned_issues
else
@issues = all_issues
end
if params[:labels].is_a?(Array) && params[:labels].present?
@issues = @issues.joins(:labels).where(labels: {name: params[:labels]})
end
@opened_issues, @closed_issues = @issues.not_closed_or_merged, @issues.closed_or_merged
@issues = @issues.send( params[:status] == :closed ? :closed_or_merged : :not_closed_or_merged )
if params[:sort] == 'submitted'
@issues = @issues.order(created_at: params[:direction])
else
@issues = @issues.order(updated_at: params[:direction])
end
@issues = @issues.includes(:assignee, :user, :pull_request).uniq
.paginate(page: current_page)
render 'index'
end
end
end
def pull_requests
params[:kind] = 'pull_requests'
index
end
def labels
render partial: 'projects/issues/labels.json', locals: {project: @project}, layout: false
end
def new
authorize @issue = @project.issues.build
end
def create
@issue = @project.issues.new
@issue.assign_attributes(issue_params)
@issue.user = current_user
authorize @issue
if @issue.save
@issue.subscribe_creator(current_user.id)
flash[:notice] = I18n.t("flash.issue.saved")
redirect_to project_issues_path(@project)
else
flash[:error] = I18n.t("flash.issue.save_error")
render action: :new
end
end
def show
redirect_to project_pull_request_path(@project, @issue.pull_request) if @issue.pull_request
@commentable = @issue
end
def update
respond_to do |format|
format.html { render nothing: true, status: 200 }
format.json {
status = 200
if params[:issue] && status = params[:issue][:status]
@issue.set_close(current_user) if status == 'closed'
@issue.set_open if status == 'open'
status = @issue.save ? 200 : 500
else
status = 422 unless @issue.update_attributes(issue_params)
end
render status: status
}
end
end
# def destroy
# @issue.destroy
# flash[:notice] = t("flash.issue.destroyed")
# redirect_to root_path
# end
def create_label
@label = @project.labels.new(name: params[:name], color: params[:color])
respond_to do |format|
if @label.save
format.json { render partial: 'labels', locals: {project: @project} }
else
format.json { render text: @label.errors.full_messages, status: 422 }
end
end
end
def update_label
respond_to do |format|
if @label.update_attributes(name: params[:name], color: params[:color])
format.json { render partial: 'labels', locals: {project: @project} }
else
format.json { render text: @label.errors.full_messages, status: 422 }
end
end
end
def destroy_label
respond_to do |format|
if @label.destroy
format.json { render partial: 'labels', locals: {project: @project} }
else
format.json { render json: @label.errors.full_messages, status: 422 }
end
end
end
def search_collaborators
end
private
def issue_params
subject_params(Issue, @issue)
end
# Private: before_action hook which loads Issue.
def load_issue
authorize @issue = @project.issues.find_by!(serial_id: params[:id])
end
# Private: before_action hook which loads Label.
def load_and_authorize_label
authorize @project, :write?
@label = @project.labels.find(params[:label_id]) if params[:label_id]
end
end

View File

@ -1,3 +0,0 @@
class Projects::Project::BaseController < Projects::BaseController
end

View File

@ -1,13 +0,0 @@
class Projects::Project::ProjectController < Projects::Project::BaseController
def index
(render :error_github) if not @project.github_data
end
def commit
redirect_to 'https://github.com/' + @project.github_get_organization + '/' + @project.name + '/commit/' + params[:sha]
end
def diff
redirect_to 'https://github.com/' + @project.github_get_organization + '/' + @project.name + '/compare/' + params[:diff]
end
end

View File

@ -136,29 +136,6 @@ class Projects::ProjectsController < Projects::BaseController
redirect_to @project.owner redirect_to @project.owner
end end
def fork(is_alias = false)
owner = (Group.find params[:group] if params[:group].present?) || current_user
authorize owner, :write?
if forked = @project.fork(owner, new_name: params[:fork_name], is_alias: is_alias) and forked.valid?
redirect_to forked, notice: t("flash.project.forked")
else
flash[:warning] = t("flash.project.fork_error")
flash[:error] = forked.errors.full_messages.join("\n")
redirect_to @project
end
end
def alias
authorize @project
fork(true)
end
def possible_forks
authorize @project
render partial: 'projects/git/base/forks', layout: false,
locals: { owner: current_user, name: (params[:name].presence || @project.name) }
end
def sections def sections
authorize @project, :update? authorize @project, :update?
if request.patch? if request.patch?
@ -193,20 +170,16 @@ class Projects::ProjectsController < Projects::BaseController
render json: items render json: items
end end
def preview def commit
authorize @project redirect_to 'https://github.com/' + @project.github_get_organization + '/' + @project.name + '/commit/' + params[:sha]
respond_to do |format|
format.json {}
format.html {render inline: view_context.markdown(params[:text]), layout: false}
end
end end
def refs_list def diff
authorize @project redirect_to 'https://github.com/' + @project.github_get_organization + '/' + @project.name + '/compare/' + params[:diff]
refs = @project.repo.branches_and_tags.map(&:name) end
@selected = params[:selected] if refs.include?(params[:selected])
@selected ||= @project.resolve_default_branch def bl_redirect
render layout: false redirect_to controller: "build_lists", action: "index"
end end
protected protected

View File

@ -1,169 +0,0 @@
class Projects::PullRequestsController < Projects::BaseController
before_action :authenticate_user!
skip_before_action :authenticate_user!, only: [:index, :show] if APP_CONFIG['anonymous_access']
before_action :load_issue, except: %i(index autocomplete_to_project new create)
before_action :load_pull, except: %i(index autocomplete_to_project new create)
def new
to_project = find_destination_project(false)
authorize to_project, :show?
@pull = to_project.pull_requests.new
@issue = @pull.issue = to_project.issues.new
set_attrs
authorize @pull
if PullRequest.check_ref(@pull, 'to', @pull.to_ref) && PullRequest.check_ref(@pull, 'from', @pull.from_ref) || @pull.uniq_merge
flash.now[:warning] = @pull.errors.full_messages.join('. ')
else
@pull.check(false) # don't make event transaction
if @pull.already?
@pull.destroy
flash.now[:warning] = I18n.t('projects.pull_requests.up_to_date', to_ref: @pull.to_ref, from_ref: @pull.from_ref)
else
load_diff_commits_data
end
end
end
def create
unless pull_params
redirect :back
end
to_project = find_destination_project
authorize to_project, :show?
@pull = to_project.pull_requests.build pull_params
@issue = @pull.issue
@pull.issue.assignee_id = (params[:issue] || {})[:assignee_id] if policy(to_project).write?
@pull.issue.user, @pull.issue.project, @pull.from_project = current_user, to_project, @project
@pull.from_project_owner_uname = @pull.from_project.owner.uname
@pull.from_project_name = @pull.from_project.name
@pull.issue.new_pull_request = true
authorize @pull
if @pull.valid? # FIXME more clean/clever logics
@pull.save # set pull id
@pull.reload
@pull.check(false) # don't make event transaction
if @pull.already?
@pull.destroy
flash.now[:error] = I18n.t('projects.pull_requests.up_to_date', to_ref: @pull.to_ref, from_ref: @pull.from_ref)
render :new
else
@pull.send(@pull.status == 'blocked' ? 'block' : @pull.status)
redirect_to project_pull_request_path(@pull.to_project, @pull)
end
else
flash.now[:error] = t('flash.pull_request.save_error')
flash.now[:warning] = @pull.errors.full_messages.join('. ')
if @pull.errors.try(:messages) && @pull.errors.messages[:to_ref].nil? && @pull.errors.messages[:from_ref].nil?
@pull.check(false) # don't make event transaction
load_diff_commits_data
end
render :new
end
end
def merge
authorize @pull
status = @pull.merge!(current_user) ? 200 : 422
render nothing: true, status: status
end
def update
authorize @pull
status = 422
if (action = params[:pull_request_action]) && %w(close reopen).include?(params[:pull_request_action])
if @pull.send("can_#{action}?")
@pull.set_user_and_time current_user
@pull.send(action)
@pull.check if @pull.open?
status = 200
end
end
render nothing: true, status: status
end
def show
if @pull.nil?
redirect_to project_issue_path(@project, @issue)
return
end
load_diff_commits_data
if params[:get_activity] == 'true'
render partial: 'activity', layout: false
elsif params[:get_diff] == 'true'
render partial: 'diff_tab', layout: false
elsif params[:get_commits] == 'true'
render partial: 'commits_tab', layout: false
end
end
def autocomplete_to_project
items = []
term = params[:query].to_s.strip.downcase
[ Project.where(id: @project.pull_requests.last.try(:to_project_id)),
@project.ancestors,
ProjectPolicy::Scope.new(current_user, Project).membered
].each do |p|
items.concat p.by_owner_and_name(term)
end
items = items.uniq{|i| i.id}.select{|e| e.repo.branches.count > 0}
render json: json_for_autocomplete_base(items)
end
protected
# Private: before_action hook which loads Issue.
def load_issue
@issue = @project.issues.find_by!(serial_id: params[:id])
end
# Private: before_action hook which loads PullRequest.
def load_pull
@pull = @issue.pull_request
authorize @pull, :show? if @pull
end
def pull_params
@pull_params ||= subject_params(PullRequest).presence
end
def json_for_autocomplete_base items
items.collect do |project|
{id: project.id.to_s, name: project.name_with_owner}
end
end
def load_diff_commits_data
@commits = @pull.repo.commits_between(@pull.to_commit, @pull.from_commit)
@total_commits = @commits.count
@commits = @commits.last(100)
@stats = @pull.diff_stats
@comments, @commentable = @issue.comments, @issue
end
def find_destination_project bang=true
project = Project.find_by_owner_and_name params[:to_project]
raise ActiveRecord::RecordNotFound if bang && !project
project || @project.pull_requests.last.try(:to_project) || @project.root
end
def set_attrs
if pull_params && pull_params[:issue_attributes]
@pull.issue.title = pull_params[:issue_attributes][:title].presence
@pull.issue.body = pull_params[:issue_attributes][:body].presence
end
@pull.from_project = @project
@pull.to_ref = (pull_params[:to_ref].presence if pull_params) || @pull.to_project.default_head
@pull.from_ref = params[:treeish].presence || (pull_params[:from_ref].presence if pull_params) || @pull.from_project.default_head(params[:treeish])
@pull.from_project_owner_uname = @pull.from_project.owner.uname
@pull.from_project_name = @pull.from_project.name
end
end

View File

@ -1,31 +0,0 @@
class Projects::SubscribesController < Projects::BaseController
before_action :authenticate_user!
before_action :load_issue
def create
authorize @subscribe = @issue.subscribes.build(user_id: current_user.id)
if @subscribe.save
flash[:notice] = I18n.t("flash.subscribe.saved")
redirect_to :back
else
flash[:error] = I18n.t("flash.subscribe.saved_error")
redirect_to :back
end
end
def destroy
authorize @subscribe = @issue.subscribes.find_by(user_id: current_user.id)
@subscribe.destroy
flash[:notice] = t("flash.subscribe.destroyed")
redirect_to :back
end
private
# Private: before_action hook which loads Issue.
def load_issue
authorize @issue = @project.issues.find_by!(serial_id: params[:issue_id]), :show?
end
end

View File

@ -1,287 +0,0 @@
#require 'lib/gollum'
require 'cgi'
class Projects::WikiController < Projects::BaseController
WIKI_OPTIONS = {}
before_action :authenticate_user!
skip_before_action :authenticate_user!, only: [:show, :index, :git, :compare, :compare_wiki, :history, :wiki_history, :search, :pages] if APP_CONFIG['anonymous_access']
before_action :authorize_read_actions, only: [:index, :show, :git, :compare, :compare_wiki, :history, :wiki_history, :search, :pages]
before_action :authorize_write_actions, only: [:edit, :update, :new, :create, :destroy, :revert, :revert_wiki, :preview]
before_action :get_wiki
def index
@name = 'Home'
@page = @wiki.page(@name)
show_or_create_page
end
def show
@name = CGI.unescape(params[:id])
redirect_to project_wiki_index_path(@project) and return if @name == 'Home'
ref = params[:ref].presence || @wiki.ref
@page = @wiki.page(@name, ref)
if !@page && @wiki.page(@name)
flash[:error] = t('flash.wiki.ref_not_exist')
redirect_to project_wiki_path(@project, CGI.escape(@name)) and return
end
show_or_create_page
end
def edit
@name = CGI.unescape(params[:id])
if page = @wiki.page(@name)
@page = page
@content = page.text_data
render :edit
else
render :new
end
end
def update
@name = CGI.unescape(params[:id])
@page = @wiki.page(@name)
name = wiki_page_params[:rename] || @name
update_wiki_page(@wiki, @page, wiki_page_params[:content], {committer: committer}, name, wiki_page_params[:format])
update_wiki_page(@wiki, @page.footer, wiki_page_params[:footer], {committer: committer}) if wiki_page_params[:footer]
update_wiki_page(@wiki, @page.sidebar, wiki_page_params[:sidebar], {committer: committer}) if wiki_page_params[:sidebar]
committer.commit
flash[:notice] = t('flash.wiki.successfully_updated', name: @name)
redirect_to project_wiki_path(@project, CGI.escape(@name))
end
def new
@name = ''
@new = true
end
def create
@name = CGI.unescape(wiki_page_params[:page])
format = wiki_page_params[:format].intern
begin
@wiki.write_page(@name, format, wiki_page_params[:content] || '', {committer: committer}).commit
redirect_to project_wiki_path(@project, CGI.escape(@name))
rescue Gollum::DuplicatePageError => e
flash[:error] = t("flash.wiki.duplicate_page", name: @name)
render :new
end
end
def destroy
@name = CGI.unescape(params[:id])
page = @wiki.page(@name)
if page
@wiki.delete_page(page, {committer: committer}).commit
flash[:notice] = t("flash.wiki.page_successfully_removed")
else
flash[:notice] = t("flash.wiki.page_not_found", name: params[:id])
end
redirect_to project_wiki_index_path(@project)
end
def git
end
def compare
@name = CGI.unescape(params[:id])
if request.post?
@versions = params[:versions] || []
if @versions.size < 2
redirect_to history_project_wiki_path(@project, CGI.escape(@name))
else
redirect_to compare_versions_project_wiki_path(@project, CGI.escape(@name),
sprintf('%s...%s', @versions.last, @versions.first))
end
elsif request.get?
@versions = params[:versions].split(/\.{2,3}/)
if @versions.size < 2
redirect_to history_project_wiki_path(@project, CGI.escape(@name))
return
end
@page = @wiki.page(@name)
@diffs = [@wiki.repo.diff(@versions.first, @versions.last, @page.path).first]
render :compare
else
redirect_to project_wiki_path(@project, CGI.escape(@name))
end
end
def compare_wiki
if request.post?
@versions = params[:versions] || []
versions_string = case @versions.size
when 1 then @versions.first
when 2 then sprintf('%s...%s', @versions.last, @versions.first)
else begin
redirect_to history_project_wiki_index_path(@project)
return
end
end
redirect_to compare_versions_project_wiki_index_path(@project, versions_string)
elsif request.get?
@versions = params[:versions].split(/\.{2,3}/) || []
@diffs = case @versions.size
when 1 then @wiki.repo.commit_diff(@versions.first)
when 2 then @wiki.repo.diff(@versions.first, @versions.last)
else begin
redirect_to history_project_wiki_index_path(@project)
return
end
end
render :compare
else
redirect_to project_wiki_path(@project, CGI.escape(@name))
end
end
def revert
@name = CGI.unescape(params[:id])
@page = @wiki.page(@name)
sha1 = params[:sha1]
sha2 = params[:sha2]
sha2 = nil if params[:sha2] == 'prev'
if c = @wiki.revert_page(@page, sha1, sha2, {committer: committer}) and c.commit
flash[:notice] = t("flash.wiki.revert_success")
redirect_to project_wiki_path(@project, CGI.escape(@name))
else
# if revert wasn't successful then redirect back to comparsion.
# if second commit version is missed, then second version is
# params[:sha1] and first version is parent of params[:sha1]
# (see Gollum::Wiki#revert_page)
sha2, sha1 = sha1, "#{sha1}^" if !sha2
@versions = [sha1, sha2]
diffs = @wiki.repo.diff(@versions.first, @versions.last, @page.path)
@diffs = [diffs.first]
flash[:error] = t("flash.wiki.patch_does_not_apply")
render :compare
end
end
def revert_wiki
sha1 = params[:sha1]
sha2 = params[:sha2]
sha2 = nil if sha2 == 'prev'
if c = @wiki.revert_commit(sha1, sha2, {committer: committer}) and c.commit
flash[:notice] = t("flash.wiki.revert_success")
redirect_to project_wiki_index_path(@project)
else
sha2, sha1 = sha1, "#{sha1}^" if !sha2
@versions = [sha1, sha2]
@diffs = @wiki.repo.diff(@versions.first, @versions.last)
flash[:error] = t("flash.wiki.patch_does_not_apply")
render :compare
end
end
def preview
@name = wiki_page_params[:page]
@page = @wiki.preview_page(@name, wiki_page_params[:content], wiki_page_params[:format])
@content = @page.formatted_data
@editable = false
render :show
end
def history
@name = CGI.unescape(params[:id])
if @page = @wiki.page(@name)
@versions = @page.versions
else
redirect_to :back
end
end
def wiki_history
@versions = @wiki.log
render :history
end
def search
@query = params[:q]
@results = @wiki.search @query
end
def pages
@results = @wiki.pages
@ref = @wiki.ref
end
protected
def get_wiki
@wiki = Gollum::Wiki.new(@project.wiki_path,
WIKI_OPTIONS.merge(base_path: project_wiki_index_path(@project)))
end
# This method was grabbed from sinatra application, shipped with Gollum gem.
# See Gollum gem and Gollum License if you have any questions about license notes.
# https://github.com/github/gollum https://github.com/github/gollum/blob/master/LICENSE
def update_wiki_page(wiki, page, content, commit_msg, name = nil, format = nil)
return if !page ||
((!content || page.raw_data == content) && page.format == format)
name ||= page.name
format = (format || page.format).to_sym
content ||= page.raw_data
wiki.update_page(page, name, format, content.to_s, commit_msg)
end
def commit_message
msg = wiki_page_params[:message].presence
unless msg
msg = case action_name.to_s
when 'create' then "Created page #{@name.to_s}"
when 'update' then "Updated page #{@name.to_s}"
when 'destroy' then "Removed page #{@name.to_s}"
when 'revert' then "Reverted page #{@name.to_s}"
when 'revert_wiki' then "Reverted wiki"
end
msg << " (#{wiki_page_params[:format]})" if wiki_page_params[:format]
end
msg = 'Unhandled action' if !msg || msg.empty?
{ message: msg }
end
def committer
unless @committer
p = commit_message.merge({name: current_user.uname, email: current_user.email})
@committer = Gollum::Committer.new(@wiki, p)
GitHook.perform_later!(:notification, :process, {project_id: @project.id, actor_name: @committer.actor.name, commit_sha: @committer.commit})
end
@committer
end
def show_or_create_page
if @page
@content = @page.formatted_data
@editable = policy(@project).write?
render :show
elsif file = @wiki.file(@name)
render text: file.raw_data, content_type: file.mime_type
elsif policy(@project).write?
@new = true
render :new
else
redirect_to action: :index #forbidden_path
end
end
def wiki_page_params
@wiki_page_params ||= params[:wiki_page] || {}
end
def authorize_read_actions
authorize @project, :show?
end
def authorize_write_actions
authorize @project, :write?
end
end

View File

@ -1,63 +0,0 @@
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
def facebook
oauthorize 'Facebook'
end
def google_oauth2
oauthorize 'google_oauth2'
end
def github
oauthorize 'GitHub'
end
def passthru
render file: "#{Rails.root}/public/404.html", status: 404, layout: false
end
private
def oauthorize(kind)
provider = kind.downcase
@user = find_for_ouath(env["omniauth.auth"], current_user)
if @user && @user.persisted?
flash[:notice] = I18n.t "devise.omniauth_callbacks.success", kind: action_name.classify
sign_in_and_redirect @user, event: :authentication
else
session["devise.#{provider}_data"] = env["omniauth.auth"]
redirect_to new_user_registration_url
end
end
def find_for_ouath(auth, resource=nil)
provider, uid = auth['provider'], auth['uid']
authentication = Authentication.find_or_initialize_by(provider: provider, uid: uid)
if authentication.new_record?
if user_signed_in? # New authentication method for current_user
authentication.user = current_user
else # Register new user from session
case provider
when 'facebook'
name = auth['extra']['raw_info']['name']
when 'google_oauth2', 'github'
name = auth['info']['nickname'] || auth['info']['name']
else
raise 'Provider #{provider} not handled'
end
user = User.find_or_initialize_by email: auth['info']['email']
if user.new_record?
user.name = name
user.uname = name.gsub(/\s/, '').underscore
user.password = Devise.friendly_token[0,20]
user.confirmed_at = Time.zone.now
user.save
end
authentication.user = user
end
authentication.save
end
return authentication.user
end
end

View File

@ -1,24 +0,0 @@
class Users::RegisterRequestsController < ApplicationController
before_action :user_choose_locale
layout 'invite'
def new
if APP_CONFIG['preregistration']
render :invite
else
redirect_to new_user_registration_path
end
end
def create
params[:register_request][:language] = I18n.locale if params[:register_request]
RegisterRequest.create(params[:register_request])
render :thanks
end
protected
def user_choose_locale
I18n.locale = params[:format] if User::LANGUAGES.include?(params[:format])
end
end

View File

@ -1,8 +1,4 @@
module ActivityFeedsHelper module ActivityFeedsHelper
def render_activity_feed(activity_feed)
render activity_feed.partial, activity_feed.data.merge(activity_feed: activity_feed)
end
def get_feed_title_from_content(content) def get_feed_title_from_content(content)
# removes html tags and haml generator indentation whitespaces and new line chars: # removes html tags and haml generator indentation whitespaces and new line chars:
feed_title = strip_tags(content).gsub(/(^\s+|\n| )/, ' ') feed_title = strip_tags(content).gsub(/(^\s+|\n| )/, ' ')

View File

@ -1,21 +0,0 @@
module AdvisoriesHelper
def advisories_select_options(advisories, opts = {class: 'popoverable'})
def_values = [[t("layout.advisories.no_"), 'no'], [t("layout.advisories.new"), 'new'], [t("layout.advisories.existing"), 'existing', {class: 'advisory_id'}]]
options_for_select(def_values, def_values.first)
end
def advisory_id_for_hint
sprintf(Advisory::ID_STRING_TEMPLATE, type: "{#{Advisory::TYPES.values.join(',')}}",
year: 'YYYY', id: 'XXXX')
end
def construct_ref_link(ref)
ref = sanitize(ref)
url = if ref =~ %r[^http(s?)://*]
ref
else
'http://' << ref
end
link_to url, url
end
end

View File

@ -47,15 +47,12 @@ module ApplicationHelper
'fa-cogs' 'fa-cogs'
when :groups when :groups
'fa-users' 'fa-users'
when :advisories
'fa-newspaper-o'
when :statistics when :statistics
'fa-area-chart' 'fa-area-chart'
end end
end end
def title_object(object) def title_object(object)
return object.advisory_id if object.class == Advisory
name = object.class == Group ? object.uname : object.name name = object.class == Group ? object.uname : object.name
object_name = t "activerecord.models.#{object.class.name.downcase}" object_name = t "activerecord.models.#{object.class.name.downcase}"
case object.class.name case object.class.name

View File

@ -82,17 +82,6 @@ module BuildListsHelper
end end
end end
def build_list_classified_update_types
advisoriable = BuildList::RELEASE_UPDATE_TYPES.map do |el|
[el, {class: 'advisoriable'}]
end
nonadvisoriable = (BuildList::UPDATE_TYPES - BuildList::RELEASE_UPDATE_TYPES).map do |el|
[el, {class: 'nonadvisoriable'}]
end
return advisoriable + nonadvisoriable
end
def build_list_item_version_link(item, str_version = false) def build_list_item_version_link(item, str_version = false)
hash_size=5 hash_size=5
if item.version =~ /^[\da-z]+$/ && item.name == item.build_list.project.name if item.version =~ /^[\da-z]+$/ && item.name == item.build_list.project.name
@ -331,4 +320,12 @@ module BuildListsHelper
checked = build_list.auto_create_container if checked.nil? checked = build_list.auto_create_container if checked.nil?
checked checked
end end
def short_hash_id(id)
id[0..19]
end
def shortest_hash_id(id, size=10)
id[0..size-1]
end
end end

View File

@ -1,29 +0,0 @@
module CommentsHelper
def project_commentable_comment_path(project, commentable, comment)
if Comment.issue_comment?(commentable.class)
project_issue_comment_path(project, commentable, comment)
elsif Comment.commit_comment?(commentable.class)
project_commit_comment_path(project, commentable, comment)
end
end
def project_commentable_path(project, commentable)
if Comment.issue_comment?(commentable.class)
polymorphic_path [project, commentable.pull_request ? commentable.pull_request : commentable]
elsif Comment.commit_comment?(commentable.class)
commit_path project, commentable.id
end
end
def project_commentable_comments_path(project, commentable)
if commentable.is_a? Issue
project_issue_comments_path(@project, @commentable)
elsif commentable.is_a? Grit::Commit
project_commit_comments_path(@project, @commentable)
end
end
def comment_anchor c
"#{(c.data.present? && c.actual_inline_comment?) ? 'diff-' : ''}comment#{c.id}"
end
end

View File

@ -1,196 +0,0 @@
module CommitHelper
MAX_FILES_WITHOUT_COLLAPSE = 25
def render_commit_stats(options = {})
stats = options[:stats]
diff = options[:diff]
repo = options[:repo]
commit = options[:commit]
parent_commit = commit.parents.try(:first)
res = ["<ul class='list-group boffset0'>"]
ind=0
stats.files.each do |filename, adds, deletes, total|
file_name = get_filename_in_diff(diff[ind], filename)
file_status = t "layout.projects.diff.#{get_file_status_in_diff(diff[ind])}"
res << "<li class='list-group-item'>"
res << "<div class='row'>"
res << "<div class='col-sm-8'>"
res << "<a href='#diff-#{ind}' data-toggle='tooltip' data-placement='top' title='#{file_status}'>"
res << "#{diff_file_icon(diff[ind])} #{h(file_name)}"
res << "</a></div>"
res << render_file_changes(diff: diff[ind], adds: adds, deletes: deletes, total: total,
repo: repo, commit: commit, parent_commit: parent_commit, file_status: file_status)
res << "</div"
res << "</li>"
ind +=1
end
res << "</ul>"
wrap_commit_header_list(stats, res)
end
def wrap_commit_header_list(stats, list)
is_stats_open = stats.files.count <= MAX_FILES_WITHOUT_COLLAPSE ? 'in' : ''
res = ["<div class='panel-group' id='diff_header' role='tablist' aria-multiselectable='false'>"]
res << "<div class='panel panel-default'>"
res << "<div class='panel-heading' role='tab' id='heading'>"
res << "<h4 class='panel-title'>"
res << "<a data-toggle='collapse' data-parent='#diff_header' href='#collapseList' aria-expanded='true' aria-controls='collapseList'>"
res << "<span class='fa fa-chevron-#{is_stats_open ? 'down' : 'up'}'></span>"
res << " #{diff_commit_header_message(stats)}</a>"
res << "</h4>"
res << "</div>"
res << "<div id='collapseList' class='panel-collapse collapse #{is_stats_open}' role='tabpanel' aria-labelledby='collapseList'>"
res << "<div class='panel-body'>"
res += list
res << "</div>"
res << "</div>"
res << "</div>"
res << "</div>"
res.join("\n").html_safe
end
def diff_commit_header_message(stats)
t("layout.projects.diff_show_header",
files: t("layout.projects.commit_files_count", count: stats.files.size),
additions: t("layout.projects.commit_additions_count", count: stats.additions),
deletions: t("layout.projects.commit_deletions_count", count: stats.deletions))
end
def commit_date(date)
I18n.localize(date, { format: "%d %B %Y" })
end
def short_hash_id(id)
id[0..19]
end
def shortest_hash_id(id, size=10)
id[0..size-1]
end
def commit_author_link(author)
name = author.name
email = author.email
u = User.where(email: email).first
u.present? ? link_to(name, user_path(u)) : mail_to(email, name)
end
def commits_pluralize(commits_count)
Russian.p(commits_count, *commits_pluralization_arr)
end
def is_file_open_in_diff(blob, diff)
return true if blob.binary? && blob.render_as == :image
return true if diff.diff.blank? && diff.a_mode != diff.b_mode
diff.diff.present? && diff.diff.split("\n").count <= DiffHelper::MAX_LINES_WITHOUT_COLLAPSE
end
def file_blob_in_diff(repo, commit_id, diff)
return if repo.nil? || commit_id.nil? || diff.nil?
tree = repo.tree(commit_id)
blob = diff.renamed_file ? (tree / diff.b_path) : (tree / (diff.a_path || diff.b_path))
blob || diff.a_blob || diff.b_blob
end
def get_commit_id_for_file(diff, commit, parent_commit)
diff.deleted_file ? parent_commit.id : commit.id
end
def get_file_status_in_diff(diff)
if diff.renamed_file
:renamed_file
elsif diff.new_file
:new_file
elsif diff.deleted_file
:deleted_file
else
:changed_file
end
end
def get_filename_in_diff(diff, filename)
if diff.renamed_file
"#{diff.a_path.rtruncate 50} => #{diff.b_path.rtruncate 50}"
else
filename.rtruncate(100)
end
end
protected
def commits_pluralization_arr
pluralize ||= t('layout.commits.pluralize').map {|base, title| title.to_s}
end
def render_file_changes(options = {})
diff = options[:diff]
adds = options[:adds]
deletes = options[:deletes]
total = options[:total]
repo = options[:repo]
file_status = options[:file_status]
commit_id = get_commit_id_for_file(diff, options[:commit], options[:parent_commit])
blob = file_blob_in_diff(repo, commit_id, diff)
res = ''
res << "<div class='col-sm-3'>"
res << "<div class='pull-right'>"
if blob.binary?
res << "<strong class='text-primary'>#{t 'layout.projects.diff.binary'} #{file_status}</strong>"
elsif total > 0
res << "<strong class='text-success'>+#{adds}</strong> <strong class='text-danger'>-#{deletes}</strong>"
else # total == 0
res << "<strong class='text-primary'>#{t 'layout.projects.diff.without_changes'}</strong>"
end
res << "</div>"
res << "</div>"
res << "<div class='col-sm-1'>"
res << render_progress_bar(adds, deletes, total, blob)
res << "</div>"
end
def render_progress_bar(adds, deletes, total, blob)
res = ''
pluses = 0
minuses = 0
if total > 0
pluses = ((adds/(adds+deletes).to_f)*100).round
minuses = 100 - pluses
end
title = if total >0
t 'layout.projects.inline_changes_count', count: total
elsif !blob.binary?
t 'layout.projects.diff.without_changes'
else
'BIN'
end
res << "<div class='progress' style='margin-bottom: 0' data-toggle='tooltip' data-placement='top' title='#{title}'>"
res << "<div class='progress-bar progress-bar-success' style='width: #{pluses}%'></div>"
res << "<div class='progress-bar progress-bar-danger' style='width: #{minuses}%'></div>"
res << "</div>"
res
end
def diff_file_icon(diff)
icon = case get_file_status_in_diff(diff)
when :renamed_file
'fa-caret-square-o-right text-info'
when :new_file
'fa-plus-square text-success'
when :deleted_file
'fa-minus-square text-danger'
when :changed_file
'fa-pencil-square text-primary'
else
'fa-exclamation-circle text-danger'
end
"<i class='fa #{icon}'></i>"
end
end

View File

@ -1,332 +0,0 @@
module DiffHelper
include CommitHelper
MAX_LINES_WITHOUT_COLLAPSE = 50
def render_diff_stats(options = {})
stats = options[:stats]
diff = options[:diff]
repo = options[:repo]
commit = options[:commit]
parent_commit = options[:common_ancestor]
res = ["<ul class='list-group boffset0'>"]
stats.each_with_index do |stat, ind|
adds = stat.additions
deletes = stat.deletions
total = adds + deletes
file_name = get_filename_in_diff(diff[ind], stat.filename)
file_status = t "layout.projects.diff.#{get_file_status_in_diff(diff[ind])}"
res << "<li class='list-group-item'>"
res << "<div class='row'>"
res << "<div class='col-sm-8'>"
res << "<a href='#diff-#{ind}' data-toggle='tooltip' data-placement='top' title='#{file_status}'>"
res << "#{diff_file_icon(diff[ind])} #{h(file_name)}"
res << "</a></div>"
res << render_file_changes(diff: diff[ind], adds: adds, deletes: deletes, total: total,
repo: repo, commit: commit, parent_commit: parent_commit, file_status: file_status)
res << "</div"
res << "</li>"
ind +=1
end
res << "</ul>"
wrap_diff_header_list(stats, res)
end
def wrap_diff_header_list(stats, list)
is_stats_open = stats.count <= MAX_FILES_WITHOUT_COLLAPSE ? 'in' : ''
res = ["<div class='panel-group' id='diff_header' role='tablist' aria-multiselectable='false'>"]
res << "<div class='panel panel-default'>"
res << "<div class='panel-heading' role='tab' id='heading'>"
res << "<h4 class='panel-title'>"
res << "<a data-toggle='collapse' data-parent='#diff_header' href='#collapseList' aria-expanded='true' aria-controls='collapseList'>"
res << "<span class='fa fa-chevron-#{is_stats_open ? 'down' : 'up'}'></span>"
res << " #{diff_header_message(stats)}</a>"
res << "</h4>"
res << "</div>"
res << "<div id='collapseList' class='panel-collapse collapse #{is_stats_open}' role='tabpanel' aria-labelledby='collapseList'>"
res << "<div class='panel-body'>"
res += list
res << "</div>"
res << "</div>"
res << "</div>"
res << "</div>"
res.join("\n").html_safe
end
def diff_header_message(stats)
total_additions = stats.inject(0) {|sum, n| sum + n.additions}
total_deletions = stats.inject(0) {|sum, n| sum + n.deletions}
I18n.t('layout.projects.diff_show_header',
files: t('layout.projects.commit_files_count', count: stats.count),
additions: t('layout.projects.commit_additions_count', count: total_additions),
deletions: t('layout.projects.commit_deletions_count', count: total_deletions))
end
#include Git::Diff::InlineCallback
def render_diff(diff, args = {})#diff_counter, comments, opts = nil diffpath = nil)
if diff.respond_to?(:diff)
diff, filepath, in_discussion = diff.diff, diff.a_path, false
comments = (args[:comments] || []).select{|c| c.data.try('[]', :path) == filepath}
else
filepath, in_discussion, comments = args[:diffpath], true, args[:comments]
end
diff_display ||= Diff::Display::Unified.new(diff)
url = if @pull
@pull.id ? polymorphic_path([@project, @pull]) : ''
elsif @commit
commit_path @project, @commit
end
prepare(args.merge({filepath: filepath, comments: comments, in_discussion: in_discussion}))
res = '<div class="table-responsive overflow-auto">'
res << '<table class="table diff inline table-borderless" cellspacing="0" cellpadding="0">'
res << '<tbody>'
res << renderer(diff_display.data) #diff_display.render(Git::Diff::InlineCallback.new comments, path)
res << tr_line_comments(comments) if in_discussion
res << '</tbody>'
res << '</table>'
res << '</div>'
res.html_safe
end
########################################################
# FIXME: Just to dev, remove to lib. Really need it?
########################################################
def prepare(args)
@url, @diff_counter, @in_discussion = args[:url], args[:diff_counter], args[:in_discussion]
@filepath, @line_comments = args[:filepath], args[:comments]
@diff_prefix = args[:diff_prefix] || 'diff'
@add_reply_id, @num_line = if @in_discussion
[@line_comments[0].id, @line_comments[0].data[:line].to_i - @line_comments[0].data[:strings].lines.count.to_i-1]
else
[nil, -1]
end
@no_commit_comment = true if params[:controller] == 'projects/wiki' || (params[:action] == 'diff')
end
def headerline(line)
set_line_number
"<tr class='header'>
<td class='line_numbers'>...</td>
<td class='line_numbers'>...</td>
<td class='header'>#{line}</td>
</tr>"
end
def addline(line)
set_line_number
"<tr class='changes'>
<td class='line_numbers'></td>
#{td_line_link "#{@diff_prefix}-F#{@diff_counter}R#{line.new_number}", line.new_number}
<td class='code ins'>
#{line_comment_icon}
<pre ng-non-bindable>#{render_line(line)}</pre>
</td>
</tr>
#{render_line_comments}"
end
def remline(line)
set_line_number
"<tr class='changes'>
#{td_line_link "#{@diff_prefix}-F#{@diff_counter}L#{line.old_number}", line.old_number}
<td class='line_numbers'></td>
<td class='code del'>
#{line_comment_icon}
<pre ng-non-bindable>#{render_line(line)}</pre>
</td>
</tr>
#{render_line_comments}"
end
def modline(line)
set_line_number
"<tr class='changes line'>
#{td_line_link "#{@diff_prefix}-F#{@diff_counter}L#{line.old_number}", line.old_number}
#{td_line_link "#{@diff_prefix}-F#{@diff_counter}R#{line.new_number}", line.new_number}
<td class='code unchanged modline'>
#{line_comment_icon}
<pre ng-non-bindable>#{render_line(line)}</pre>
</td>
</tr>
#{render_line_comments}"
end
def unmodline(line)
set_line_number
"<tr class='changes unmodline'>
#{td_line_link "#{@diff_prefix}-F#{@diff_counter}L#{line.old_number}", line.old_number}
#{td_line_link "#{@diff_prefix}-F#{@diff_counter}R#{line.new_number}", line.new_number}
<td class='code unchanged unmodline'>
#{line_comment_icon}
<pre ng-non-bindable>#{render_line(line)}</pre>
</td>
</tr>
#{render_line_comments}"
end
def sepline(line)
"<tr class='changes hunk-sep'>
<td class='line_numbers line_num_cut'>&hellip;</td>
<td class='line_numbers line_num_cut'>&hellip;</td>
<td class='code cut-line'></td>
</tr>"
end
def nonewlineline(line)
set_line_number
"<tr class='changes'>
#{td_line_link "#{@diff_prefix}-F#{@diff_counter}L#{line.old_number}", line.old_number}
#{td_line_link "#{@diff_prefix}-F#{@diff_counter}R#{line.new_number}", line.new_number}
<td class='code modline unmodline'>
#{line_comment_icon}
<pre ng-non-bindable>#{render_line(line)}</pre>
</td>
</tr>
#{render_line_comments}"
end
def before_headerblock(block)
end
def after_headerblock(block)
end
def before_unmodblock(block)
end
def before_modblock(block)
end
def before_remblock(block)
end
def before_addblock(block)
end
def before_sepblock(block)
end
def before_nonewlineblock(block)
end
def after_unmodblock(block)
end
def after_modblock(block)
end
def after_remblock(block)
end
def after_addblock(block)
end
def after_sepblock(block)
end
def after_nonewlineblock(block)
end
def new_line
""
end
def renderer(data)
result = []
data.each do |block|
result << send("before_" + classify(block), block)
result << block.map { |line| send(classify(line), line) }
result << send("after_" + classify(block), block)
end
result.compact.join(new_line)
end
protected
def classify(object)
object.class.name[/\w+$/].downcase
end
def escape(str)
str.to_s.gsub('&', '&amp;').gsub('<', '&lt;').gsub('>', '&gt;').gsub('"', '&#34;')
end
def render_line(line)
res = '<span class="diff-content">'
if line.inline_changes?
prefix, changed, postfix = line.segments.map{|segment| escape(segment) }
res << "#{prefix}<span class='idiff'>#{changed}</span>#{postfix}"
else
res << escape(line)
end
res << '</span>'
res
end
def set_line_number
@num_line = @num_line.succ
end
def line_comment_icon
return if @no_commit_comment || (@in_discussion && @add_reply_id && @line_comments[0].data[:line].to_i != @num_line)
if current_user
link_to image_tag('line_comment.png', alt: t('layout.comments.new_header')),
'#new_inline_comment',
class: 'add_line-comment',
'ng-click' => "commentsCtrl.showInlineForm($event, #{new_inline_comment_params.to_json})"
end
end
def render_line_comments
unless @no_commit_comment || @in_discussion
comments = @line_comments.select do |c|
c.data.try('[]', :line).to_s == @num_line.to_s && c.actual_inline_comment?
end
tr_line_comments(comments) if comments.count > 0
end
end
def td_line_link id, num
"<td class='line_numbers' id='#{id}'><a href='#{@url}##{id}'>#{num}</a></td>"
end
def tr_line_comments comments
return if @no_commit_comment
res="<tr class='line-comments'>
<td class='line_numbers' colspan='2'>#{comments.count}</td>
<td>"
comments.each do |comment|
res << "<div class='line-comment'>
#{render 'projects/comments/comment', comment: comment, data: {project: @project, commentable: @commentable, add_anchor: 'inline', in_discussion: @in_discussion}}
</div>"
end
if current_user
res << link_to( t('layout.comments.new_inline'),
'#new_inline_comment',
class: 'btn btn-primary',
'ng-click' => "commentsCtrl.showInlineForm($event, #{new_inline_comment_params.to_json})",
'ng-hide' => "commentsCtrl.hideInlineCommentButton(#{new_inline_comment_params.to_json})" )
end
res << "</td></tr>"
end
# def new_comment_path
# hash = {path: @filepath, line: @num_line}
# if @commentable.is_a? Issue
# project_new_line_pull_comment_path(@project, @commentable, hash.merge({in_reply: @add_reply_id}))
# elsif @commentable.is_a? Grit::Commit
# new_line_commit_comment_path(@project, @commentable, hash)
# end
# end
def new_inline_comment_params
{ path: @filepath, line: @num_line, in_reply: @add_reply_id }
end
end

View File

@ -52,8 +52,6 @@ module FacebookHelper
@group @group
when Users::BaseController when Users::BaseController
@user @user
when Projects::Git::BaseController
@project
else else
instance_variable_get "@#{controller_name.singularize}" instance_variable_get "@#{controller_name.singularize}"
end end

View File

@ -1,92 +1,4 @@
module GitHelper module GitHelper
def submodule_url(node, treeish)
# node.url(treeish) looks like:
# - http://0.0.0.0:3000/abf/git@abf.rosalinux.ru:abf/rhel-scripts.git
# - git://github.com/avokhmin/mdv-scripts.git
# - empty string if ".gitmodules" does not exist
url = node.url(treeish)
return nil if url.blank?
url.gsub!(/.git$/, '')
if url =~ /^git:/
url.gsub!(/^git/, 'http')
elsif str = /git@.*:.*/.match(url)
str = str[0].gsub(/^git@/, '')
domen = str.gsub(/:.*/, '')
owner = str.gsub(/^#{domen}:/, '').gsub(/\/.*/, '')
project = str.gsub(/.*\//, '')
url = "http://#{domen}/#{owner}/#{project}"
end
url
end
def render_path
# TODO: Looks ugly, rewrite with clear mind.
if @path.present?
if @treeish == @project.resolve_default_branch
res = "#{link_to @project.name, tree_path(@project)} / "
else
res = "#{link_to @project.name, tree_path(@project, @treeish)} / "
end
parts = @path.split("/")
current_path = parts.first
res << (parts.length == 1 ? parts.first : link_to(parts.first, tree_path(@project, @treeish, current_path)) + " / ")
parts[1..-2].each do |part|
current_path = File.join([current_path, part].compact)
res << link_to(part, tree_path(@project, @treeish, current_path))
res << " / "
end
res << parts.last if parts.length > 1
else
res = "#{link_to @project.name, tree_path(@project)} /"
end
res.html_safe
end
def render_line_numbers(n)
res = ""
1.upto(n){ |i| res << "<span id='L#{i}'><a href='#L#{i}'>#{i}</a></span><br/>" }
res.html_safe
end
def iterate_path(path)
tree = []
path.split("\/").each do |name|
if tree.last
tree << [File.join(tree.try(:last).try(:first), name), name]
else
tree << [name, name]
end
end
tree
end
def branch_selector_options(project)
p, tag_enabled = params.dup, !(controller_name == 'trees' && action_name == 'branches')
p.delete(:path) if p[:path].present? # to root path
p.merge!(project_id: project.id, treeish: project.resolve_default_branch).delete(:id) unless p[:treeish].present?
current = url_for(p).split('?', 2).first
res = []
if params[:treeish].present? && !project.repo.branches_and_tags.map(&:name).include?(params[:treeish])
res << [I18n.t('layout.git.repositories.commits'), [params[:treeish].truncate(20)]]
end
linking = Proc.new {|name| [name.truncate(20), url_for(p.merge treeish: name).split('?', 2).first]}
res << [I18n.t('layout.git.repositories.branches'), project.repo.branches.map(&:name).sort.map(&linking)]
if tag_enabled
res << [I18n.t('layout.git.repositories.tags'), project.repo.tags.map(&:name).sort.map(&linking)]
else
res << [I18n.t('layout.git.repositories.tags'), project.repo.tags.map(&:name).sort.map {|name| [name.truncate(20), {disabled: true}]}]
end
grouped_options_for_select(res, current)
end
def versions_for_group_select(project) def versions_for_group_select(project)
return [] unless project return [] unless project
[ [
@ -94,46 +6,4 @@ module GitHelper
[I18n.t('layout.git.repositories.tags'), project.github_tags.map(&:name).sort] [I18n.t('layout.git.repositories.tags'), project.github_tags.map(&:name).sort]
] ]
end end
def split_commits_by_date(commits)
# See: https://github.com/gitlabhq/gitlabhq/blob/master/app/views/projects/commits/_commits.html.haml#L1
commits.sort{|x, y| y.committed_date <=> x.committed_date}.inject({}) do |h, commit|
dt = commit.committed_date
h[dt.year] ||= {}
h[dt.year][dt.month] ||= {}
h[dt.year][dt.month][dt.day] ||= []
h[dt.year][dt.month][dt.day] << commit
h
end
end
def blob_highlight(blob)
return if blob.nil? || blob.data.blank?
result = if blob.mime_type == 'text/rpm-spec'
Pygments.highlight blob.data, highlight_options.merge(lexer: 'spec')
else
blob.colorize(highlight_options)
end
result.present? ? result.html_safe : blob.data
rescue MentosError, Yajl::ParseError => e
blob.data.html_safe
end
def blame_highlight(blob, text)
return if blob.nil? || text.blank?
result = if blob.mime_type == 'text/rpm-spec'
Pygments.highlight(text, lexer: 'spec')
else
blob.lexer.highlight text
end
result.present? ? result.html_safe : text
rescue MentosError, Yajl::ParseError => e
text.html_safe
end
protected
def highlight_options
@highlight ||= { options: { linenos: true, lineanchors: 'lc', linespans: 'ln', anchorlinenos: true }}
end
end end

View File

@ -1,63 +0,0 @@
# This module is based on
# https://github.com/gitlabhq/gitlabhq/blob/7665b1de7eed4addd7b94786c84e6674710e6377/app/helpers/gitlab_markdown_helper.rb
module GitlabMarkdownHelper
include MarkdownHelper
# Use this in places where you would normally use link_to(gfm(...), ...).
#
# It solves a problem occurring with nested links (i.e.
# "<a>outer text <a>gfm ref</a> more outer text</a>"). This will not be
# interpreted as intended. Browsers will parse something like
# "<a>outer text </a><a>gfm ref</a> more outer text" (notice the last part is
# not linked any more). link_to_gfm corrects that. It wraps all parts to
# explicitly produce the correct linking behavior (i.e.
# "<a>outer text </a><a>gfm ref</a><a> more outer text</a>").
def link_to_gfm(body, url, html_options = {})
return "" if body.blank?
escaped_body = if body =~ /^\<img/
body
else
escape_once(body)
end
gfm_body = gfm(escaped_body, html_options)
gfm_body.gsub!(%r{<a.*?>.*?</a>}m) do |match|
"</a>#{match}#{link_to("", url, html_options)[0..-5]}" # "</a>".length +1
end
link_to(gfm_body.html_safe, url, html_options)
end
def markdown(text)
return '' if text.blank?
unless @markdown
gitlab_renderer = Redcarpet::Render::GitlabHTML.new(self,
# see https://github.com/vmg/redcarpet#darling-i-packed-you-a-couple-renderers-for-lunch-
filter_html: true,
with_toc_data: true,
hard_wrap: true)
@markdown = Redcarpet::Markdown.new(gitlab_renderer,
# see https://github.com/vmg/redcarpet#and-its-like-really-simple-to-use
no_intra_emphasis: true,
tables: true,
fenced_code_blocks: true,
autolink: true,
strikethrough: true,
lax_html_blocks: true,
space_after_headers: true,
superscript: true)
end
@markdown.render(text).html_safe
end
def render_wiki_content(wiki_page)
if wiki_page.format == :markdown
markdown(wiki_page.content)
else
wiki_page.formatted_content.html_safe
end
end
end

View File

@ -1,2 +0,0 @@
module HooksHelper
end

View File

@ -1,8 +0,0 @@
module IssuesHelper
def tracker_search_field(name, txt, classes = nil)
str = "<input name='#{name}' id='#{name}' type='text' value='#{txt}'"
str << "onblur=\"if(this.value==''){this.value='#{txt}';this.className='gray #{classes}';}\""
str << "onclick=\"if(this.value=='#{txt}'){this.value='';this.className='black #{classes}';}\" class=\"gray #{classes}\">"
str.html_safe
end
end

View File

@ -1,176 +0,0 @@
# This module is based on
# https://github.com/gitlabhq/gitlabhq/blob/397c3da9758c03a215a308c011f94261d9c61cfa/lib/gitlab/markdown.rb
# Custom parser for GitLab-flavored Markdown
#
# It replaces references in the text with links to the appropriate items in
# GitLab.
#
# Supported reference formats are:
# * @foo for team members
# * for issues & pull requests:
# * #123
# * abf#123
# * abf/rosa-build#123
# * 123456 for commits
#
# It also parses Emoji codes to insert images. See
# http://www.emoji-cheat-sheet.com/ for a list of the supported icons.
#
# Examples
#
# >> gfm("Hey @david, can you fix this?")
# => "Hey <a href="/users/david">@david</a>, can you fix this?"
#
# >> gfm("Commit 35d5f7c closes #1234")
# => "Commit <a href="/gitlab/commits/35d5f7c">35d5f7c</a> closes <a href="/gitlab/issues/1234">#1234</a>"
#
# >> gfm(":trollface:")
# => "<img alt=\":trollface:\" class=\"emoji\" src=\"/images/trollface.png" title=\":trollface:\" />
module MarkdownHelper
include IssuesHelper
attr_reader :html_options
# Public: Parse the provided text with GitLab-Flavored Markdown
#
# text - the source text
# html_options - extra options for the reference links as given to link_to
#
# Note: reference links will only be generated if @project is set
def gfm(text, html_options = {})
return text if text.nil?
# Duplicate the string so we don't alter the original, then call to_str
# to cast it back to a String instead of a SafeBuffer. This is required
# for gsub calls to work as we need them to.
text = text.dup.to_str
@html_options = html_options
# Extract pre blocks so they are not altered
# from http://github.github.com/github-flavored-markdown/
text.gsub!(%r{<pre>.*?</pre>|<code>.*?</code>}m) { |match| extract_piece(match) }
# Extract links with probably parsable hrefs
text.gsub!(%r{<a.*?>.*?</a>}m) { |match| extract_piece(match) }
# Extract images with probably parsable src
text.gsub!(%r{<img.*?>}m) { |match| extract_piece(match) }
# TODO: add popups with additional information
text = parse(text)
# Insert pre block extractions
text.gsub!(/\{gfm-extraction-(\h{32})\}/) do
insert_piece($1)
end
sanitize text.html_safe, attributes: %w(href src alt id class)
end
private
def extract_piece(text)
@extractions ||= {}
md5 = Digest::MD5.hexdigest(text)
@extractions[md5] = text
"{gfm-extraction-#{md5}}"
end
def insert_piece(id)
@extractions[id]
end
# Private: Parses text for references and emoji
#
# text - Text to parse
#
# Note: reference links will only be generated if @project is set
#
# Returns parsed text
def parse(text)
parse_references(text) if @project
parse_emoji(text)
end
REFERENCE_PATTERN = %r{
(?<prefix>[\W\/])? # Prefix
( # Reference
@(?<user>[a-zA-Z][a-zA-Z0-9_\-\.]*) # User/Group uname
|(?<issue>(?:[a-zA-Z0-9\-_]*\/)?(?:[a-zA-Z0-9\-_]*)?\#[0-9]+) # Issue ID
|(?<commit>[\h]{6,40}) # Commit ID
)
(?<suffix>\W)? # Suffix
}x.freeze
TYPES = [:user, :issue, :commit].freeze
def parse_references(text)
# parse reference links
text.gsub!(REFERENCE_PATTERN) do |match|
prefix = $~[:prefix]
suffix = $~[:suffix]
type = TYPES.select{|t| !$~[t].nil?}.first
identifier = $~[type]
# Avoid HTML entities
if prefix && suffix && prefix[0] == '&' && suffix[-1] == ';'
match
elsif ref_link = reference_link(type, identifier)
"#{prefix}#{ref_link}#{suffix}"
else
match
end
end
end
def parse_emoji(text)
text.gsub(/:([\w+-]+):/) do |match|
if emoji = Emoji.find_by_alias($1)
image_tag("/images/emoji/#{emoji.image_filename}", class: 'emoji', title: $1, alt: $1, size: "20x20")
else
match
end
end if text.present?
end
# Private: Dispatches to a dedicated processing method based on reference
#
# reference - Object reference ("@1234", "!567", etc.)
# identifier - Object identifier (Issue ID, SHA hash, etc.)
#
# Returns string rendered by the processing method
def reference_link(type, identifier)
send("reference_#{type}", identifier)
end
def reference_user(identifier)
member = User.where(uname: identifier).first || Group.where(uname: identifier).first
if member
link_to("@#{identifier}", "/#{identifier}", html_options.merge(title: member.fullname, class: "gfm gfm-member #{html_options[:class]}"))
end
end
def reference_issue(identifier)
if issue = Issue.find_by_hash_tag(identifier, current_user, @project)
if issue.pull_request
title = "#{PullRequest.model_name.human}: #{issue.title}"
url = project_pull_request_path(issue.project, issue.pull_request)
else
title = "#{Issue.model_name.human}: #{issue.title}"
url = project_issue_path(issue.project, issue.serial_id)
end
link_to(identifier, url, html_options.merge(title: title, class: "gfm gfm-issue #{html_options[:class]}"))
end
end
def reference_commit(identifier)
if commit = @project.repo.commit(identifier)
link_to shortest_hash_id(commit.id), commit_path(@project, commit.id)
title = GitPresenters::CommitAsMessagePresenter.present(commit, project: @project) do |presenter|
link_to(identifier, commit_path(@project, commit), html_options.merge(title: presenter.caption, class: "gfm gfm-commit #{html_options[:class]}"))
end
end
end
end

View File

@ -1,61 +0,0 @@
module PullRequestHelper
def merge_activity comments, commits
common_comments, pull_comments = comments.partition {|c| c.automatic || c.data.blank?}
common_comments = common_comments.map{ |c| [c.created_at, c] }
pull_comments = pull_comments.group_by(&:data).map{|data, c| [c.first.created_at, [data || {}, [c].flatten]]}
commits = commits.map{ |c| [(c.committed_date || c.authored_date), c] }
(common_comments + pull_comments + commits).sort_by{ |c| c[0] }.map{ |c| c[1] }
end
def pull_status_label pull_status, options = {}
statuses = {'ready' => 'success', 'closed' => 'default', 'merged' => 'info', 'blocked' => 'warning'}
options[:class] = "#{options[:class]} label label-#{statuses[pull_status]}"
content_tag :span, t("projects.pull_requests.statuses.#{pull_status}"), options
end
def pull_status pull
if %w(blocked merged closed ready open).include? pull.status
t("projects.pull_requests.#{pull.status}", user: pull.issue.closer.try(:uname), to_ref: show_ref(pull, 'to'),
from_ref: show_ref(pull, 'from'), time: pull.issue.closed_at).html_safe
else
raise "pull id (#{pull.id}) wrong status #{pull.status} "
end
end
def pull_header pull
str = "#{t '.header'} #{t 'from'} \
#{show_ref pull, 'from'} \
#{t 'into'} \
#{show_ref pull, 'to'}"
str << " #{t 'by'} #{link_to pull.user.uname, user_path(pull.user)}" if pull.user# pull.persisted?
str.html_safe
end
#helper for helpers
def show_ref pull, which, limit = 30
project, ref = pull.send("#{which}_project"), pull.send("#{which}_ref")
fullname = if which == 'to'
"#{project.owner.uname.truncate limit}/#{project.name.truncate limit}"
elsif which == 'from'
"#{pull.from_project_owner_uname.truncate limit}/#{pull.from_project_name.truncate limit}"
end
link_to "#{fullname}: #{ref.truncate limit}", ref_path(project, ref), class: 'btn btn-primary'
end
def ref_path project, ref
if project && project.repo.branches_and_tags.map(&:name).include?(ref)
tree_path(project, ref)
else
'#'
end
end
def ref_selector_options(project, current)
res = []
value = Proc.new {|t| [t.name.truncate(50), t.name]}
res << [I18n.t('layout.git.repositories.branches'), project.repo.branches.map(&value).sort]
res << [I18n.t('layout.git.repositories.tags'), project.repo.tags.map(&value).sort]
grouped_options_for_select(res, current)
end
end

View File

@ -1,106 +0,0 @@
module WikiHelper
def revert_path(project, first, second, name)
if name
revert_page_project_wiki_path(project, CGI.escape(name), first, second)
else
revert_project_wiki_index_path(project, first, second)
end
end
def compare_path(project, name)
if name
compare_project_wiki_path(@project, CGI.escape(name))
else
compare_project_wiki_index_path(@project)
end
end
def escaped_name
CGI.escape(@name)
end
def editor_path(project, name)
if @new
url_for(controller: :wiki, action: :create, project_id: project.id)
else
url_for(controller: :wiki, action: :update, project_id: project.id, id: name)
end
end
def view_path(project, name)
name == 'Home' ? project_wiki_index_path(project) : project_wiki_path(project, name)
end
def wiki_formats
APP_CONFIG['wiki_formats'].map do |key, val|
[ val, key.to_s ]
end.sort do |a, b|
a.first.downcase <=> b.first.downcase
end
end
def footer
if @footer.nil? && @page
@footer = !!@page.footer ? @page.footer : false
end
@footer
end
def sidebar
if @sidebar.nil? && @page
@sidebar = !!@page.sidebar ? @page.sidebar : false
end
@sidebar
end
def has_footer?
@footer = (@page.footer || false) if @footer.nil? && @page
!!@footer
end
def has_sidebar?
@sidebar = (@page.sidebar || false) if @sidebar.nil? && @page
!!@sidebar
end
def footer_content
has_footer? && @footer.formatted_data
end
def footer_format
has_footer? && @footer.format.to_s
end
def sidebar_content
has_sidebar? && @sidebar.formatted_data
end
def sidebar_format
has_sidebar? && @sidebar.format.to_s
end
def author
@page.version.author.name
end
def author_email
@page.version.author.email
end
def user_path_by_user(user)
(user.present?) ? user_path(user) : 'javascript:void(0)'
end
def user_link_by_user(user)
link_to (user.present?) ? user.uname : author, user_path_by_user(user)
end
def date
@page.version.authored_date
end
def format
@page.try(:format) || 'markdown'
end
end

View File

@ -31,7 +31,6 @@ module BuildLists
bl.include_repos |= [save_to_repository.id] bl.include_repos |= [save_to_repository.id]
%i( %i(
build_for_platform_id build_for_platform_id
update_type
save_to_platform_id save_to_platform_id
extra_build_lists extra_build_lists
extra_params extra_params

View File

@ -1,57 +1,11 @@
class UserMailer < ActionMailer::Base class UserMailer < ActionMailer::Base
add_template_helper ActivityFeedsHelper add_template_helper ActivityFeedsHelper
add_template_helper CommitHelper
default from: "\"#{APP_CONFIG['project_name']}\" <#{APP_CONFIG['do-not-reply-email']}>" default from: "\"#{APP_CONFIG['project_name']}\" <#{APP_CONFIG['do-not-reply-email']}>"
default_url_options.merge!(protocol: 'https') if APP_CONFIG['mailer_https_url'] default_url_options.merge!(protocol: 'https') if APP_CONFIG['mailer_https_url']
include Resque::Mailer # send email async include Resque::Mailer # send email async
def new_user_notification(user)
@user = user
mail(
to: email_with_name(user, user.email),
subject: I18n.t("notifications.subjects.new_user_notification",
project_name: APP_CONFIG['project_name'])
) do |format|
format.html
end
end
def new_comment_notification(comment, user_id)
@user, @comment = User.find(user_id), comment
subject = @comment.issue_comment? ? subject_for_issue(@comment.commentable) :
I18n.t('notifications.subjects.new_commit_comment_notification')
mail(
to: email_with_name(@user, @user.email),
subject: subject,
from: email_with_name(comment.user)
) do |format|
format.html
end
end
def new_issue_notification(issue_id, user_id)
@user, @issue = User.find(user_id), Issue.find(issue_id)
mail(
to: email_with_name(@user, @user.email),
subject: subject_for_issue(@issue, true),
from: email_with_name(@issue.user)
) do |format|
format.html
end
end
def issue_assign_notification(issue, user)
@issue = issue
mail(
to: email_with_name(user, user.email),
subject: subject_for_issue(@issue)
) do |format|
format.html
end
end
def build_list_notification(build_list, user) def build_list_notification(build_list, user)
set_locale user set_locale user
@user, @build_list = user, build_list @user, @build_list = user, build_list
@ -84,37 +38,6 @@ class UserMailer < ActionMailer::Base
end end
end end
def invite_approve_notification(register_request)
set_locale register_request
@register_request = register_request
mail(
to: register_request.email,
subject: I18n.t("notifications.subjects.invite_approve_notification")
) do |format|
format.html
end
end
def git_delete_branch_notification(user, options)
set_locale user
mail(
to: user.email,
subject: I18n.t('notifications.subjects.update_code', project_name: "#{options[:project_owner]}/#{options[:project_name]}")
) do |format|
format.html { render 'git_delete_branch_notification', locals: options }
end
end
def git_new_push_notification(user, options)
set_locale user
mail(
to: user.email,
subject: I18n.t('notifications.subjects.update_code', project_name: "#{options[:project_owner]}/#{options[:project_name]}")
) do |format|
format.html { render 'git_new_push_notification', locals: options }
end
end
protected protected
def set_locale(user) def set_locale(user)

View File

@ -1,9 +1,6 @@
class ActivityFeed < ActiveRecord::Base class ActivityFeed < ActiveRecord::Base
CODE = %w(git_delete_branch_notification git_new_push_notification new_comment_commit_notification)
TRACKER = %w(issue_assign_notification new_comment_notification new_issue_notification)
BUILD = %w(build_list_notification) BUILD = %w(build_list_notification)
WIKI = %w(wiki_new_commit_notification)
belongs_to :user belongs_to :user
belongs_to :creator, class_name: 'User' belongs_to :creator, class_name: 'User'

View File

@ -1,74 +0,0 @@
class Advisory < ActiveRecord::Base
self.include_root_in_json = false
self.per_page = 30
has_and_belongs_to_many :platforms
has_and_belongs_to_many :projects
has_many :build_lists
validates :description, :update_type, presence: true
validates :update_type, inclusion: BuildList::RELEASE_UPDATE_TYPES
after_create :generate_advisory_id
before_save :normalize_references, if: :references_changed?
ID_TEMPLATE = 'ROSA-%<type>s-%<year>d:%<id>04d'
ID_STRING_TEMPLATE = 'ROSA-%<type>s-%<year>04s:%<id>04s'
TYPES = {'security' => 'SA', 'bugfix' => 'A'}
scope :search, ->(q) {
q = q.to_s.strip
where("#{table_name}.advisory_id ILIKE :q OR #{table_name}.description ILIKE :q OR build_list_packages.fullname ILIKE :q", q: "%#{q}%").
joins(build_lists: :packages) if q.present?
}
scope :search_by_id, ->(aid) { where("#{table_name}.advisory_id ILIKE ?", "%#{aid.to_s.strip}%") }
scope :by_update_type, ->(ut) { where(update_type: ut) }
default_scope { order(created_at: :desc) }
def to_param
advisory_id
end
def attach_build_list(build_list)
return false if update_type != build_list.update_type
self.platforms << build_list.save_to_platform unless platforms.include? build_list.save_to_platform
self.projects << build_list.project unless projects.include? build_list.project
build_list.advisory = self
save && build_list.save
end
# this method fetches and structurize packages attached to current advisory.
def fetch_packages_info
packages_info = Hash.new { |h, k| h[k] = {} } # maaagic, it's maaagic ;)
build_lists.includes(:save_to_platform, :packages, :project).find_in_batches do |batch|
batch.each do |build_list|
tmp = build_list.packages.inject({srpm: nil, rpm: []}) do |h, p|
p.package_type == 'binary' ? h[:rpm] << p.fullname : h[:srpm] = p.fullname
h
end
h = { build_list.project => tmp }
packages_info[build_list.save_to_platform].merge!(h) do |pr, old, new|
{srpm: new[:srpm], rpm: old[:rpm].concat(new[:rpm]).uniq}
end
end
end
packages_info
end
protected
def generate_advisory_id
self.advisory_id = sprintf(ID_TEMPLATE, type: TYPES[self.update_type], year: Time.now.utc.year, id: self.id)
self.save
end
def normalize_references
self.references.gsub!(/\r| /, '')
self.references = self.references.split('\n').map do |ref|
ref = CGI::escapeHTML(ref)
ref = "http://#{ref}" unless ref =~ %r[^http(s?)://*]
ref
end.join("\n")
end
end

View File

@ -17,21 +17,11 @@ class BuildList < ActiveRecord::Base
belongs_to :user belongs_to :user
belongs_to :builder, class_name: 'User' belongs_to :builder, class_name: 'User'
belongs_to :publisher, class_name: 'User' belongs_to :publisher, class_name: 'User'
belongs_to :advisory
belongs_to :mass_build, counter_cache: true belongs_to :mass_build, counter_cache: true
has_many :items, class_name: '::BuildList::Item', dependent: :destroy has_many :items, class_name: '::BuildList::Item', dependent: :destroy
has_many :packages, class_name: '::BuildList::Package', dependent: :destroy has_many :packages, class_name: '::BuildList::Package', dependent: :destroy
has_many :source_packages, -> { where(package_type: 'source') }, class_name: '::BuildList::Package' has_many :source_packages, -> { where(package_type: 'source') }, class_name: '::BuildList::Package'
UPDATE_TYPES = [
UPDATE_TYPE_BUGFIX = 'bugfix',
UPDATE_TYPE_SECURITY = 'security',
UPDATE_TYPE_ENHANCEMENT = 'enhancement',
UPDATE_TYPE_RECOMMENDED = 'recommended',
UPDATE_TYPE_NEWPACKAGE = 'newpackage'
]
RELEASE_UPDATE_TYPES = [UPDATE_TYPE_BUGFIX, UPDATE_TYPE_SECURITY]
EXTRA_PARAMS = %w[cfg_options cfg_urpm_options build_src_rpm build_rpm] EXTRA_PARAMS = %w[cfg_options cfg_urpm_options build_src_rpm build_rpm]
AUTO_PUBLISH_STATUSES = [ AUTO_PUBLISH_STATUSES = [
@ -51,10 +41,6 @@ class BuildList < ActiveRecord::Base
validates_numericality_of :priority, greater_than_or_equal_to: 0 validates_numericality_of :priority, greater_than_or_equal_to: 0
validates :auto_publish_status, inclusion: { in: AUTO_PUBLISH_STATUSES } validates :auto_publish_status, inclusion: { in: AUTO_PUBLISH_STATUSES }
validates :update_type, inclusion: UPDATE_TYPES,
unless: Proc.new { |b| b.advisory.present? }
validates :update_type, inclusion: { in: RELEASE_UPDATE_TYPES, message: I18n.t('flash.build_list.frozen_platform') },
if: Proc.new { |b| b.advisory.present? }
validate -> { validate -> {
if save_to_platform.try(:main?) && save_to_platform_id != build_for_platform_id if save_to_platform.try(:main?) && save_to_platform_id != build_for_platform_id
errors.add(:build_for_platform, I18n.t('flash.build_list.wrong_platform')) errors.add(:build_for_platform, I18n.t('flash.build_list.wrong_platform'))
@ -507,25 +493,9 @@ class BuildList < ActiveRecord::Base
#[WAITING_FOR_RESPONSE, BUILD_PENDING, BUILD_STARTED].include?(status) #[WAITING_FOR_RESPONSE, BUILD_PENDING, BUILD_STARTED].include?(status)
end end
def associate_and_create_advisory(params)
build_advisory(params){ |a| a.update_type = update_type }
advisory.attach_build_list(self)
end
def can_attach_to_advisory?
!save_to_repository.publish_without_qa &&
save_to_platform.main? &&
save_to_platform.released &&
build_published?
end
def log(load_lines=nil) def log(load_lines=nil)
if new_core?
worker_log = abf_worker_log worker_log = abf_worker_log
Pygments.highlight(worker_log, lexer: 'sh') rescue worker_log Pygments.highlight(worker_log, lexer: 'sh') rescue worker_log
else
I18n.t('layout.build_lists.log.not_available')
end
end end
def last_published(testing = false) def last_published(testing = false)
@ -694,7 +664,6 @@ class BuildList < ActiveRecord::Base
unless mass_build_id unless mass_build_id
users = [user, publisher].compact.uniq.select{ |u| u.notifier.can_notify? && u.notifier.new_build? } users = [user, publisher].compact.uniq.select{ |u| u.notifier.can_notify? && u.notifier.new_build? }
# find associated users
users |= project.all_members(:notifier).select do |u| users |= project.all_members(:notifier).select do |u|
u.notifier.can_notify? && u.notifier.new_associated_build? u.notifier.can_notify? && u.notifier.new_associated_build?
end if project end if project

View File

@ -23,7 +23,6 @@ class BuildList::Filter
else else
BuildListPolicy::Scope.new(@user, build_lists).everything BuildListPolicy::Scope.new(@user, build_lists).everything
end end
build_lists = build_lists.scoped_to_new_core(@options[:new_core] == '0' ? nil : true) if @options[:new_core].present?
if @options[:mass_build_id] if @options[:mass_build_id]
build_lists = build_lists.by_mass_build(@options[:mass_build_id] == '-1' ? nil : @options[:mass_build_id]) build_lists = build_lists.by_mass_build(@options[:mass_build_id] == '-1' ? nil : @options[:mass_build_id])
end end
@ -65,8 +64,7 @@ class BuildList::Filter
project_version: nil, project_version: nil,
id: nil, id: nil,
project_name: nil, project_name: nil,
mass_build_id: nil, mass_build_id: nil
new_core: nil
})) }))
@options[:ownership] = @options[:ownership].presence || (@project || !@user ? 'everything' : 'owned') @options[:ownership] = @options[:ownership].presence || (@project || !@user ? 'everything' : 'owned')
@ -84,7 +82,6 @@ class BuildList::Filter
@options[:id] = @options[:id].presence @options[:id] = @options[:id].presence
@options[:project_name] = @options[:project_name].presence @options[:project_name] = @options[:project_name].presence
@options[:mass_build_id] = @options[:mass_build_id].presence @options[:mass_build_id] = @options[:mass_build_id].presence
@options[:new_core] = @options[:new_core].presence
end end
def build_date_from_params(field_name, params) def build_date_from_params(field_name, params)

View File

@ -12,7 +12,7 @@ class BuildList::Package < ActiveRecord::Base
:package_type, :name, :release, :version, :package_type, :name, :release, :version,
presence: true presence: true
validates :package_type, inclusion: PACKAGE_TYPES validates :package_type, inclusion: PACKAGE_TYPES
validates :sha1, presence: true, if: Proc.new { |p| p.build_list.new_core? } validates :sha1, presence: true
default_scope { order("lower(#{table_name}.name) ASC, length(#{table_name}.name) ASC") } default_scope { order("lower(#{table_name}.name) ASC, length(#{table_name}.name) ASC") }

Some files were not shown because too many files have changed in this diff Show More