summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/api/api.rb1
-rw-r--r--lib/api/entities.rb23
-rw-r--r--lib/api/groups.rb4
-rw-r--r--lib/api/settings.rb35
-rw-r--r--lib/backup/database.rb22
-rw-r--r--lib/gitlab/google_code_import/importer.rb2
-rw-r--r--lib/gitlab/markup_helper.rb10
-rw-r--r--lib/gitlab/visibility_level.rb4
-rw-r--r--lib/repository_cache.rb8
-rwxr-xr-xlib/support/init.d/gitlab2
-rw-r--r--lib/tasks/gitlab/db/drop_all_postgres_sequences.rake10
-rw-r--r--lib/tasks/gitlab/db/drop_all_tables.rake10
-rw-r--r--lib/tasks/gitlab/test.rake2
13 files changed, 103 insertions, 30 deletions
diff --git a/lib/api/api.rb b/lib/api/api.rb
index d2a35c78fc1..eebd44ea5b6 100644
--- a/lib/api/api.rb
+++ b/lib/api/api.rb
@@ -49,5 +49,6 @@ module API
mount Namespaces
mount Branches
mount Labels
+ mount Settings
end
end
diff --git a/lib/api/entities.rb b/lib/api/entities.rb
index 14a8f929d76..ecf1412dee5 100644
--- a/lib/api/entities.rb
+++ b/lib/api/entities.rb
@@ -171,6 +171,7 @@ module API
expose :source_project_id, :target_project_id
expose :label_names, as: :labels
expose :description
+ expose :work_in_progress?, as: :work_in_progress
expose :milestone, using: Entities::Milestone
end
@@ -277,5 +278,27 @@ module API
class BroadcastMessage < Grape::Entity
expose :message, :starts_at, :ends_at, :color, :font
end
+
+ class ApplicationSetting < Grape::Entity
+ expose :id
+ expose :default_projects_limit
+ expose :signup_enabled
+ expose :signin_enabled
+ expose :gravatar_enabled
+ expose :sign_in_text
+ expose :created_at
+ expose :updated_at
+ expose :home_page_url
+ expose :default_branch_protection
+ expose :twitter_sharing_enabled
+ expose :restricted_visibility_levels
+ expose :max_attachment_size
+ expose :session_expire_delay
+ expose :default_project_visibility
+ expose :default_snippet_visibility
+ expose :restricted_signup_domains
+ expose :user_oauth_applications
+ expose :after_sign_out_path
+ end
end
end
diff --git a/lib/api/groups.rb b/lib/api/groups.rb
index e88b6e31775..024aeec2e14 100644
--- a/lib/api/groups.rb
+++ b/lib/api/groups.rb
@@ -74,9 +74,9 @@ module API
# POST /groups/:id/projects/:project_id
post ":id/projects/:project_id" do
authenticated_as_admin!
- group = Group.find(params[:id])
+ group = Group.find_by(id: params[:id])
project = Project.find(params[:project_id])
- result = ::Projects::TransferService.new(project, current_user, namespace_id: group.id).execute
+ result = ::Projects::TransferService.new(project, current_user).execute(group)
if result
present group
diff --git a/lib/api/settings.rb b/lib/api/settings.rb
new file mode 100644
index 00000000000..c885fcd7ea3
--- /dev/null
+++ b/lib/api/settings.rb
@@ -0,0 +1,35 @@
+module API
+ class Settings < Grape::API
+ before { authenticated_as_admin! }
+
+ helpers do
+ def current_settings
+ @current_setting ||=
+ (ApplicationSetting.current || ApplicationSetting.create_from_defaults)
+ end
+ end
+
+ # Get current applicaiton settings
+ #
+ # Example Request:
+ # GET /application/settings
+ get "application/settings" do
+ present current_settings, with: Entities::ApplicationSetting
+ end
+
+ # Modify applicaiton settings
+ #
+ # Example Request:
+ # PUT /application/settings
+ put "application/settings" do
+ attributes = current_settings.attributes.keys - ["id"]
+ attrs = attributes_for_keys(attributes)
+
+ if current_settings.update_attributes(attrs)
+ present current_settings, with: Entities::ApplicationSetting
+ else
+ render_validation_error!(current_settings)
+ end
+ end
+ end
+end
diff --git a/lib/backup/database.rb b/lib/backup/database.rb
index 9ab6aca276d..c5a5396cbbf 100644
--- a/lib/backup/database.rb
+++ b/lib/backup/database.rb
@@ -18,23 +18,31 @@ module Backup
when "postgresql" then
$progress.print "Dumping PostgreSQL database #{config['database']} ... "
pg_env
- system('pg_dump', config['database'], out: db_file_name)
+ # Pass '--clean' to include 'DROP TABLE' statements in the DB dump.
+ system('pg_dump', '--clean', config['database'], out: db_file_name)
end
report_success(success)
abort 'Backup failed' unless success
+
+ $progress.print 'Compressing database ... '
+ FileUtils.rm_f db_file_name_gz
+ success = system('gzip', db_file_name)
+ report_success(success)
+ abort 'Backup failed: compress error' unless success
end
def restore
+ $progress.print 'Decompressing database ... '
+ success = system('gzip', '-d', db_file_name_gz)
+ report_success(success)
+ abort 'Restore failed: decompress error' unless success
+
success = case config["adapter"]
when /^mysql/ then
$progress.print "Restoring MySQL database #{config['database']} ... "
system('mysql', *mysql_args, config['database'], in: db_file_name)
when "postgresql" then
$progress.print "Restoring PostgreSQL database #{config['database']} ... "
- # Drop all tables because PostgreSQL DB dumps do not contain DROP TABLE
- # statements like MySQL.
- Rake::Task["gitlab:db:drop_all_tables"].invoke
- Rake::Task["gitlab:db:drop_all_postgres_sequences"].invoke
pg_env
system('psql', config['database'], '-f', db_file_name)
end
@@ -48,6 +56,10 @@ module Backup
File.join(db_dir, 'database.sql')
end
+ def db_file_name_gz
+ File.join(db_dir, 'database.sql.gz')
+ end
+
def mysql_args
args = {
'host' => '--host',
diff --git a/lib/gitlab/google_code_import/importer.rb b/lib/gitlab/google_code_import/importer.rb
index 70bfe059776..03c410726a5 100644
--- a/lib/gitlab/google_code_import/importer.rb
+++ b/lib/gitlab/google_code_import/importer.rb
@@ -327,7 +327,7 @@ module Gitlab
link = "https://storage.googleapis.com/google-code-attachments/#{@repo.name}/issue-#{issue_id}/comment-#{comment_id}/#{filename}"
text = "[#{filename}](#{link})"
- text = "!#{text}" if filename =~ /\.(png|jpg|jpeg|gif|bmp|tiff)\z/
+ text = "!#{text}" if filename =~ /\.(png|jpg|jpeg|gif|bmp|tiff)\z/i
text
end.compact
end
diff --git a/lib/gitlab/markup_helper.rb b/lib/gitlab/markup_helper.rb
index f99be969d3e..b1991e2e285 100644
--- a/lib/gitlab/markup_helper.rb
+++ b/lib/gitlab/markup_helper.rb
@@ -33,6 +33,16 @@ module Gitlab
filename.downcase.end_with?(*%w(.adoc .ad .asciidoc))
end
+ # Public: Determines if the given filename is plain text.
+ #
+ # filename - Filename string to check
+ #
+ # Returns boolean
+ def plain?(filename)
+ filename.downcase.end_with?('.txt') ||
+ filename.downcase == 'readme'
+ end
+
def previewable?(filename)
markup?(filename)
end
diff --git a/lib/gitlab/visibility_level.rb b/lib/gitlab/visibility_level.rb
index 582fc759efd..335dc44be19 100644
--- a/lib/gitlab/visibility_level.rb
+++ b/lib/gitlab/visibility_level.rb
@@ -47,6 +47,10 @@ module Gitlab
def valid_level?(level)
options.has_value?(level)
end
+
+ def allowed_fork_levels(origin_level)
+ [PRIVATE, INTERNAL, PUBLIC].select{ |level| level <= origin_level }
+ end
end
def private?
diff --git a/lib/repository_cache.rb b/lib/repository_cache.rb
index fa016a170cd..8ddc3511293 100644
--- a/lib/repository_cache.rb
+++ b/lib/repository_cache.rb
@@ -18,4 +18,12 @@ class RepositoryCache
def fetch(key, &block)
backend.fetch(cache_key(key), &block)
end
+
+ def exist?(key)
+ backend.exist?(cache_key(key))
+ end
+
+ def read(key)
+ backend.read(cache_key(key))
+ end
end
diff --git a/lib/support/init.d/gitlab b/lib/support/init.d/gitlab
index 946902e2f6d..a3455728a94 100755
--- a/lib/support/init.d/gitlab
+++ b/lib/support/init.d/gitlab
@@ -41,7 +41,7 @@ shell_path="/bin/bash"
test -f /etc/default/gitlab && . /etc/default/gitlab
# Switch to the app_user if it is not he/she who is running the script.
-if [ "$USER" != "$app_user" ]; then
+if [ `whoami` != "$app_user" ]; then
eval su - "$app_user" -s $shell_path -c $(echo \")$0 "$@"$(echo \"); exit;
fi
diff --git a/lib/tasks/gitlab/db/drop_all_postgres_sequences.rake b/lib/tasks/gitlab/db/drop_all_postgres_sequences.rake
deleted file mode 100644
index e9cf0a9b5e8..00000000000
--- a/lib/tasks/gitlab/db/drop_all_postgres_sequences.rake
+++ /dev/null
@@ -1,10 +0,0 @@
-namespace :gitlab do
- namespace :db do
- task drop_all_postgres_sequences: :environment do
- connection = ActiveRecord::Base.connection
- connection.execute("SELECT c.relname FROM pg_class c WHERE c.relkind = 'S';").each do |sequence|
- connection.execute("DROP SEQUENCE #{sequence['relname']}")
- end
- end
- end
-end
diff --git a/lib/tasks/gitlab/db/drop_all_tables.rake b/lib/tasks/gitlab/db/drop_all_tables.rake
deleted file mode 100644
index a66030ab93a..00000000000
--- a/lib/tasks/gitlab/db/drop_all_tables.rake
+++ /dev/null
@@ -1,10 +0,0 @@
-namespace :gitlab do
- namespace :db do
- task drop_all_tables: :environment do
- connection = ActiveRecord::Base.connection
- connection.tables.each do |table|
- connection.drop_table(table)
- end
- end
- end
-end
diff --git a/lib/tasks/gitlab/test.rake b/lib/tasks/gitlab/test.rake
index cbb3d61af04..4d4e746503a 100644
--- a/lib/tasks/gitlab/test.rake
+++ b/lib/tasks/gitlab/test.rake
@@ -6,7 +6,7 @@ namespace :gitlab do
%W(rake rubocop),
%W(rake spinach),
%W(rake spec),
- %W(rake jasmine:ci)
+ %W(rake teaspoon)
]
cmds.each do |cmd|