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

Commit

Permalink
Only show the needed circles
Browse files Browse the repository at this point in the history
Fixes the previous commit so only the proper circles are shown to the current
user.

Signed-off-by: Miquel Sabaté Solà <[email protected]>
  • Loading branch information
mssola committed Jun 2, 2016
1 parent dc2abf4 commit a3ffe49
Show file tree
Hide file tree
Showing 5 changed files with 145 additions and 83 deletions.
22 changes: 21 additions & 1 deletion app/helpers/namespaces_helper.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
module NamespacesHelper
def can_manage_namespace?(namespace)
current_user.admin? || namespace.team.owners.exists?(current_user.id)
current_user.admin? || owner?(namespace)
end

def owner?(namespace)
namespace.team.owners.exists?(current_user.id)
end

def contributor?(namespace)
namespace.team.contributors.exists?(current_user.id)
end

def viewer?(namespace)
namespace.team.viewers.exists?(current_user.id)
end

def can_pull?(namespace)
NamespacePolicy.new(current_user, namespace).pull?
end

def can_push?(namespace)
NamespacePolicy.new(current_user, namespace).push?
end
end
85 changes: 45 additions & 40 deletions app/views/namespaces/show.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -56,46 +56,51 @@
| <span>Belongs to: </span>
= link_to "#{@namespace.team.name}", @namespace.team
.col-xs-6.text-right
.circle-label.permissions-label.circle-label-sm[data-placement="left"
data-toggle="popover"
data-container=".panel-heading"
data-content="You can push images"
data-original-title="What can I do?"
tabindex="0" data-html="true"]
i.fa.fa-arrow-up
' Push
.circle-label.permissions-label.circle-label-sm[data-placement="left"
data-toggle="popover"
data-container=".panel-heading"
data-content="You can pull images"
data-original-title="What can I do?"
tabindex="0" data-html="true"]
i.fa.fa-arrow-down
' Pull
.circle-label.permissions-label.circle-label-sm[data-placement="left"
data-toggle="popover"
data-container=".panel-heading"
data-content="You are the owner of this namespace"
data-original-title="What's my role?"
tabindex="0" data-html="true"]
i.fa.fa-male
' Owner
.circle-label.permissions-label.circle-label-sm[data-placement="left"
data-toggle="popover"
data-container=".panel-heading"
data-content="You are a contributor in this namespace"
data-original-title="What's my role?"
tabindex="0" data-html="true"]
i.fa.fa-exchange
' Contr.
.circle-label.permissions-label.circle-label-sm[data-placement="left"
data-toggle="popover"
data-container=".panel-heading"
data-content="You are a viewer in this namespace"
data-original-title="What's my role?"
tabindex="0" data-html="true"]
i.fa.fa-eye
' Viewer
- if can_push?(@namespace)
.circle-label.permissions-label.circle-label-sm[data-placement="left"
data-toggle="popover"
data-container=".panel-heading"
data-content="You can push images"
data-original-title="What can I do?"
tabindex="0" data-html="true"]
i.fa.fa-arrow-up
' Push
- if can_pull?(@namespace)
.circle-label.permissions-label.circle-label-sm[data-placement="left"
data-toggle="popover"
data-container=".panel-heading"
data-content="You can pull images"
data-original-title="What can I do?"
tabindex="0" data-html="true"]
i.fa.fa-arrow-down
' Pull
- if owner?(@namespace)
.circle-label.permissions-label.circle-label-sm[data-placement="left"
data-toggle="popover"
data-container=".panel-heading"
data-content="You are an owner of this namespace"
data-original-title="What's my role?"
tabindex="0" data-html="true"]
i.fa.fa-male
' Owner
- elsif contributor?(@namespace)
.circle-label.permissions-label.circle-label-sm[data-placement="left"
data-toggle="popover"
data-container=".panel-heading"
data-content="You are a contributor in this namespace"
data-original-title="What's my role?"
tabindex="0" data-html="true"]
i.fa.fa-exchange
' Contr.
- elsif viewer?(@namespace)
.circle-label.permissions-label.circle-label-sm[data-placement="left"
data-toggle="popover"
data-container=".panel-heading"
data-content="You are a viewer in this namespace"
data-original-title="What's my role?"
tabindex="0" data-html="true"]
i.fa.fa-eye
' Viewer

.panel-body
.table-responsive
Expand Down
85 changes: 45 additions & 40 deletions app/views/repositories/show.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -33,46 +33,51 @@
| /
= @repository.name
.col-xs-6.text-right
.circle-label.permissions-label.circle-label-sm[data-placement="left"
data-toggle="popover"
data-container=".panel-heading"
data-content="You can push images"
data-original-title="What can I do?"
tabindex="0" data-html="true"]
i.fa.fa-arrow-up
' Push
.circle-label.permissions-label.circle-label-sm[data-placement="left"
data-toggle="popover"
data-container=".panel-heading"
data-content="You can pull images"
data-original-title="What can I do?"
tabindex="0" data-html="true"]
i.fa.fa-arrow-down
' Pull
.circle-label.permissions-label.circle-label-sm[data-placement="left"
data-toggle="popover"
data-container=".panel-heading"
data-content="You are the owner of this repository"
data-original-title="What's my role?"
tabindex="0" data-html="true"]
i.fa.fa-male
' Owner
.circle-label.permissions-label.circle-label-sm[data-placement="left"
data-toggle="popover"
data-container=".panel-heading"
data-content="You are a contributor in this repository"
data-original-title="What's my role?"
tabindex="0" data-html="true"]
i.fa.fa-exchange
' Contr.
.circle-label.permissions-label.circle-label-sm[data-placement="left"
data-toggle="popover"
data-container=".panel-heading"
data-content="You are a viewer in this repository"
data-original-title="What's my role?"
tabindex="0" data-html="true"]
i.fa.fa-eye
' Viewer
- if can_push?(@repository.namespace)
.circle-label.permissions-label.circle-label-sm[data-placement="left"
data-toggle="popover"
data-container=".panel-heading"
data-content="You can push images"
data-original-title="What can I do?"
tabindex="0" data-html="true"]
i.fa.fa-arrow-up
' Push
- if can_pull?(@repository.namespace)
.circle-label.permissions-label.circle-label-sm[data-placement="left"
data-toggle="popover"
data-container=".panel-heading"
data-content="You can pull images"
data-original-title="What can I do?"
tabindex="0" data-html="true"]
i.fa.fa-arrow-down
' Pull
- if owner?(@repository.namespace)
.circle-label.permissions-label.circle-label-sm[data-placement="left"
data-toggle="popover"
data-container=".panel-heading"
data-content="You are an owner of this repository"
data-original-title="What's my role?"
tabindex="0" data-html="true"]
i.fa.fa-male
' Owner
- elsif contributor?(@repository.namespace)
.circle-label.permissions-label.circle-label-sm[data-placement="left"
data-toggle="popover"
data-container=".panel-heading"
data-content="You are a contributor in this repository"
data-original-title="What's my role?"
tabindex="0" data-html="true"]
i.fa.fa-exchange
' Contr.
- elsif viewer?(@repository.namespace)
.circle-label.permissions-label.circle-label-sm[data-placement="left"
data-toggle="popover"
data-container=".panel-heading"
data-content="You are a viewer in this repository"
data-original-title="What's my role?"
tabindex="0" data-html="true"]
i.fa.fa-eye
' Viewer


.panel-body
Expand Down
19 changes: 18 additions & 1 deletion spec/features/namespaces_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
feature "Namespaces support" do
let!(:registry) { create(:registry) }
let!(:user) { create(:admin) }
let!(:team) { create(:team, owners: [user]) }
let!(:user2) { create(:user) }
let!(:user3) { create(:user) }
let!(:team) { create(:team, owners: [user], contributors: [user2], viewers: [user3]) }
let!(:namespace) { create(:namespace, team: team, registry: registry) }

before do
Expand Down Expand Up @@ -139,4 +141,19 @@
expect(page).to have_content("Team 'unknown' unknown")
end
end

describe "#show" do
it "shows the proper visual aid for each role", js: true do
visit namespace_path(namespace.id)
expect(page).to have_content("Push Pull Owner")

login_as user2, scope: :user
visit namespace_path(namespace.id)
expect(page).to have_content("Push Pull Contr.")

login_as user3, scope: :user
visit namespace_path(namespace.id)
expect(page).to have_content("Pull Viewer")
end
end
end
17 changes: 16 additions & 1 deletion spec/features/repositories_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
feature "Repositories support" do
let!(:registry) { create(:registry) }
let!(:user) { create(:admin) }
let!(:team) { create(:team, owners: [user]) }
let!(:user2) { create(:user) }
let!(:user3) { create(:user) }
let!(:team) { create(:team, owners: [user], contributors: [user2], viewers: [user3]) }
let!(:namespace) { create(:namespace, team: team) }
let!(:repository) { create(:repository, namespace: namespace) }
let!(:starred_repo) { create(:repository, namespace: namespace) }
Expand All @@ -14,6 +16,19 @@
end

describe "repository#show" do
scenario "Visual aid for each role is shown properly", js: true do
visit repository_path(repository)
expect(page).to have_content("Push Pull Owner")

login_as user2, scope: :user
visit repository_path(repository)
expect(page).to have_content("Push Pull Contr.")

login_as user3, scope: :user
visit repository_path(repository)
expect(page).to have_content("Pull Viewer")
end

scenario "A user can star a repository", js: true do
visit repository_path(repository)
expect(find("#toggle_star")).to be_visible
Expand Down

0 comments on commit a3ffe49

Please sign in to comment.