diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-01-09 09:07:57 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-01-09 09:07:57 +0300 |
commit | 8bda404e2919234c299f088b7d8d04f8449125de (patch) | |
tree | cec81ff8bb6dbc77c3ae9b3580bb40c247599afd | |
parent | afa0ab923d697a3e737b04d078d3f28e0d573901 (diff) |
Add latest changes from gitlab-org/gitlab@master
-rw-r--r-- | GITALY_SERVER_VERSION | 2 | ||||
-rw-r--r-- | app/models/appearance.rb | 5 | ||||
-rw-r--r-- | app/services/akismet_service.rb | 17 | ||||
-rw-r--r-- | app/services/ham_service.rb | 4 | ||||
-rw-r--r-- | app/services/spam_service.rb | 3 | ||||
-rw-r--r-- | changelogs/unreleased/feat-appearance-api.yml | 5 | ||||
-rw-r--r-- | changelogs/unreleased/mk-add-geo-node-name-to-check-task.yml | 5 | ||||
-rw-r--r-- | changelogs/unreleased/pokstad1-bump-gitaly-1-80-0.yml | 5 | ||||
-rw-r--r-- | doc/administration/geo/replication/troubleshooting.md | 31 | ||||
-rw-r--r-- | doc/api/api_resources.md | 1 | ||||
-rw-r--r-- | doc/api/appearance.md | 80 | ||||
-rw-r--r-- | doc/ssh/README.md | 2 | ||||
-rw-r--r-- | lib/api/api.rb | 1 | ||||
-rw-r--r-- | lib/api/appearance.rb | 47 | ||||
-rw-r--r-- | lib/api/entities.rb | 24 | ||||
-rw-r--r-- | spec/requests/api/appearance_spec.rb | 142 |
16 files changed, 349 insertions, 25 deletions
diff --git a/GITALY_SERVER_VERSION b/GITALY_SERVER_VERSION index b3a8c61e6a8..aaceec04e04 100644 --- a/GITALY_SERVER_VERSION +++ b/GITALY_SERVER_VERSION @@ -1 +1 @@ -1.79.0 +1.80.0 diff --git a/app/models/appearance.rb b/app/models/appearance.rb index 2815a117f7f..1104b676bc4 100644 --- a/app/models/appearance.rb +++ b/app/models/appearance.rb @@ -18,6 +18,11 @@ class Appearance < ApplicationRecord validate :single_appearance_row, on: :create + default_value_for :title, '' + default_value_for :description, '' + default_value_for :new_project_guidelines, '' + default_value_for :header_message, '' + default_value_for :footer_message, '' default_value_for :message_background_color, '#E75E40' default_value_for :message_font_color, '#FFFFFF' default_value_for :email_header_and_footer_enabled, false diff --git a/app/services/akismet_service.rb b/app/services/akismet_service.rb index 63be3c371ec..d8098c4a8f5 100644 --- a/app/services/akismet_service.rb +++ b/app/services/akismet_service.rb @@ -1,10 +1,11 @@ # frozen_string_literal: true class AkismetService - attr_accessor :owner, :text, :options + attr_accessor :text, :options - def initialize(owner, text, options = {}) - @owner = owner + def initialize(owner_name, owner_email, text, options = {}) + @owner_name = owner_name + @owner_email = owner_email @text = text @options = options end @@ -16,8 +17,8 @@ class AkismetService type: 'comment', text: text, created_at: DateTime.now, - author: owner.name, - author_email: owner.email, + author: owner_name, + author_email: owner_email, referrer: options[:referrer] } @@ -40,6 +41,8 @@ class AkismetService private + attr_accessor :owner_name, :owner_email + def akismet_client @akismet_client ||= ::Akismet::Client.new(Gitlab::CurrentSettings.akismet_api_key, Gitlab.config.gitlab.url) @@ -55,8 +58,8 @@ class AkismetService params = { type: 'comment', text: text, - author: owner.name, - author_email: owner.email + author: owner_name, + author_email: owner_email } begin diff --git a/app/services/ham_service.rb b/app/services/ham_service.rb index 794eb34d9ca..0bbdaa47a1b 100644 --- a/app/services/ham_service.rb +++ b/app/services/ham_service.rb @@ -18,8 +18,10 @@ class HamService private def akismet + user = spam_log.user @akismet ||= AkismetService.new( - spam_log.user, + user.name, + user.email, spam_log.text, ip_address: spam_log.source_ip, user_agent: spam_log.user_agent diff --git a/app/services/spam_service.rb b/app/services/spam_service.rb index babe69cfdc8..62ba8d8872e 100644 --- a/app/services/spam_service.rb +++ b/app/services/spam_service.rb @@ -56,7 +56,8 @@ class SpamService def akismet @akismet ||= AkismetService.new( - spammable_owner, + spammable_owner.name, + spammable_owner.email, spammable.spammable_text, options ) diff --git a/changelogs/unreleased/feat-appearance-api.yml b/changelogs/unreleased/feat-appearance-api.yml new file mode 100644 index 00000000000..916c1474fbd --- /dev/null +++ b/changelogs/unreleased/feat-appearance-api.yml @@ -0,0 +1,5 @@ +--- +title: Implement application appearance API endpoint +merge_request: 20674 +author: Fabio Huser +type: added diff --git a/changelogs/unreleased/mk-add-geo-node-name-to-check-task.yml b/changelogs/unreleased/mk-add-geo-node-name-to-check-task.yml new file mode 100644 index 00000000000..22e304c0206 --- /dev/null +++ b/changelogs/unreleased/mk-add-geo-node-name-to-check-task.yml @@ -0,0 +1,5 @@ +--- +title: 'Geo: Check current node in gitlab:geo:check Rake task' +merge_request: 22436 +author: +type: added diff --git a/changelogs/unreleased/pokstad1-bump-gitaly-1-80-0.yml b/changelogs/unreleased/pokstad1-bump-gitaly-1-80-0.yml new file mode 100644 index 00000000000..6623636c4a3 --- /dev/null +++ b/changelogs/unreleased/pokstad1-bump-gitaly-1-80-0.yml @@ -0,0 +1,5 @@ +--- +title: Update Gitaly to v1.80.0 +merge_request: 22654 +author: +type: other diff --git a/doc/administration/geo/replication/troubleshooting.md b/doc/administration/geo/replication/troubleshooting.md index 05916e02255..0fbdaa942e8 100644 --- a/doc/administration/geo/replication/troubleshooting.md +++ b/doc/administration/geo/replication/troubleshooting.md @@ -51,6 +51,7 @@ Checking Geo ... GitLab Geo is available ... yes GitLab Geo is enabled ... yes +This machine's Geo node name matches a database record ... yes, found a secondary node named "Shanghai" GitLab Geo secondary database is correctly configured ... yes Database replication enabled? ... yes Database replication working? ... yes @@ -115,34 +116,36 @@ Any **secondary** nodes should point only to read-only instances. #### Can Geo detect the current node correctly? -Geo finds the current machine's name in `/etc/gitlab/gitlab.rb` by: +Geo finds the current machine's Geo node name in `/etc/gitlab/gitlab.rb` by: - Using the `gitlab_rails['geo_node_name']` setting. - If that is not defined, using the `external_url` setting. -To get a machine's name, run: - -```sh -sudo gitlab-rails runner "puts GeoNode.current_node_name" -``` - This name is used to look up the node with the same **Name** in **Admin Area > Geo**. -To check if current machine is correctly finding its node: +To check if the current machine has a node name that matches a node in the +database, run the check task: ```sh -sudo gitlab-rails runner "puts Gitlab::Geo.current_node.inspect" +sudo gitlab-rake gitlab:geo:check ``` -and expect something like: +It displays the current machine's node name and whether the matching database +record is a **primary** or **secondary** node. -```ruby -#<GeoNode id: 2, schema: "https", host: "gitlab.example.com", port: 443, relative_url_root: "", primary: false, ...> +``` +This machine's Geo node name matches a database record ... yes, found a secondary node named "Shanghai" ``` -By running the command above, `primary` should be `true` when executed in -the **primary** node, and `false` on any **secondary** node. +``` +This machine's Geo node name matches a database record ... no + Try fixing it: + You could add or update a Geo node database record, setting the name to "https://example.com/". + Or you could set this machine's Geo node name to match the name of an existing database record: "London", "Shanghai" + For more information see: + doc/administration/geo/replication/troubleshooting.md#can-geo-detect-the-current-node-correctly +``` ## Fixing errors found when running the Geo check rake task diff --git a/doc/api/api_resources.md b/doc/api/api_resources.md index c2713f54c47..d14c6c8feca 100644 --- a/doc/api/api_resources.md +++ b/doc/api/api_resources.md @@ -105,6 +105,7 @@ The following API resources are available outside of project and group contexts | Resource | Available endpoints | |:--------------------------------------------------|:------------------------------------------------------------------------| +| [Appearance](appearance.md) **(CORE ONLY)** | `/application/appearance` | | [Applications](applications.md) | `/applications` | | [Audit Events](audit_events.md) **(PREMIUM ONLY)** | `/audit_events` | | [Avatar](avatar.md) | `/avatar` | diff --git a/doc/api/appearance.md b/doc/api/appearance.md new file mode 100644 index 00000000000..e2c10fa2574 --- /dev/null +++ b/doc/api/appearance.md @@ -0,0 +1,80 @@ +# Appearance API **(CORE ONLY)** + +> [Introduced](https://gitlab.com/gitlab-org/gitlab/issues/16647) in GitLab 12.7. + +Appearance API allows you to maintain GitLab's appearance as if using the GitLab UI at +`/admin/appearance`. The API requires administrator privileges. + +## Get current appearance configuration + +List the current appearance configuration of the GitLab instance. + +``` +GET /application/appearance +``` + +```bash +curl --header "PRIVATE-TOKEN: <your_access_token>" https://gitlab.example.com/api/v4/application/appearance +``` + +Example response: + +```json +{ + "title": "GitLab Test Instance", + "description": "gitlab-test.example.com", + "logo": "/uploads/-/system/appearance/logo/1/logo.png", + "header_logo": "/uploads/-/system/appearance/header_logo/1/header.png", + "favicon": "/uploads/-/system/appearance/favicon/1/favicon.png", + "new_project_guidelines": "Please read the FAQs for help.", + "header_message": "", + "footer_message": "", + "message_background_color": "#e75e40", + "message_font_color": "#ffffff", + "email_header_and_footer_enabled": false +} +``` + +## Change appearance configuration + +Use an API call to modify GitLab instance appearance configuration. + +``` +PUT /application/appearance +``` + +| Attribute | Type | Required | Description | +| --------------------------------- | ------- | -------- | ----------- | +| `title` | string | no | Instance title on the sign in / sign up page +| `description` | string | no | Markdown text shown on the sign in / sign up page +| `logo` | mixed | no | Instance image used on the sign in / sign up page +| `header_logo` | mixed | no | Instance image used for the main navigation bar +| `favicon` | mixed | no | Instance favicon in .ico/.png format +| `new_project_guidelines` | string | no | Markdown text shown on the new project page +| `header_message` | string | no | Message within the system header bar +| `footer_message` | string | no | Message within the system footer bar +| `message_background_color` | string | no | Background color for the system header / footer bar +| `message_font_color` | string | no | Font color for the system header / footer bar +| `email_header_and_footer_enabled` | boolean | no | Add header and footer to all outgoing emails if enabled + +```bash +curl --request PUT --header "PRIVATE-TOKEN: <your_access_token>" https://gitlab.example.com/api/v4/application/appearance?email_header_and_footer_enabled=true&header_message=test +``` + +Example response: + +```json +{ + "title": "GitLab Test Instance", + "description": "gitlab-test.example.com", + "logo": "/uploads/-/system/appearance/logo/1/logo.png", + "header_logo": "/uploads/-/system/appearance/header_logo/1/header.png", + "favicon": "/uploads/-/system/appearance/favicon/1/favicon.png", + "new_project_guidelines": "Please read the FAQs for help.", + "header_message": "test", + "footer_message": "", + "message_background_color": "#e75e40", + "message_font_color": "#ffffff", + "email_header_and_footer_enabled": true +} +``` diff --git a/doc/ssh/README.md b/doc/ssh/README.md index 2627c0ec7c1..5a3f97de77d 100644 --- a/doc/ssh/README.md +++ b/doc/ssh/README.md @@ -183,7 +183,7 @@ Now, it's time to add the newly created public key to your GitLab account. 1. Add your **public** SSH key to your GitLab account by: 1. Clicking your avatar in the upper right corner and selecting **Settings**. - 1. Navigating to **SSH Keys** and pasting your **public** key in the **Key** field. If you: + 1. Navigating to **SSH Keys** and pasting your **public** key from the clipboard into the **Key** field. If you: - Created the key with a comment, this will appear in the **Title** field. - Created the key without a comment, give your key an identifiable title like _Work Laptop_ or _Home Workstation_. 1. Click the **Add key** button. diff --git a/lib/api/api.rb b/lib/api/api.rb index eae10738f32..555639a4b62 100644 --- a/lib/api/api.rb +++ b/lib/api/api.rb @@ -104,6 +104,7 @@ module API # Keep in alphabetical order mount ::API::AccessRequests + mount ::API::Appearance mount ::API::Applications mount ::API::Avatar mount ::API::AwardEmoji diff --git a/lib/api/appearance.rb b/lib/api/appearance.rb new file mode 100644 index 00000000000..a775102e87d --- /dev/null +++ b/lib/api/appearance.rb @@ -0,0 +1,47 @@ +# frozen_string_literal: true + +module API + class Appearance < Grape::API + before { authenticated_as_admin! } + + helpers do + def current_appearance + @current_appearance ||= (::Appearance.current || ::Appearance.new) + end + end + + desc 'Get the current appearance' do + success Entities::Appearance + end + get "application/appearance" do + present current_appearance, with: Entities::Appearance + end + + desc 'Modify appearance' do + success Entities::Appearance + end + params do + optional :title, type: String, desc: 'Instance title on the sign in / sign up page' + optional :description, type: String, desc: 'Markdown text shown on the sign in / sign up page' + # TODO: remove rubocop disable - https://gitlab.com/gitlab-org/gitlab/issues/14960 + optional :logo, type: File, desc: 'Instance image used on the sign in / sign up page' # rubocop:disable Scalability/FileUploads + optional :header_logo, type: File, desc: 'Instance image used for the main navigation bar' # rubocop:disable Scalability/FileUploads + optional :favicon, type: File, desc: 'Instance favicon in .ico/.png format' # rubocop:disable Scalability/FileUploads + optional :new_project_guidelines, type: String, desc: 'Markmarkdown text shown on the new project page' + optional :header_message, type: String, desc: 'Message within the system header bar' + optional :footer_message, type: String, desc: 'Message within the system footer bar' + optional :message_background_color, type: String, desc: 'Background color for the system header / footer bar' + optional :message_font_color, type: String, desc: 'Font color for the system header / footer bar' + optional :email_header_and_footer_enabled, type: Boolean, desc: 'Add header and footer to all outgoing emails if enabled' + end + put "application/appearance" do + attrs = declared_params(include_missing: false) + + if current_appearance.update(attrs) + present current_appearance, with: Entities::Appearance + else + render_validation_error!(current_appearance) + end + end + end +end diff --git a/lib/api/entities.rb b/lib/api/entities.rb index e6803d48a47..9433edb20b0 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -1343,6 +1343,30 @@ module API expose :allow_local_requests_from_web_hooks_and_services, as: :allow_local_requests_from_hooks_and_services end + class Appearance < Grape::Entity + expose :title + expose :description + + expose :logo do |appearance, options| + appearance.logo.url + end + + expose :header_logo do |appearance, options| + appearance.header_logo.url + end + + expose :favicon do |appearance, options| + appearance.favicon.url + end + + expose :new_project_guidelines + expose :header_message + expose :footer_message + expose :message_background_color + expose :message_font_color + expose :email_header_and_footer_enabled + end + # deprecated old Release representation class TagRelease < Grape::Entity expose :tag, as: :tag_name diff --git a/spec/requests/api/appearance_spec.rb b/spec/requests/api/appearance_spec.rb new file mode 100644 index 00000000000..40fd216f32d --- /dev/null +++ b/spec/requests/api/appearance_spec.rb @@ -0,0 +1,142 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe API::Appearance, 'Appearance' do + let_it_be(:user) { create(:user) } + let_it_be(:admin) { create(:admin) } + + describe "GET /application/appearance" do + context 'as a non-admin user' do + it "returns 403" do + get api("/application/appearance", user) + + expect(response).to have_gitlab_http_status(403) + end + end + + context 'as an admin user' do + it "returns appearance" do + get api("/application/appearance", admin) + + expect(response).to have_gitlab_http_status(200) + expect(json_response).to be_an Hash + expect(json_response['description']).to eq('') + expect(json_response['email_header_and_footer_enabled']).to be(false) + expect(json_response['favicon']).to be_nil + expect(json_response['footer_message']).to eq('') + expect(json_response['header_logo']).to be_nil + expect(json_response['header_message']).to eq('') + expect(json_response['logo']).to be_nil + expect(json_response['message_background_color']).to eq('#E75E40') + expect(json_response['message_font_color']).to eq('#FFFFFF') + expect(json_response['new_project_guidelines']).to eq('') + expect(json_response['title']).to eq('') + end + end + end + + describe "PUT /application/appearance" do + context 'as a non-admin user' do + it "returns 403" do + put api("/application/appearance", user), params: { title: "Test" } + + expect(response).to have_gitlab_http_status(403) + end + end + + context 'as an admin user' do + context "instance basics" do + it "allows updating the settings" do + put api("/application/appearance", admin), params: { + title: "GitLab Test Instance", + description: "gitlab-test.example.com", + new_project_guidelines: "Please read the FAQs for help." + } + + expect(response).to have_gitlab_http_status(200) + expect(json_response).to be_an Hash + expect(json_response['description']).to eq('gitlab-test.example.com') + expect(json_response['email_header_and_footer_enabled']).to be(false) + expect(json_response['favicon']).to be_nil + expect(json_response['footer_message']).to eq('') + expect(json_response['header_logo']).to be_nil + expect(json_response['header_message']).to eq('') + expect(json_response['logo']).to be_nil + expect(json_response['message_background_color']).to eq('#E75E40') + expect(json_response['message_font_color']).to eq('#FFFFFF') + expect(json_response['new_project_guidelines']).to eq('Please read the FAQs for help.') + expect(json_response['title']).to eq('GitLab Test Instance') + end + end + + context "system header and footer" do + it "allows updating the settings" do + settings = { + footer_message: "This is a Header", + header_message: "This is a Footer", + message_font_color: "#ffffff", + message_background_color: "#009999", + email_header_and_footer_enabled: true + } + + put api("/application/appearance", admin), params: settings + + expect(response).to have_gitlab_http_status(200) + settings.each do |attribute, value| + expect(Appearance.current.public_send(attribute)).to eq(value) + end + end + + context "fails on invalid color values" do + it "with message_font_color" do + put api("/application/appearance", admin), params: { message_font_color: "No Color" } + + expect(response).to have_gitlab_http_status(400) + expect(json_response['message']['message_font_color']).to contain_exactly('must be a valid color code') + end + + it "with message_background_color" do + put api("/application/appearance", admin), params: { message_background_color: "#1" } + + expect(response).to have_gitlab_http_status(400) + expect(json_response['message']['message_background_color']).to contain_exactly('must be a valid color code') + end + end + end + + context "instance logos" do + let_it_be(:appearance) { create(:appearance) } + + it "allows updating the image files" do + put api("/application/appearance", admin), params: { + logo: fixture_file_upload("spec/fixtures/dk.png", "image/png"), + header_logo: fixture_file_upload("spec/fixtures/dk.png", "image/png"), + favicon: fixture_file_upload("spec/fixtures/dk.png", "image/png") + } + + expect(response).to have_gitlab_http_status(200) + expect(json_response['logo']).to eq("/uploads/-/system/appearance/logo/#{appearance.id}/dk.png") + expect(json_response['header_logo']).to eq("/uploads/-/system/appearance/header_logo/#{appearance.id}/dk.png") + expect(json_response['favicon']).to eq("/uploads/-/system/appearance/favicon/#{appearance.id}/dk.png") + end + + context "fails on invalid color images" do + it "with string instead of file" do + put api("/application/appearance", admin), params: { logo: 'not-a-file.png' } + + expect(response).to have_gitlab_http_status(400) + expect(json_response['error']).to eq("logo is invalid") + end + + it "with .svg file instead of .png" do + put api("/application/appearance", admin), params: { favicon: fixture_file_upload("spec/fixtures/logo_sample.svg", "image/svg") } + + expect(response).to have_gitlab_http_status(400) + expect(json_response['message']['favicon']).to contain_exactly("You are not allowed to upload \"svg\" files, allowed types: png, ico") + end + end + end + end + end +end |