diff options
author | Kamil Trzciński <ayufan@ayufan.eu> | 2015-09-16 11:57:40 +0000 |
---|---|---|
committer | Kamil Trzciński <ayufan@ayufan.eu> | 2015-09-16 11:57:40 +0000 |
commit | cccd269da3f5d82c5d14289980d9b52c9cad08db (patch) | |
tree | 2947658dfff44a3873f7d350f0353dbdb7b9b541 /lib/api/helpers.rb | |
parent | 7d59ba00b9aa1a8be28f1b7ccaa1c628be90aabb (diff) | |
parent | ac8d2eb065e9522679d4eae4649c6815daa5460c (diff) | |
download | gitlab-ce-cccd269da3f5d82c5d14289980d9b52c9cad08db.tar.gz |
Merge branch 'ci-and-ce-sitting-in-a-tree-k-i-s-s-i-n-g' into 'master'
Merge CI into CE
First step of #2164.
- [x] Merge latest CE master
- [x] Make application start
- [x] Re-use gitlab sessions (remove CI oauth part)
- [x] Get rid of gitlab_ci.yml config
- [x] Make tests start
- [x] Make most CI features works
- [x] Make tests green
- [x] Write migration documentation
- [x] Add CI builds to CE backup
See merge request !1204
Diffstat (limited to 'lib/api/helpers.rb')
-rw-r--r-- | lib/api/helpers.rb | 43 |
1 files changed, 40 insertions, 3 deletions
diff --git a/lib/api/helpers.rb b/lib/api/helpers.rb index 76c9cc2e3a4..7fada98fcdc 100644 --- a/lib/api/helpers.rb +++ b/lib/api/helpers.rb @@ -148,15 +148,14 @@ module API end end - def attributes_for_keys(keys) + def attributes_for_keys(keys, custom_params = nil) + params_hash = custom_params || params attrs = {} - keys.each do |key| if params[key].present? or (params.has_key?(key) and params[key] == false) attrs[key] = params[key] end end - ActionController::Parameters.new(attrs).permit! end @@ -246,6 +245,44 @@ module API error!({ 'message' => message }, status) end + # Projects helpers + + def filter_projects(projects) + # If the archived parameter is passed, limit results accordingly + if params[:archived].present? + projects = projects.where(archived: parse_boolean(params[:archived])) + end + + if params[:search].present? + projects = projects.search(params[:search]) + end + + if params[:ci_enabled_first].present? + projects.includes(:gitlab_ci_service). + reorder("services.active DESC, projects.#{project_order_by} #{project_sort}") + else + projects.reorder(project_order_by => project_sort) + end + end + + def project_order_by + order_fields = %w(id name path created_at updated_at last_activity_at) + + if order_fields.include?(params['order_by']) + params['order_by'] + else + 'created_at' + end + end + + def project_sort + if params["sort"] == 'asc' + :asc + else + :desc + end + end + private def add_pagination_headers(paginated, per_page) |