From 63f9b5374e01394486a07dba4f9a43cfd76707e3 Mon Sep 17 00:00:00 2001 From: Tom Clegg Date: Tue, 11 Jun 2013 13:00:06 -0400 Subject: [PATCH] add Repositories resource, fix authorized_user attr name, some wb fixes --- .../assets/javascripts/repositories.js.coffee | 3 ++ .../app/assets/stylesheets/application.css | 4 ++ .../assets/stylesheets/repositories.css.scss | 3 ++ .../app/controllers/application_controller.rb | 4 +- .../controllers/authorized_keys_controller.rb | 4 +- .../controllers/repositories_controller.rb | 2 + .../app/controllers/sessions_controller.rb | 2 +- .../app/helpers/repositories_helper.rb | 2 + apps/workbench/app/models/arvados_base.rb | 9 +++- .../app/models/arvados_resource_list.rb | 4 ++ apps/workbench/app/models/authorized_key.rb | 2 +- apps/workbench/app/models/repository.rb | 5 ++ apps/workbench/app/models/user.rb | 4 ++ .../app/views/application/index.html.erb | 50 +++++++++++++++++ .../app/views/authorized_keys/_form.html.erb | 31 ----------- .../app/views/authorized_keys/index.html.erb | 53 ------------------- .../app/views/authorized_keys/new.html.erb | 1 - .../app/views/authorized_keys/show.html.erb | 1 - .../app/views/layouts/application.html.erb | 2 + .../app/views/virtual_machines/index.html.erb | 41 -------------- apps/workbench/config/routes.rb | 3 ++ apps/workbench/test/fixtures/repositories.yml | 11 ++++ .../repositories_controller_test.rb | 7 +++ .../unit/helpers/repositories_helper_test.rb | 4 ++ apps/workbench/test/unit/repository_test.rb | 7 +++ .../assets/javascripts/repositories.js.coffee | 3 ++ .../assets/stylesheets/repositories.css.scss | 3 ++ .../app/controllers/application_controller.rb | 4 +- .../arvados/v1/repositories_controller.rb | 2 + .../api/app/helpers/repositories_helper.rb | 2 + services/api/app/models/arvados_model.rb | 7 ++- services/api/app/models/authorized_key.rb | 12 ++--- services/api/app/models/repository.rb | 20 +++++++ services/api/app/models/user.rb | 2 +- services/api/config/routes.rb | 2 + .../20130610202538_create_repositories.rb | 18 +++++++ ...authorized_user_to_authorized_user_uuid.rb | 13 +++++ services/api/db/schema.rb | 26 +++++++-- .../api/test/fixtures/authorized_keys.yml | 4 +- services/api/test/fixtures/repositories.yml | 9 ++++ .../repositories_controller_test.rb | 7 +++ .../unit/helpers/repositories_helper_test.rb | 4 ++ services/api/test/unit/repository_test.rb | 7 +++ 43 files changed, 253 insertions(+), 151 deletions(-) create mode 100644 apps/workbench/app/assets/javascripts/repositories.js.coffee create mode 100644 apps/workbench/app/assets/stylesheets/repositories.css.scss create mode 100644 apps/workbench/app/controllers/repositories_controller.rb create mode 100644 apps/workbench/app/helpers/repositories_helper.rb create mode 100644 apps/workbench/app/models/repository.rb create mode 100644 apps/workbench/app/views/application/index.html.erb delete mode 100644 apps/workbench/app/views/authorized_keys/_form.html.erb delete mode 100644 apps/workbench/app/views/authorized_keys/index.html.erb delete mode 100644 apps/workbench/app/views/authorized_keys/new.html.erb delete mode 100644 apps/workbench/app/views/authorized_keys/show.html.erb delete mode 100644 apps/workbench/app/views/virtual_machines/index.html.erb create mode 100644 apps/workbench/test/fixtures/repositories.yml create mode 100644 apps/workbench/test/functional/repositories_controller_test.rb create mode 100644 apps/workbench/test/unit/helpers/repositories_helper_test.rb create mode 100644 apps/workbench/test/unit/repository_test.rb create mode 100644 services/api/app/assets/javascripts/repositories.js.coffee create mode 100644 services/api/app/assets/stylesheets/repositories.css.scss create mode 100644 services/api/app/controllers/arvados/v1/repositories_controller.rb create mode 100644 services/api/app/helpers/repositories_helper.rb create mode 100644 services/api/app/models/repository.rb create mode 100644 services/api/db/migrate/20130610202538_create_repositories.rb create mode 100644 services/api/db/migrate/20130611163736_rename_authorized_key_authorized_user_to_authorized_user_uuid.rb create mode 100644 services/api/test/fixtures/repositories.yml create mode 100644 services/api/test/functional/repositories_controller_test.rb create mode 100644 services/api/test/unit/helpers/repositories_helper_test.rb create mode 100644 services/api/test/unit/repository_test.rb diff --git a/apps/workbench/app/assets/javascripts/repositories.js.coffee b/apps/workbench/app/assets/javascripts/repositories.js.coffee new file mode 100644 index 0000000000..761567942f --- /dev/null +++ b/apps/workbench/app/assets/javascripts/repositories.js.coffee @@ -0,0 +1,3 @@ +# 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/ diff --git a/apps/workbench/app/assets/stylesheets/application.css b/apps/workbench/app/assets/stylesheets/application.css index 829b1759f1..8f67306c2b 100644 --- a/apps/workbench/app/assets/stylesheets/application.css +++ b/apps/workbench/app/assets/stylesheets/application.css @@ -42,3 +42,7 @@ body .editable-empty { body .editable-empty:hover { color: #0088cc; } +table.arv-index tbody td.arv-object-AuthorizedKey.arv-attr-public_key { + overflow-x: hidden; + max-width: 120px; +} diff --git a/apps/workbench/app/assets/stylesheets/repositories.css.scss b/apps/workbench/app/assets/stylesheets/repositories.css.scss new file mode 100644 index 0000000000..85e38d231e --- /dev/null +++ b/apps/workbench/app/assets/stylesheets/repositories.css.scss @@ -0,0 +1,3 @@ +// 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/ diff --git a/apps/workbench/app/controllers/application_controller.rb b/apps/workbench/app/controllers/application_controller.rb index b65b00aae9..3fabcaa8eb 100644 --- a/apps/workbench/app/controllers/application_controller.rb +++ b/apps/workbench/app/controllers/application_controller.rb @@ -100,12 +100,12 @@ class ApplicationController < ActionController::Base 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 diff --git a/apps/workbench/app/controllers/authorized_keys_controller.rb b/apps/workbench/app/controllers/authorized_keys_controller.rb index 5ca5222d6e..a2beb494e4 100644 --- a/apps/workbench/app/controllers/authorized_keys_controller.rb +++ b/apps/workbench/app/controllers/authorized_keys_controller.rb @@ -1,12 +1,12 @@ 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 diff --git a/apps/workbench/app/controllers/repositories_controller.rb b/apps/workbench/app/controllers/repositories_controller.rb new file mode 100644 index 0000000000..d710bd611d --- /dev/null +++ b/apps/workbench/app/controllers/repositories_controller.rb @@ -0,0 +1,2 @@ +class RepositoriesController < ApplicationController +end diff --git a/apps/workbench/app/controllers/sessions_controller.rb b/apps/workbench/app/controllers/sessions_controller.rb index 6531e3d9ed..ba08137589 100644 --- a/apps/workbench/app/controllers/sessions_controller.rb +++ b/apps/workbench/app/controllers/sessions_controller.rb @@ -3,7 +3,7 @@ class SessionsController < ApplicationController 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] diff --git a/apps/workbench/app/helpers/repositories_helper.rb b/apps/workbench/app/helpers/repositories_helper.rb new file mode 100644 index 0000000000..2860b5a916 --- /dev/null +++ b/apps/workbench/app/helpers/repositories_helper.rb @@ -0,0 +1,2 @@ +module RepositoriesHelper +end diff --git a/apps/workbench/app/models/arvados_base.rb b/apps/workbench/app/models/arvados_base.rb index cb4463a9be..267a4a9133 100644 --- a/apps/workbench/app/models/arvados_base.rb +++ b/apps/workbench/app/models/arvados_base.rb @@ -204,6 +204,10 @@ class ArvadosBase < ActiveRecord::Base } end + def self.creatable? + current_user + end + def editable? (current_user and (current_user.is_admin or @@ -257,8 +261,11 @@ class ArvadosBase < ActiveRecord::Base 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 diff --git a/apps/workbench/app/models/arvados_resource_list.rb b/apps/workbench/app/models/arvados_resource_list.rb index a3032a67f2..c8e6de6302 100644 --- a/apps/workbench/app/models/arvados_resource_list.rb +++ b/apps/workbench/app/models/arvados_resource_list.rb @@ -94,4 +94,8 @@ class ArvadosResourceList def to_hash Hash[results.collect { |x| [x.uuid, x] }] end + + def empty? + results.empty? + end end diff --git a/apps/workbench/app/models/authorized_key.rb b/apps/workbench/app/models/authorized_key.rb index 62ee83238d..c018cc56b0 100644 --- a/apps/workbench/app/models/authorized_key.rb +++ b/apps/workbench/app/models/authorized_key.rb @@ -1,6 +1,6 @@ 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) diff --git a/apps/workbench/app/models/repository.rb b/apps/workbench/app/models/repository.rb new file mode 100644 index 0000000000..06c70f4688 --- /dev/null +++ b/apps/workbench/app/models/repository.rb @@ -0,0 +1,5 @@ +class Repository < ArvadosBase + def self.creatable? + current_user and current_user.is_admin + end +end diff --git a/apps/workbench/app/models/user.rb b/apps/workbench/app/models/user.rb index 625f505a1c..0dec2e0ba8 100644 --- a/apps/workbench/app/models/user.rb +++ b/apps/workbench/app/models/user.rb @@ -9,4 +9,8 @@ class User < ArvadosBase 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 diff --git a/apps/workbench/app/views/application/index.html.erb b/apps/workbench/app/views/application/index.html.erb new file mode 100644 index 0000000000..0d7657f512 --- /dev/null +++ b/apps/workbench/app/views/application/index.html.erb @@ -0,0 +1,50 @@ +<% if @objects.empty? %> + +

+ No <%= controller.model_class.to_s.underscore.pluralize.gsub '_', ' ' %> to display. +

+ +<% else %> + +<% attr_blacklist = 'created_at modified_at modified_by_user modified_by_client updated_at' %> + + + + + <% @objects.first.attributes_for_display.each do |attr, attrvalue| %> + <% next if attr_blacklist.index attr %> + + <% end %> + + + + + <% @objects.each do |object| %> + + <% object.attributes_for_display.each do |attr, attrvalue| %> + <% next if attr_blacklist.index attr %> + + <% end %> + + <% end %> + + + + +
+ <%= attr.sub /_uuid/, '' %> +
+ <% 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 %> +
+ +<% 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 %> diff --git a/apps/workbench/app/views/authorized_keys/_form.html.erb b/apps/workbench/app/views/authorized_keys/_form.html.erb deleted file mode 100644 index 5a7231d07f..0000000000 --- a/apps/workbench/app/views/authorized_keys/_form.html.erb +++ /dev/null @@ -1,31 +0,0 @@ -<%= form_for @object do |f| %> - - - - - - - - - - - - - - -
- name - - <%= f.text_field :name %> -
- authorized user - - <%= f.text_field :authorized_user %> -
- public key - - <%= f.text_area :public_key %> -
- <%= f.submit class: 'btn btn-primary' %> -
-<% end %> diff --git a/apps/workbench/app/views/authorized_keys/index.html.erb b/apps/workbench/app/views/authorized_keys/index.html.erb deleted file mode 100644 index bdfc2f7eb6..0000000000 --- a/apps/workbench/app/views/authorized_keys/index.html.erb +++ /dev/null @@ -1,53 +0,0 @@ - - - - - - - - - <% @objects.sort_by { |ak| ak[:created_at] }.each do |ak| %> - - - - - - <% end %> - <% if @objects.count == 0 %> - - - - <% end %> - - -
- id - - owner - - name - - key type - - public key - - expires -
- <%= link_to_if_arvados_object ak %> - - <%= render_editable_attribute ak, 'owner' %> - - <%= render_editable_attribute ak, 'name' %> - - <%= render_editable_attribute ak, 'key_type', ak.key_type, "data-type" => "select", "data-source" => '[{value:"SSH",text:"SSH"}]' %> - - <%= render_editable_attribute ak, 'public_key' %> - - <%= render_editable_attribute ak, 'expires_at' %> - - <%= link_to raw(''), { action: 'destroy', id: ak.uuid }, { confirm: 'Delete this key?', method: 'delete' } %> -
- (no authorized keys) -
- -<%= button_to "Add a new key", { action: 'create', return_to: './' }, { class: 'btn btn-primary' } %> diff --git a/apps/workbench/app/views/authorized_keys/new.html.erb b/apps/workbench/app/views/authorized_keys/new.html.erb deleted file mode 100644 index 23997ae13a..0000000000 --- a/apps/workbench/app/views/authorized_keys/new.html.erb +++ /dev/null @@ -1 +0,0 @@ -<%= render partial: 'form' %> diff --git a/apps/workbench/app/views/authorized_keys/show.html.erb b/apps/workbench/app/views/authorized_keys/show.html.erb deleted file mode 100644 index 90790856ae..0000000000 --- a/apps/workbench/app/views/authorized_keys/show.html.erb +++ /dev/null @@ -1 +0,0 @@ -<%= render :partial => 'application/arvados_object' %> diff --git a/apps/workbench/app/views/layouts/application.html.erb b/apps/workbench/app/views/layouts/application.html.erb index a9081ccaf5..bca12e974d 100644 --- a/apps/workbench/app/views/layouts/application.html.erb +++ b/apps/workbench/app/views/layouts/application.html.erb @@ -35,6 +35,7 @@ <% [ [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], @@ -48,6 +49,7 @@