Skip to content
This repository has been archived by the owner on Apr 17, 2023. It is now read-only.

Commit

Permalink
Merge branch 'master' of github.com:SUSE/Portus into UI-review-and-fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
cyntss committed Jun 13, 2016
2 parents 818354d + 213b734 commit 33ac4c7
Show file tree
Hide file tree
Showing 127 changed files with 2,664 additions and 252 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ gem "redcarpet"
gem "font-awesome-rails"
gem "bootstrap-typeahead-rails"
gem "rails_stdout_logging", "~> 0.0.5", group: [:development, :staging, :production]
gem "typhoeus"

# Used to store application tokens. This is already a Rails depedency. However
# better safe than sorry...
Expand Down
7 changes: 6 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ GEM
execjs
coffee-script-source (1.9.1.1)
columnize (0.9.0)
crack (0.4.2)
crack (0.4.3)
safe_yaml (~> 1.0.0)
crono (0.9.0)
activerecord (~> 4.0)
Expand All @@ -113,6 +113,8 @@ GEM
excon (>= 0.38.0)
json
erubis (2.7.0)
ethon (0.8.1)
ffi (>= 1.3.0)
excon (0.49.0)
execjs (2.2.2)
factory_girl (4.5.0)
Expand Down Expand Up @@ -355,6 +357,8 @@ GEM
polyglot (~> 0.3)
turbolinks (2.5.3)
coffee-rails
typhoeus (1.0.1)
ethon (>= 0.8.0)
tzinfo (1.2.2)
thread_safe (~> 0.1)
uglifier (2.7.2)
Expand Down Expand Up @@ -441,6 +445,7 @@ DEPENDENCIES
thor
timecop
turbolinks
typhoeus
uglifier
vcr
web-console (~> 2.1.3)
Expand Down
15 changes: 14 additions & 1 deletion app/assets/javascripts/profile.coffee
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@

jQuery ->
email = $('#user_email').val()
display = $('#user_display_name').val()

$('#user_email').keyup ->
val = $('#user_email').val()
if val == email || val == ''
dname = $('#user_display_name').val()

if dname == display && (val == email || val == '')
$('#edit_user.profile .btn').attr('disabled', 'disabled')
else
$('#edit_user.profile .btn').removeAttr('disabled')

$('#user_display_name').keyup ->
val = $('#user_display_name').val()
em = $('#user_email').val()

if val == display && (em == email || em == '')
$('#edit_user.profile .btn').attr('disabled', 'disabled')
else
$('#edit_user.profile .btn').removeAttr('disabled')
Expand Down
40 changes: 40 additions & 0 deletions app/assets/javascripts/teams.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,46 @@ $(document).on "page:change", ->
layout_resizer()
set_typeahead('/namespaces/typeahead/%QUERY')

$('#add_webhook_btn').unbind('click').on 'click', (event) ->
$('#webhook_url').val('')
$('#webhook_username').val('')
$('#webhook_password').val('')

$('#add_webhook_form').toggle 400, "swing", ->
if $('#add_webhook_form').is(':visible')
$('#add_webhook_btn i').addClass("fa-minus-circle")
$('#add_webhook_btn i').removeClass("fa-plus-circle")
$('#webhook_url').focus()
layout_resizer()
else
$('#add_webhook_btn i').removeClass("fa-minus-circle")
$('#add_webhook_btn i').addClass("fa-plus-circle")
layout_resizer()

$('body').on('click', '.btn-edit-webhook', (event) ->
el = $(this).find('i.fa')
if $(this).hasClass('button_edit_webhook')
$('.webhook_information').toggle()
$('#update_webhook_' + event.currentTarget.value).toggle()
$('#webhook_url').focus()
layout_resizer()
)

$('#add_webhook_header_btn').unbind('click').on 'click', (event) ->
$('#webhook_header_name').val('')
$('#webhook_header_value').val('')

$('#add_webhook_header_form').toggle 400, "swing", ->
if $('#add_webhook_header_form').is(':visible')
$('#add_webhook_header_btn i').addClass("fa-minus-circle")
$('#add_webhook_header_btn i').removeClass("fa-plus-circle")
$('#webhook_header_name').focus()
layout_resizer()
else
$('#add_webhook_header_btn i').removeClass("fa-minus-circle")
$('#add_webhook_header_btn i').addClass("fa-plus-circle")
layout_resizer()

$('#add_team_btn').on 'click', (event) ->
$('#team_name').val('')
$('#add_team_form').toggle 400, "swing", ->
Expand Down
6 changes: 6 additions & 0 deletions app/assets/stylesheets/activities.scss
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@
&.application-token-destroyed {
background: $activity-application-token-destroyed;
}
&.change-webhook-visibility {
background: $activity-change-webhook-visibility;
}
&.create-webhook {
background: $activity-create-webhook;
}
}
}
}
2 changes: 2 additions & 0 deletions app/assets/stylesheets/variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ $font-size-h2: floor(($font-size-base * 1.95));
$activity-change-description: $light-blue;
$activity-create-namespace: $blue;
$activity-change-namespace-visibility: $dark-green;
$activity-create-webhook: $blue;
$activity-change-webhook-visibility: $dark-green;
$activity-add-member-team: $green;
$activity-remove-member-team: $yellow;
$activity-change-role: $orange;
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/admin/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def edit
def update
return if @user.nil?

attr = params.require(:user).permit([:email])
attr = params.require(:user).permit([:email, :display_name])

if @user.update_attributes(attr)
redirect_to admin_users_path, notice: "User updated successfully", float: true
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/api/v2/events_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class Api::V2::EventsController < Api::BaseController
# A new notification is coming, register it if valid.
def create
body = JSON.parse(request.body.read)
Portus::RegistryNotification.process!(body, Repository)
Portus::RegistryNotification.process!(body, Repository, Webhook)
head status: :accepted
end
end
5 changes: 3 additions & 2 deletions app/controllers/auth/registrations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ class Auth::RegistrationsController < Devise::RegistrationsController
layout "authentication", except: :edit

include CheckLDAP
include SessionFlash

before_action :check_signup, only: [:new, :create]
before_action :check_admin, only: [:new, :create]
Expand All @@ -20,7 +21,7 @@ def create

resource.save
if resource.persisted?
set_flash_message :notice, :signed_up
session_flash(resource, :signed_up)
sign_up(resource_name, resource)
respond_with resource, location: after_sign_up_path_for(resource), float: true
else
Expand All @@ -41,7 +42,7 @@ def update
sign_in(current_user, bypass: true) if succ
succ
else
current_user.update_without_password(params.require(:user).permit(:email))
current_user.update_without_password(params.require(:user).permit(:email, :display_name))
end

if success
Expand Down
10 changes: 9 additions & 1 deletion app/controllers/auth/sessions_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
class Auth::SessionsController < Devise::SessionsController
include SessionFlash

layout "authentication"

# Re-implementing. The logic is: if there is already a user that can log in
Expand All @@ -23,7 +25,13 @@ def new

def create
super
flash[:notice] = nil

if ::Portus::LDAP.enabled? && session[:first_login]
session[:first_login] = nil
session_flash(current_user, nil)
else
flash[:notice] = nil
end
end

def destroy
Expand Down
33 changes: 33 additions & 0 deletions app/controllers/concerns/session_flash.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# SessionFlash adds the `session_flash` method which deals with flashy messages
# on signup/login, while notifying users about their personal namespace.
module SessionFlash
extend ActiveSupport::Concern

# Sets the flash object accordingly for the given authenticated user. The
# method is the Devise method to be used for greeting the user (e.g.
# `:signed_up`). If method is nil, then a generic greeting will be set. This
# method also notifies users about their personal namespace (and whether it
# changed or not).
def session_flash(user, method)
# First of all we've got a greeting.
if method.nil?
flash[:notice] = "Welcome!"
else
set_flash_message :notice, method unless method.nil?
end

# This will happen for the first user, which is the admin that has to
# configure the registry.
return if user.namespace.nil?

# Now inform the user
ns = user.namespace.name
str = " Your personal namespace is '#{ns}'"
if user.username == ns
str += "."
else
str += " (your username was not a valid Docker namespace, so we had to tweak it)."
end
flash[:notice] << str
end
end
2 changes: 1 addition & 1 deletion app/controllers/dashboard_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def index

# The personal namespace could not exist, that happens when portus
# does not have a registry associated yet (right after the initial setup)
personal_namespace = Namespace.find_by(name: current_user.username)
personal_namespace = current_user.namespace
@personal_repositories = personal_namespace ? personal_namespace.repositories : []

@stars = current_user.stars.order("updated_at desc")
Expand Down
18 changes: 18 additions & 0 deletions app/controllers/webhook_deliveries_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# WebhookDeliveriesController manages the updates of webhook deliveries.
class WebhookDeliveriesController < ApplicationController
respond_to :html, :js

after_action :verify_authorized

# PATCH/PUT /namespaces/1/webhooks/1/deliveries/1
def update
namespace = Namespace.find(params[:namespace_id])
webhook = namespace.webhooks.find(params[:webhook_id])
webhook_delivery = webhook.deliveries.find(params[:id])

authorize webhook_delivery

webhook_delivery.retrigger
render template: "webhooks/retrigger", locals: { webhook_delivery: webhook_delivery }
end
end
47 changes: 47 additions & 0 deletions app/controllers/webhook_headers_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# WebhookHeadersController manages the creation/removal of webhook headers.
class WebhookHeadersController < ApplicationController
respond_to :html, :js

before_action :set_namespace
before_action :set_webhook

after_action :verify_authorized

# POST /namespaces/1/webhooks/1/headers
# POST /namespaces/1/webhooks/1/headers.json
def create
@webhook_header = @webhook.headers.build(webhook_header_params)
authorize @webhook_header

if @webhook_header.save
respond_with @namespace, @webhook, @webhook_header
else
respond_with @webhook_header.errors, status: :unprocessable_entity
end
end

# DELETE /namespaces/1/webhooks/1/headers/1
# DELETE /namespaces/1/webhooks/1/headers/1.json
def destroy
@webhook_header = @webhook.headers.find(params[:id])

authorize @webhook_header

@webhook_header.destroy
respond_with @namespace, @webhook, @webhook_header
end

private

def set_namespace
@namespace = Namespace.find(params[:namespace_id])
end

def set_webhook
@webhook = @namespace.webhooks.find(params[:webhook_id])
end

def webhook_header_params
params.require(:webhook_header).permit(:name, :value)
end
end
Loading

0 comments on commit 33ac4c7

Please sign in to comment.