Skip to content

Commit fa75ad2

Browse files
committed
feature/Add private icon to private snippets
1 parent c2647dd commit fa75ad2

File tree

7 files changed

+27
-16
lines changed

7 files changed

+27
-16
lines changed

app/assets/stylesheets/helpers.scss

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,13 @@
5555
margin-left: 4px;
5656
}
5757
}
58-
.margin-right { margin-right: 16px }
58+
.margin-right {
59+
margin-right: 16px;
60+
61+
&--tiny {
62+
margin-right: 4px;
63+
}
64+
}
5965
.margin-auto { margin: 0 auto; }
6066

6167
.text-center { text-align: center; }

app/assets/stylesheets/toast.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
padding: 18px;
1111
box-shadow: 0px 4px 24px rgba(0, 0, 0, 0.1);
1212
text-align: center;
13-
z-index: 4;
13+
z-index: 10;
1414

1515
&-notice {
1616
@extend .toast--container;

app/controllers/snippets_controller.rb

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,6 @@ def file
7070
end
7171
end
7272

73-
def unfile_alert
74-
@snippet = current_user.filed_snippets.find(params[:id])
75-
@title = 'Unfile Snippet'
76-
@message = UNFILE_CONFIRM_TEXT
77-
@confirm_word = 'UNFILE'
78-
@confirm_path = unfile_snippet_path(@snippet)
79-
@method = :delete
80-
81-
render layout: false
82-
end
83-
8473
def current_folder
8574
snippet_folder = current_user.snippet_folders.find_by(snippet_id: params[:id])
8675

@@ -97,8 +86,8 @@ def show
9786
@page_title = "Snippet"
9887
@snippet = Snippet.includes(comments: :user).find_by(id: params[:id])
9988

100-
unless @snippet
101-
flash[:alert] = "We were unable to find that snippet"
89+
unless @snippet && @snippet.visible_to?(current_user)
90+
flash[:alert] = "You are not authorized to view that snippet"
10291
redirect_to root_path
10392
end
10493

app/javascript/controllers/modal_controller.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ export default class extends Controller {
2323
}
2424

2525
close() {
26-
if (this.hasModalTarget) { this.modalTarget.remove(); };
26+
const modal = document.getElementById('modal');
27+
28+
if (modal) { modal.remove(); };
2729
}
2830
}

app/models/snippet.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,14 @@ def client_id
6161
"snippet_#{id}"
6262
end
6363

64+
def private?
65+
!public?
66+
end
67+
68+
def visible_to?(user)
69+
self.user_id == user.try(:id)
70+
end
71+
6472
private
6573

6674
def owner_folder_presence

app/views/snippets/_snippet.html.erb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
<div>
1313
<div style="display: flex; flex-direction: column;">
1414
<div style="display: flex; justify-content: flex-end; margin-bottom: 8px; align-items: center;">
15+
<% if snippet.private? %>
16+
<img data-checkbox-target="icon" title="This snippet is only visible to you" src="/icons/lock-closed.svg" width="16">
17+
<% end %>
1518
<% if folder %>
1619
<div class="folder-tag">
1720
<img src="/icons/icons8-folder-white.svg" width="12">

app/views/snippets/_snippet_preview.html.erb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
<div>
1212
<div style="display: flex; flex-direction: column;">
1313
<div style="display: flex; justify-content: flex-end; margin-bottom: 8px; align-items: center;">
14+
<% if snippet.private? %>
15+
<img class="margin-right--tiny" title="This snippet is only visible to you" data-checkbox-target="icon" src="/icons/lock-closed.svg" width="16">
16+
<% end %>
1417
<% if folder %>
1518
<div class="folder-tag">
1619
<img src="/icons/icons8-folder-white.svg" width="12">

0 commit comments

Comments
 (0)