diff --git a/src/api/app/components/token_card_component.html.haml b/src/api/app/components/token_card_component.html.haml index 2d43fa4262e..a4e0858a648 100644 --- a/src/api/app/components/token_card_component.html.haml +++ b/src/api/app/components/token_card_component.html.haml @@ -1,11 +1,11 @@ .card.m-1.p-2 .card-body = link_to token_path(@token) do - - if @token.name.present? + - if @token.description.present? %h5.card-title - = @token.name + = @token.description - else - %h5.card-title.font-italic No name + %h5.card-title.font-italic No description %p.card-text Id: #{@token.id} %p.card-text diff --git a/src/api/app/controllers/person/token_controller.rb b/src/api/app/controllers/person/token_controller.rb index 431fed4bf80..3aab387b7fd 100644 --- a/src/api/app/controllers/person/token_controller.rb +++ b/src/api/app/controllers/person/token_controller.rb @@ -20,7 +20,7 @@ def create pkg = (Package.get_by_project_and_name(params[:project], params[:package]) if params[:project] || params[:package]) - @token = Token.token_type(params[:operation]).create(name: params[:name], user: @user, package: pkg, scm_token: params[:scm_token]) + @token = Token.token_type(params[:operation]).create(description: params[:description], user: @user, package: pkg, scm_token: params[:scm_token]) return if @token.valid? render_error status: 400, diff --git a/src/api/app/controllers/webui/users/tokens_controller.rb b/src/api/app/controllers/webui/users/tokens_controller.rb index 60c0a80e233..8bc87f004bd 100644 --- a/src/api/app/controllers/webui/users/tokens_controller.rb +++ b/src/api/app/controllers/webui/users/tokens_controller.rb @@ -83,7 +83,7 @@ def set_token end def set_parameters - @params = params.except(:project_name, :package_name).require(:token).except(:string_readonly).permit(:type, :name, :scm_token).tap do |token_parameters| + @params = params.except(:project_name, :package_name).require(:token).except(:string_readonly).permit(:type, :description, :scm_token).tap do |token_parameters| token_parameters.require(:type) end @params = @params.except(:scm_token) unless @params[:type] == 'workflow' @@ -91,7 +91,7 @@ def set_parameters end def update_parameters - params.require(:token).except(:string_readonly).permit(:name, :scm_token).reject! { |k, v| k == 'scm_token' && (@token.type != 'Token::Workflow' || v.empty?) } + params.require(:token).except(:string_readonly).permit(:description, :scm_token).reject! { |k, v| k == 'scm_token' && (@token.type != 'Token::Workflow' || v.empty?) } end def set_package diff --git a/src/api/app/models/token.rb b/src/api/app/models/token.rb index 89abfacdc06..2daed7efc62 100644 --- a/src/api/app/models/token.rb +++ b/src/api/app/models/token.rb @@ -8,10 +8,10 @@ class Token < ApplicationRecord has_secure_token :string before_validation do - self.name ||= '' + self.description ||= '' end - validates :name, length: { maximum: 64 } + validates :description, length: { maximum: 64 } validates :string, uniqueness: { case_sensitive: false } validates :scm_token, absence: true, if: -> { type != 'Token::Workflow' } @@ -63,7 +63,7 @@ def set_triggered_at # Table name: tokens # # id :integer not null, primary key -# name :string(64) default("") +# description :string(64) default("") # scm_token :string(255) indexed # string :string(255) indexed # triggered_at :datetime diff --git a/src/api/app/models/token/rebuild.rb b/src/api/app/models/token/rebuild.rb index 47d661c09c4..4270c18b343 100644 --- a/src/api/app/models/token/rebuild.rb +++ b/src/api/app/models/token/rebuild.rb @@ -18,7 +18,7 @@ def package_find_options # Table name: tokens # # id :integer not null, primary key -# name :string(64) default("") +# description :string(64) default("") # scm_token :string(255) indexed # string :string(255) indexed # triggered_at :datetime diff --git a/src/api/app/models/token/release.rb b/src/api/app/models/token/release.rb index addff89801e..79ca41893e9 100644 --- a/src/api/app/models/token/release.rb +++ b/src/api/app/models/token/release.rb @@ -32,7 +32,7 @@ def package_find_options # Table name: tokens # # id :integer not null, primary key -# name :string(64) default("") +# description :string(64) default("") # scm_token :string(255) indexed # string :string(255) indexed # triggered_at :datetime diff --git a/src/api/app/models/token/rss.rb b/src/api/app/models/token/rss.rb index f27db698fe7..fe7b1811ebc 100644 --- a/src/api/app/models/token/rss.rb +++ b/src/api/app/models/token/rss.rb @@ -6,7 +6,7 @@ class Token::Rss < Token # Table name: tokens # # id :integer not null, primary key -# name :string(64) default("") +# description :string(64) default("") # scm_token :string(255) indexed # string :string(255) indexed # triggered_at :datetime diff --git a/src/api/app/models/token/service.rb b/src/api/app/models/token/service.rb index 81df7258c33..22b26577fd8 100644 --- a/src/api/app/models/token/service.rb +++ b/src/api/app/models/token/service.rb @@ -16,7 +16,7 @@ def package_find_options # Table name: tokens # # id :integer not null, primary key -# name :string(64) default("") +# description :string(64) default("") # scm_token :string(255) indexed # string :string(255) indexed # triggered_at :datetime diff --git a/src/api/app/models/token/workflow.rb b/src/api/app/models/token/workflow.rb index 4a3c4efa343..434578d3b7e 100644 --- a/src/api/app/models/token/workflow.rb +++ b/src/api/app/models/token/workflow.rb @@ -50,7 +50,7 @@ def validation_errors # Table name: tokens # # id :integer not null, primary key -# name :string(64) default("") +# description :string(64) default("") # scm_token :string(255) indexed # string :string(255) indexed # triggered_at :datetime diff --git a/src/api/app/views/person/token/index.xml.builder b/src/api/app/views/person/token/index.xml.builder index 44f60fd6e85..a03859dd9dd 100644 --- a/src/api/app/views/person/token/index.xml.builder +++ b/src/api/app/views/person/token/index.xml.builder @@ -1,6 +1,6 @@ xml.directory(count: @list.length) do |dir| @list.each do |token| - p = { id: token.id, string: token.string, kind: token.token_name, name: token.name, triggered_at: token.triggered_at } + p = { id: token.id, string: token.string, kind: token.token_name, description: token.description, triggered_at: token.triggered_at } if token.package p[:project] = token.package.project.name p[:package] = token.package.name diff --git a/src/api/app/views/webui/users/tokens/edit.html.haml b/src/api/app/views/webui/users/tokens/edit.html.haml index bc030c3b58e..0ac811ef71e 100644 --- a/src/api/app/views/webui/users/tokens/edit.html.haml +++ b/src/api/app/views/webui/users/tokens/edit.html.haml @@ -24,11 +24,11 @@ = f.label(:type, 'Operation:') = @token.token_name.capitalize .form-group - = f.label(:name, 'Name:') - %span.d-none#original-token-name - = @token.name - .input-group#token-name-text-field - = f.text_field(:name, class: 'form-control', placeholder: 'Eg: Rebuild vim package', maxlength: 64) + = f.label(:description, 'Description:') + %span.d-none#original-token-description + = @token.description + .input-group#token-description-text-field + = f.text_field(:description, class: 'form-control', placeholder: 'Eg: Rebuild vim package', maxlength: 64) - if @token.package.present? .form-group = f.label(:type, 'Package:') diff --git a/src/api/app/views/webui/users/tokens/new.html.haml b/src/api/app/views/webui/users/tokens/new.html.haml index ef576ae5e82..5df6a4d169c 100644 --- a/src/api/app/views/webui/users/tokens/new.html.haml +++ b/src/api/app/views/webui/users/tokens/new.html.haml @@ -21,10 +21,10 @@ .form-row .col-sm .form-group.ui-front - = f.label(:name, 'Name:') - = f.text_field(:name, class: 'form-control', placeholder: 'Eg: Rebuild vim package') + = f.label(:description, 'Description:') + = f.text_field(:description, class: 'form-control', placeholder: 'Eg: Rebuild vim package') .form-text.text-muted - Optional: provide a name to identify your token. + Optional: provide a description to your token. .form-row#package-project-form .col-sm diff --git a/src/api/app/views/webui/users/tokens/show.html.haml b/src/api/app/views/webui/users/tokens/show.html.haml index c8cf85c5452..b444410a053 100644 --- a/src/api/app/views/webui/users/tokens/show.html.haml +++ b/src/api/app/views/webui/users/tokens/show.html.haml @@ -1,4 +1,4 @@ -- @pagetitle = "Token - #{@token.name.presence || 'No name'}" +- @pagetitle = "Token - #{@token.description.presence || 'No Description'}" .card .card-body diff --git a/src/api/db/migrate/20220412090435_rename_name_to_description_in_tokens.rb b/src/api/db/migrate/20220412090435_rename_name_to_description_in_tokens.rb new file mode 100644 index 00000000000..e4cf18fd460 --- /dev/null +++ b/src/api/db/migrate/20220412090435_rename_name_to_description_in_tokens.rb @@ -0,0 +1,11 @@ +class RenameNameToDescriptionInTokens < ActiveRecord::Migration[6.1] + def up + # rename column is safe in mysql 5.6 and beyond + # check https://stefan.magnuson.co/posts/2020-04-18-zero-downtime-migrations-with-rails-and-mysql/ + safety_assured { rename_column :tokens, :name, :description } + end + + def down + safety_assured { rename_column :tokens, :description, :name } + end +end diff --git a/src/api/db/schema.rb b/src/api/db/schema.rb index 367d9ce9d14..8f54d90dda0 100644 --- a/src/api/db/schema.rb +++ b/src/api/db/schema.rb @@ -1012,7 +1012,7 @@ t.integer "package_id" t.string "type", collation: "utf8_unicode_ci" t.string "scm_token" - t.string "name", limit: 64, default: "" + t.string "description", limit: 64, default: "" t.datetime "triggered_at" t.index ["package_id"], name: "package_id" t.index ["scm_token"], name: "index_tokens_on_scm_token" diff --git a/src/api/spec/components/token_card_component_spec.rb b/src/api/spec/components/token_card_component_spec.rb index ab45ede8e01..8735f1a37ad 100644 --- a/src/api/spec/components/token_card_component_spec.rb +++ b/src/api/spec/components/token_card_component_spec.rb @@ -9,8 +9,8 @@ render_inline(described_class.new(token: token)) end - context 'token with a name' do - let(:token) { build_stubbed(:rebuild_token, user: user, name: 'foo_token') } + context 'token with a description' do + let(:token) { build_stubbed(:rebuild_token, user: user, description: 'foo_token') } it { expect(rendered_component).to have_text('foo_token') } end @@ -18,7 +18,7 @@ context 'token without any optional information' do let(:token) { build_stubbed(:rebuild_token, user: user) } - it { expect(rendered_component).to have_text('No name') } + it { expect(rendered_component).to have_text('No description') } it { expect(rendered_component).to have_text("Id: #{token.id}") } it { expect(rendered_component).to have_text("Operation: #{token.class.token_name.capitalize}") } it { expect(rendered_component).to have_link(href: "/my/tokens/#{token.id}/edit") } diff --git a/src/api/spec/controllers/webui/users/tokens_controller_spec.rb b/src/api/spec/controllers/webui/users/tokens_controller_spec.rb index 3ac9291084e..e027d88fc4d 100644 --- a/src/api/spec/controllers/webui/users/tokens_controller_spec.rb +++ b/src/api/spec/controllers/webui/users/tokens_controller_spec.rb @@ -55,7 +55,7 @@ end context 'type is runservice, with name' do - let(:form_parameters) { { token: { type: 'runservice', name: 'My first token' } } } + let(:form_parameters) { { token: { type: 'runservice', description: 'My first token' } } } include_examples 'check for flashing a success' it { is_expected.to redirect_to(token_path(Token.last)) } @@ -103,13 +103,13 @@ context 'updates a workflow token belonging to the logged-in user' do let(:token) { create(:workflow_token, user: user, scm_token: 'something') } - let(:update_parameters) { { id: token.id, token: { name: 'My first token', scm_token: 'something_else' } } } + let(:update_parameters) { { id: token.id, token: { description: 'My first token', scm_token: 'something_else' } } } include_examples 'check for flashing a success' it { is_expected.to redirect_to(tokens_path) } it { expect { subject }.to change { token.reload.scm_token }.from('something').to('something_else') } - it { expect { subject }.to change { token.reload.name }.from('').to('My first token') } + it { expect { subject }.to change { token.reload.description }.from('').to('My first token') } end context 'updates the token string of a token belonging to the logged-in user' do