Skip to content

Commit

Permalink
Update usage of Token#name to Token#description
Browse files Browse the repository at this point in the history
  • Loading branch information
vpereira committed Apr 19, 2022
1 parent abfc5ce commit 392d364
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 27 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
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
6 changes: 1 addition & 5 deletions src/api/db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

<<<<<<< HEAD
ActiveRecord::Schema.define(version: 2022_04_13_223300) do
=======
ActiveRecord::Schema.define(version: 2022_04_12_090435) do
>>>>>>> d53ec94603 (Rename Token#name to Token#description)

create_table "architectures", id: :integer, charset: "utf8mb4", collation: "utf8mb4_unicode_ci", options: "ENGINE=InnoDB ROW_FORMAT=DYNAMIC", force: :cascade do |t|
t.string "name", null: false, collation: "utf8_general_ci"
Expand Down Expand Up @@ -1016,7 +1012,7 @@
t.integer "package_id"
t.string "type", collation: "utf8_unicode_ci"
t.string "scm_token"
t.string "description", limit: 64
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 392d364

Please sign in to comment.