diff --git a/app/controllers/platforms/key_pairs_controller.rb b/app/controllers/platforms/key_pairs_controller.rb index 41c5c09f8..84c043583 100644 --- a/app/controllers/platforms/key_pairs_controller.rb +++ b/app/controllers/platforms/key_pairs_controller.rb @@ -1,20 +1,25 @@ class Platforms::KeyPairsController < Platforms::BaseController + layout 'bootstrap' + before_filter :authenticate_user! - load_and_authorize_resource :platform, only: [:index] + load_and_authorize_resource :platform load_and_authorize_resource only: [:create, :destroy] + def index + @key_pair = KeyPair.new + end + def create @key_pair.user_id = current_user.id if @key_pair.save flash[:notice] = t('flash.key_pairs.saved') + redirect_to platform_key_pairs_path(@key_pair.repository.platform) and return else flash[:error] = t('flash.key_pairs.save_error') - flash[:warning] = @key_pair.errors.full_messages.join('. ') unless @key_pair.errors.blank? end - - redirect_to platform_key_pairs_path(@key_pair.repository.platform) + render :index end def destroy diff --git a/app/helpers/key_pairs_helper.rb b/app/helpers/key_pairs_helper.rb new file mode 100644 index 000000000..a18e221ac --- /dev/null +++ b/app/helpers/key_pairs_helper.rb @@ -0,0 +1,8 @@ +module KeyPairsHelper + + def key_pair_repository_options(platform) + platform.repositories.map do |r| + [r.name, r.id] + end + end +end \ No newline at end of file diff --git a/app/models/ability.rb b/app/models/ability.rb index dfe309f97..eafc12862 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -132,7 +132,7 @@ class Ability can(:regenerate_metadata, Platform) {|platform| owner?(platform) || local_admin?(platform)} can([:settings, :destroy, :edit, :update], Repository) {|repository| owner? repository.platform} - can([:create, :destroy], KeyPair) {|key_pair| owner?(key_pair.repository.platform) || local_admin?(key_pair.repository.platform)} + can([:create, :destroy], KeyPair) {|key_pair| key_pair.repository.blank? || owner?(key_pair.repository.platform) || local_admin?(key_pair.repository.platform)} can([:read, :create, :withdraw], Token) {|token| local_admin?(token.subject)} diff --git a/app/models/platform.rb b/app/models/platform.rb index fbbc7415b..b9da4c105 100644 --- a/app/models/platform.rb +++ b/app/models/platform.rb @@ -27,6 +27,8 @@ class Platform < ActiveRecord::Base belongs_to :owner, polymorphic: true has_many :repositories, dependent: :destroy + has_many :key_pairs, through: :repositories + has_many :products, dependent: :destroy has_many :tokens, as: :subject, dependent: :destroy has_many :platform_arch_settings, dependent: :destroy @@ -36,6 +38,7 @@ class Platform < ActiveRecord::Base has_many :actors, as: :target, class_name: 'Relation', dependent: :destroy has_many :members, through: :actors, source: :actor, source_type: 'User' + has_and_belongs_to_many :advisories has_many :packages, class_name: "BuildList::Package", dependent: :destroy diff --git a/app/views/platforms/base/_submenu.html.slim b/app/views/platforms/base/_submenu.html.slim index c0e724b5d..e7f61fba9 100644 --- a/app/views/platforms/base/_submenu.html.slim +++ b/app/views/platforms/base/_submenu.html.slim @@ -40,7 +40,7 @@ li class=('active' if act == :members && contr == :platforms) = link_to t("layout.platforms.members"), members_platform_path(@platform) - if can? :edit, @platform - li class=('active' if act == :index && contr == :key_pairs) + li class=('active' if contr == :key_pairs) = link_to t("layout.key_pairs.header"), platform_key_pairs_path(@platform) li class=('active' if contr == :tokens) = link_to t('layout.tokens.header'), platform_tokens_path(@platform) diff --git a/app/views/platforms/key_pairs/_list.html.haml b/app/views/platforms/key_pairs/_list.html.haml deleted file mode 100644 index 2af0722fb..000000000 --- a/app/views/platforms/key_pairs/_list.html.haml +++ /dev/null @@ -1,18 +0,0 @@ -%table#myTable.tablesorter.platform-repos{cellspacing: "0", cellpadding: "0"} - %thead - %tr - %th.th1= t("activerecord.attributes.key_pair.repository_id") - %th.th2= t("activerecord.attributes.key_pair.key_id") - %th.th3= t("activerecord.attributes.key_pair.user_id") - %th= t("layout.delete") - %tbody - - @platform.repositories.each do |repository| - - if repository.key_pair - %tr{class: cycle("odd", "even")} - %td= repository.name - %td= repository.key_pair.key_id - %td= link_to repository.key_pair.user.fullname, user_path(repository.key_pair.user) - %td.buttons - - if can? :destroy, repository.key_pair - = link_to platform_key_pair_path(@platform, repository.key_pair), method: :delete, data: { confirm: t("layout.key_pairs.confirm_delete") } do - %span.delete   diff --git a/app/views/platforms/key_pairs/_list.html.slim b/app/views/platforms/key_pairs/_list.html.slim new file mode 100644 index 000000000..42ba9a3a5 --- /dev/null +++ b/app/views/platforms/key_pairs/_list.html.slim @@ -0,0 +1,18 @@ +table.table.table-striped + thead + tr + th= t("activerecord.attributes.key_pair.repository_id") + th= t("activerecord.attributes.key_pair.key_id") + th= t("activerecord.attributes.key_pair.user_id") + th= t("layout.delete") + tbody + - @platform.repositories.each do |repository| + - if repository.key_pair + tr + td= repository.name + td= repository.key_pair.key_id + td= link_to repository.key_pair.user.fullname, user_path(repository.key_pair.user) + td.buttons + - if can? :destroy, repository.key_pair + = link_to platform_key_pair_path(@platform, repository.key_pair), method: :delete, data: { confirm: t("layout.key_pairs.confirm_delete") } do + span.glyphicon.glyphicon-remove diff --git a/app/views/platforms/key_pairs/_new.html.haml b/app/views/platforms/key_pairs/_new.html.haml deleted file mode 100644 index 56e282532..000000000 --- a/app/views/platforms/key_pairs/_new.html.haml +++ /dev/null @@ -1,15 +0,0 @@ -%h3= t("layout.key_pairs.header") - -= form_for :key_pair, url: platform_key_pairs_path(@platform), method: :post, html: { class: :form } do |f| - .leftlist= f.label :public, t("activerecord.attributes.key_pair.public"), class: :label - .rightlist= f.text_area :public, class: 'text_field resizable', cols: 80 - .both - .leftlist= f.label :secret, t("activerecord.attributes.key_pair.secret"), class: :label - .rightlist= f.text_area :secret, class: 'text_field resizable', cols: 80 - .both - .leftlist= f.label :repository_id, t("activerecord.attributes.key_pair.repository_id"), class: :label - .rightlist= f.select :repository_id, options_from_collection_for_select(@platform.repositories, 'id', 'name') - .both - - .button_block - = submit_tag t('layout.save'), data: {'disable-with' => t('layout.saving')} diff --git a/app/views/platforms/key_pairs/_new.html.slim b/app/views/platforms/key_pairs/_new.html.slim new file mode 100644 index 000000000..8b47ef30a --- /dev/null +++ b/app/views/platforms/key_pairs/_new.html.slim @@ -0,0 +1,13 @@ +h3 + = t("layout.key_pairs.header") + += simple_form_for @key_pair, url: platform_key_pairs_path(@platform) do |f| + + fieldset + = f.input :public, as: :text + = f.input :secret, as: :text + = f.input :repository_id, collection: key_pair_repository_options(@platform) + + .button_block + button type="submit" class="btn btn-default" data-disable-with=t('layout.saving') + = t('layout.save') \ No newline at end of file diff --git a/app/views/platforms/key_pairs/index.html.haml b/app/views/platforms/key_pairs/index.html.slim similarity index 55% rename from app/views/platforms/key_pairs/index.html.haml rename to app/views/platforms/key_pairs/index.html.slim index ac9980bff..a062bf3a5 100644 --- a/app/views/platforms/key_pairs/index.html.haml +++ b/app/views/platforms/key_pairs/index.html.slim @@ -1,6 +1,7 @@ - set_meta_tags title: [title_object(@platform), t('layout.key_pairs.header')] = render 'platforms/base/submenu' -= render 'platforms/base/sidebar' -= render 'new' if can? :edit, @platform -= render 'list' +.container + .row + = render 'new' if can? :edit, @platform + = render 'list'