--- /dev/null
+# Place all the behaviors and hooks related to the matching controller here.
+# All this logic will automatically be available in application.js.
+# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
body .editable-empty:hover {
color: #0088cc;
}
+table.arv-index tbody td.arv-object-AuthorizedKey.arv-attr-public_key {
+ overflow-x: hidden;
+ max-width: 120px;
+}
--- /dev/null
+// Place all the styles related to the Repositories controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
end
end
- protected
-
def model_class
controller_name.classify.constantize
end
+ protected
+
def find_object_by_uuid
if params[:id] and params[:id].match /\D/
params[:uuid] = params.delete :id
class AuthorizedKeysController < ApplicationController
def new
super
- @object.authorized_user = current_user.uuid if current_user
+ @object.authorized_user_uuid = current_user.uuid if current_user
@object.key_type = 'SSH'
end
def create
- @object = AuthorizedKey.new authorized_user: current_user.uuid, key_type: 'SSH'
+ @object = AuthorizedKey.new authorized_user_uuid: current_user.uuid, key_type: 'SSH'
super
end
end
--- /dev/null
+class RepositoriesController < ApplicationController
+end
skip_before_filter :find_object_by_uuid, :only => [:destroy, :index]
def destroy
session.clear
- redirect_to $arvados_api_client.orvos_logout_url(return_to: logged_out_url)
+ redirect_to $arvados_api_client.arvados_logout_url(return_to: logged_out_url)
end
def index
redirect_to root_url if session[:arvados_api_token]
--- /dev/null
+module RepositoriesHelper
+end
}
end
+ def self.creatable?
+ current_user
+ end
+
def editable?
(current_user and
(current_user.is_admin or
self
end
- def current_user
+ def self.current_user
Thread.current[:user] ||= User.current if Thread.current[:arvados_api_token]
Thread.current[:user]
end
+ def current_user
+ self.class.current_user
+ end
end
def to_hash
Hash[results.collect { |x| [x.uuid, x] }]
end
+
+ def empty?
+ results.empty?
+ end
end
class AuthorizedKey < ArvadosBase
def attribute_editable?(attr)
- if attr.to_s == 'authorized_user'
+ if attr.to_s == 'authorized_user_uuid'
current_user and current_user.is_admin
else
super(attr)
--- /dev/null
+class Repository < ArvadosBase
+ def self.creatable?
+ current_user and current_user.is_admin
+ end
+end
res = $arvados_api_client.api self, '/current'
$arvados_api_client.unpack_api_response(res)
end
+
+ def full_name
+ (self.first_name || "") + " " + (self.last_name || "")
+ end
end
--- /dev/null
+<% if @objects.empty? %>
+
+<p>
+ No <%= controller.model_class.to_s.underscore.pluralize.gsub '_', ' ' %> to display.
+</p>
+
+<% else %>
+
+<% attr_blacklist = 'created_at modified_at modified_by_user modified_by_client updated_at' %>
+
+<table class="table arv-index">
+ <thead>
+ <tr>
+ <% @objects.first.attributes_for_display.each do |attr, attrvalue| %>
+ <% next if attr_blacklist.index attr %>
+ <th class="arv-attr-<%= attr %>">
+ <%= attr.sub /_uuid/, '' %>
+ </th>
+ <% end %>
+ </tr>
+ </thead>
+
+ <tbody>
+ <% @objects.each do |object| %>
+ <tr>
+ <% object.attributes_for_display.each do |attr, attrvalue| %>
+ <% next if attr_blacklist.index attr %>
+ <td class="arv-object-<%= object.class.to_s %> arv-attr-<%= attr %>">
+ <% if attr == 'uuid' %>
+ <%= link_to_if_arvados_object object %>
+ <% elsif object.attribute_editable? attr %>
+ <%= render_editable_attribute object, attr %>
+ <% else %>
+ <%= link_to_if_arvados_object attrvalue, {referring_attr: attr, referring_object: @object, with_prefixes: true, with_class_name: true} %>
+ <% end %>
+ </td>
+ <% end %>
+ </tr>
+ <% end %>
+ </tbody>
+
+ <tfoot>
+ </tfoot>
+</table>
+
+<% end %>
+
+<% if controller.model_class.creatable? %>
+<%= button_to "Add a new #{controller.model_class.to_s.underscore.gsub '_', ' '}", { action: 'create', return_to: './' }, { class: 'btn btn-primary' } %>
+<% end %>
+++ /dev/null
-<%= form_for @object do |f| %>
-<table class="table">
- <tr>
- <td>
- name
- </td><td>
- <%= f.text_field :name %>
- </td>
- </tr>
- <tr>
- <td>
- authorized user
- </td><td>
- <%= f.text_field :authorized_user %>
- </td>
- </tr>
- <tr>
- <td>
- public key
- </td><td>
- <%= f.text_area :public_key %>
- </td>
- </tr>
- <tr>
- <td></td>
- <td>
- <%= f.submit class: 'btn btn-primary' %>
- </td>
- </tr>
-</table>
-<% end %>
+++ /dev/null
-<table class="table">
- <thead>
- <tr class="contain-align-left">
- <th>
- id
- </th><th>
- owner
- </th><th>
- name
- </th><th>
- key type
- </th><th>
- public key
- </th><th>
- expires
- </th>
- </tr>
- </thead>
- <tbody>
-
- <% @objects.sort_by { |ak| ak[:created_at] }.each do |ak| %>
-
- <tr>
- <td>
- <%= link_to_if_arvados_object ak %>
- </td><td>
- <%= render_editable_attribute ak, 'owner' %>
- </td><td>
- <%= render_editable_attribute ak, 'name' %>
- </td><td>
- <%= render_editable_attribute ak, 'key_type', ak.key_type, "data-type" => "select", "data-source" => '[{value:"SSH",text:"SSH"}]' %>
- </td><td style="max-width: 120px; overflow-x: hidden">
- <%= render_editable_attribute ak, 'public_key' %>
- </td><td>
- <%= render_editable_attribute ak, 'expires_at' %>
- </td><td>
- <%= link_to raw('<i class="icon-trash"></i>'), { action: 'destroy', id: ak.uuid }, { confirm: 'Delete this key?', method: 'delete' } %>
- </td>
- </tr>
-
- <% end %>
- <% if @objects.count == 0 %>
- <tr>
- <td colspan="7">
- (no authorized keys)
- </td>
- </tr>
- <% end %>
-
- </tbody>
-</table>
-
-<%= button_to "Add a new key", { action: 'create', return_to: './' }, { class: 'btn btn-primary' } %>
+++ /dev/null
-<%= render partial: 'form' %>
+++ /dev/null
-<%= render :partial => 'application/arvados_object' %>
<% [
[false, 'Keys', authorized_keys_path],
[false, 'VMs', virtual_machines_path],
+ [false, 'Repos', repositories_path],
[true, 'Data', collections_path],
[true, 'Groups', groups_path],
[true, 'Pipeline Templates', pipeline_templates_path],
</ul>
<ul class="nav pull-right">
<% if current_user -%>
+ <li><span class="badge badge-info" style="margin: 10px auto 10px; padding-top: 4px; padding-bottom: 4px"><%= current_user.email %></span></li>
<li><a href="<%= logout_path %>">Log out</a></li>
<% else -%>
<li><a href="<%= root_path %>">Log in</a></li>
+++ /dev/null
-<table class="table">
- <thead>
- <tr class="contain-align-left">
- <th>
- id
- </th><th>
- owner
- </th><th>
- hostname
- </th>
- </tr>
- </thead>
- <tbody>
-
- <% @objects.sort_by { |vm| vm[:hostname] }.each do |vm| %>
-
- <tr>
- <td>
- <%= link_to_if_arvados_object vm %>
- </td><td>
- <%= render_editable_attribute vm, 'owner' %>
- </td><td>
- <%= render_editable_attribute vm, 'hostname' %>
- </td>
- </tr>
-
- <% end %>
- <% if @objects.count == 0 %>
- <tr>
- <td colspan="7">
- (no VMs)
- </td>
- </tr>
- <% end %>
-
- </tbody>
-</table>
-
-<% if current_user and current_user.is_admin %>
-<%= button_to "Add a new VM", { action: 'create', return_to: './' }, { class: 'btn btn-primary' } %>
-<% end %>
ArvadosWorkbench::Application.routes.draw do
+ resources :repositories
+
+
resources :virtual_machines
--- /dev/null
+# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
+
+# This model initially had no columns defined. If you add columns to the
+# model remove the '{}' from the fixture names and add the columns immediately
+# below each fixture, per the syntax in the comments below
+#
+one: {}
+# column: value
+#
+two: {}
+# column: value
--- /dev/null
+require 'test_helper'
+
+class RepositoriesControllerTest < ActionController::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end
--- /dev/null
+require 'test_helper'
+
+class RepositoriesHelperTest < ActionView::TestCase
+end
--- /dev/null
+require 'test_helper'
+
+class RepositoryTest < ActiveSupport::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end
--- /dev/null
+# Place all the behaviors and hooks related to the matching controller here.
+# All this logic will automatically be available in application.js.
+# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
--- /dev/null
+// Place all the styles related to the Repositories controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
end
end
- unless Rails.application.config.consider_all_requests_local
+ begin
rescue_from Exception,
:with => :render_error
rescue_from ActiveRecord::RecordNotFound,
:with => :render_not_found
rescue_from ActionController::UnknownAction,
:with => :render_not_found
+ rescue_from ArvadosModel::PermissionDeniedError,
+ :with => :render_error
end
def render_error(e)
--- /dev/null
+class Arvados::V1::RepositoriesController < ApplicationController
+end
--- /dev/null
+module RepositoriesHelper
+end
before_update :maybe_update_modified_by_fields
validate :ensure_serialized_attribute_type
+ class PermissionDeniedError < StandardError
+ end
+
def self.kind_class(kind)
kind.match(/^arvados\#(.+?)(_list|List)?$/)[1].pluralize.classify.constantize rescue nil
end
protected
def ensure_permission_to_create
- raise "Permission denied" unless permission_to_create
+ raise PermissionDeniedError unless permission_to_create
end
def permission_to_create
end
def ensure_permission_to_update
- raise "Permission denied" unless permission_to_update
+ raise PermissionDeniedError unless permission_to_update
end
def permission_to_update
include AssignUuid
include KindAndEtag
include CommonApiTemplate
- before_create :permission_to_set_authorized_user
- before_update :permission_to_set_authorized_user
+ before_create :permission_to_set_authorized_user_uuid
+ before_update :permission_to_set_authorized_user_uuid
- belongs_to :authorized_user, :foreign_key => :authorized_user, :class_name => 'User', :primary_key => :uuid
+ belongs_to :authorized_user, :foreign_key => :authorized_user_uuid, :class_name => 'User', :primary_key => :uuid
api_accessible :superuser, :extend => :common do |t|
t.add :name
t.add :key_type
- t.add :authorized_user
+ t.add :authorized_user_uuid
t.add :public_key
t.add :expires_at
end
- def permission_to_set_authorized_user
+ def permission_to_set_authorized_user_uuid
# Anonymous users cannot do anything here
return false if !current_user
return true if current_user.is_admin
# All users can attach keys to their own accounts
- return true if current_user.uuid == authorized_user
+ return true if current_user.uuid == authorized_user_uuid
# Default = deny.
false
--- /dev/null
+class Repository < ArvadosModel
+ include AssignUuid
+ include KindAndEtag
+ include CommonApiTemplate
+
+ api_accessible :superuser, :extend => :common do |t|
+ t.add :name
+ t.add :fetch_url
+ t.add :push_url
+ end
+
+ protected
+
+ def permission_to_create
+ current_user and current_user.is_admin
+ end
+ def permission_to_update
+ current_user and current_user.is_admin
+ end
+end
has_many :api_client_authorizations
before_update :prevent_privilege_escalation
- has_many :authorized_keys, :foreign_key => :authorized_user, :primary_key => :uuid
+ has_many :authorized_keys, :foreign_key => :authorized_user_uuid, :primary_key => :uuid
api_accessible :superuser, :extend => :common do |t|
t.add :email
Server::Application.routes.draw do
+ resources :repositories
resources :virtual_machines
resources :authorized_keys
resources :keep_disks
resources :keep_disks
resources :authorized_keys
resources :virtual_machines
+ resources :repositories
end
end
--- /dev/null
+class CreateRepositories < ActiveRecord::Migration
+ def change
+ create_table :repositories do |t|
+ t.string :uuid, :null => false
+ t.string :owner, :null => false
+ t.string :modified_by_client
+ t.string :modified_by_user
+ t.datetime :modified_at
+ t.string :name
+ t.string :fetch_url
+ t.string :push_url
+
+ t.timestamps
+ end
+ add_index :repositories, :uuid, :unique => true
+ add_index :repositories, :name
+ end
+end
--- /dev/null
+class RenameAuthorizedKeyAuthorizedUserToAuthorizedUserUuid < ActiveRecord::Migration
+ def up
+ remove_index :authorized_keys, [:authorized_user, :expires_at]
+ rename_column :authorized_keys, :authorized_user, :authorized_user_uuid
+ add_index :authorized_keys, [:authorized_user_uuid, :expires_at]
+ end
+
+ def down
+ remove_index :authorized_keys, [:authorized_user_uuid, :expires_at]
+ rename_column :authorized_keys, :authorized_user_uuid, :authorized_user
+ add_index :authorized_keys, [:authorized_user, :expires_at]
+ end
+end
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20130608053730) do
+ActiveRecord::Schema.define(:version => 20130611163736) do
create_table "api_client_authorizations", :force => true do |t|
t.string "api_token", :null => false
add_index "api_clients", ["uuid"], :name => "index_api_clients_on_uuid", :unique => true
create_table "authorized_keys", :force => true do |t|
- t.string "uuid", :null => false
- t.string "owner", :null => false
+ t.string "uuid", :null => false
+ t.string "owner", :null => false
t.string "modified_by_client"
t.string "modified_by_user"
t.datetime "modified_at"
t.string "name"
t.string "key_type"
- t.string "authorized_user"
+ t.string "authorized_user_uuid"
t.text "public_key"
t.datetime "expires_at"
t.datetime "created_at"
t.datetime "updated_at"
end
- add_index "authorized_keys", ["authorized_user", "expires_at"], :name => "index_authorized_keys_on_authorized_user_and_expires_at"
+ add_index "authorized_keys", ["authorized_user_uuid", "expires_at"], :name => "index_authorized_keys_on_authorized_user_uuid_and_expires_at"
add_index "authorized_keys", ["uuid"], :name => "index_authorized_keys_on_uuid", :unique => true
create_table "collections", :force => true do |t|
add_index "pipeline_templates", ["modified_at"], :name => "index_pipeline_templates_on_modified_at"
add_index "pipeline_templates", ["uuid"], :name => "index_pipeline_templates_on_uuid", :unique => true
+ create_table "repositories", :force => true do |t|
+ t.string "uuid", :null => false
+ t.string "owner", :null => false
+ t.string "modified_by_client"
+ t.string "modified_by_user"
+ t.datetime "modified_at"
+ t.string "name"
+ t.string "fetch_url"
+ t.string "push_url"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ end
+
+ add_index "repositories", ["name"], :name => "index_repositories_on_name"
+ add_index "repositories", ["uuid"], :name => "index_repositories_on_uuid", :unique => true
+
create_table "specimens", :force => true do |t|
t.string "uuid"
t.string "owner"
modified_at: 2013-06-06 14:35:19
name: MyString
key_type: MyString
- authorized_user: MyString
+ authorized_user_uuid: MyString
public_key: MyText
expires_at: 2013-06-06 14:35:19
modified_at: 2013-06-06 14:35:19
name: MyString
key_type: MyString
- authorized_user: MyString
+ authorized_user_uuid: MyString
public_key: MyText
expires_at: 2013-06-06 14:35:19
--- /dev/null
+# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
+
+one:
+ fetch_url: MyString
+ push_url: MyString
+
+two:
+ fetch_url: MyString
+ push_url: MyString
--- /dev/null
+require 'test_helper'
+
+class RepositoriesControllerTest < ActionController::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end
--- /dev/null
+require 'test_helper'
+
+class RepositoriesHelperTest < ActionView::TestCase
+end
--- /dev/null
+require 'test_helper'
+
+class RepositoryTest < ActiveSupport::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end