Skip to content

Commit

Permalink
Merge pull request #12434 from vpereira/rename_token_name_description
Browse files Browse the repository at this point in the history
Rename token name description
  • Loading branch information
vpereira committed Apr 19, 2022
2 parents 33ccd2a + 392d364 commit e80cfcd
Show file tree
Hide file tree
Showing 17 changed files with 42 additions and 31 deletions.
6 changes: 3 additions & 3 deletions src/api/app/components/token_card_component.html.haml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/api/app/controllers/person/token_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/api/app/controllers/webui/users/tokens_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,15 @@ 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'
@extra_params = params.slice(:project_name, :package_name).permit!
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
Expand Down
6 changes: 3 additions & 3 deletions src/api/app/models/token.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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' }

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/api/app/models/token/rebuild.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/api/app/models/token/release.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/api/app/models/token/rss.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/api/app/models/token/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/api/app/models/token/workflow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/api/app/views/person/token/index.xml.builder
Original file line number Diff line number Diff line change
@@ -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
Expand Down
10 changes: 5 additions & 5 deletions src/api/app/views/webui/users/tokens/edit.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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:')
Expand Down
6 changes: 3 additions & 3 deletions src/api/app/views/webui/users/tokens/new.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/api/app/views/webui/users/tokens/show.html.haml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
- @pagetitle = "Token - #{@token.name.presence || 'No name'}"
- @pagetitle = "Token - #{@token.description.presence || 'No Description'}"

.card
.card-body
Expand Down
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion src/api/db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions src/api/spec/components/token_card_component_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
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

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") }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)) }
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit e80cfcd

Please sign in to comment.