#369: updated UI for KeyPairs

This commit is contained in:
Vokhmin Alexey V 2014-10-28 00:22:35 +03:00
parent 0f0b0e8ab4
commit b4f6129951
10 changed files with 57 additions and 42 deletions

View File

@ -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

View File

@ -0,0 +1,8 @@
module KeyPairsHelper
def key_pair_repository_options(platform)
platform.repositories.map do |r|
[r.name, r.id]
end
end
end

View File

@ -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)}

View File

@ -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

View File

@ -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)

View File

@ -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 &nbsp;

View File

@ -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

View File

@ -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')}

View File

@ -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')

View File

@ -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'