add privacy setting for file

This commit is contained in:
邱博亞 2020-12-19 18:28:18 +08:00
parent 55938d106a
commit 5448b69278
4 changed files with 179 additions and 135 deletions

View File

@ -233,7 +233,10 @@ class AnnouncementsController < ApplicationController
"tag" => tag.name ,
"url" => OrbitHelper.page_for_tag(tag)
} } rescue []
files = announcement.bulletin_files.map{|file| { "file_url" => file.file.url, "file_title" => (file.title.blank? ? URI.unescape(File.basename(file.file.path)) : file.title rescue '') } if file.enabled_for?(locale) } rescue []
files = announcement.bulletin_files.map do |file|
{ "file_url" => file.file.url,
"file_title" => (file.title.blank? ? URI.unescape(File.basename(file.file.path)) : file.title rescue '') } if file.enabled_for?(locale) and file.can_access?(OrbitHelper.current_user)
end rescue []
files.delete(nil)
files.each do |file|
if file["file_url"] =="" || file["file_url"] == nil

View File

@ -9,7 +9,7 @@ class BulletinFile
field :description, localize: true
field :title, localize: true
field :choose_lang, :type => Array, :default => ["en","zh_tw"]
field :privacy_type, type: String, default: 'public'
belongs_to :bulletin
@ -20,5 +20,11 @@ class BulletinFile
return self.choose_lang.include?(lang)
end
end
def can_access?(user)
if user.nil? && self.privacy_type == 'logged_in'
return false
else
return true
end
end
end

View File

@ -13,6 +13,12 @@
cursor: default;
display: inline-block;
}
.add-on.btn-group .dropdown-menu{
margin: 0;
}
.main-forms fieldset .input-area .controls .input-prepend a:hover{
color: #fff;
}
</style>
<% content_for :page_specific_javascript do %>
<%= javascript_include_tag "lib/bootstrap-fileupload" %>
@ -482,7 +488,6 @@
})
</script>
<% end %>
<% content_for :page_specific_javascript do %>
<script>
function Appendzero(obj)
{
@ -615,5 +620,15 @@
})
});
$(".privacy-changer-btn").click(function(){
var val = $(this).attr('for')
var parent_node = $(this).parents('.add-on.btn-group').eq(0)
parent_node.find('.privacy_type').val(val)
parent_node.find('i').eq(0).attr('class',$(this).find('i').attr('class'))
parent_node.find('.dropdown-menu').hide()
window.setTimeout(function(){
parent_node.find('.dropdown-menu').css('display','')
},1000)
})
</script>
<% end %>

View File

@ -65,5 +65,25 @@
<%= f.hidden_field :_destroy, :value => nil, :class => 'should_destroy' %>
</span>
<% end %>
<span class="add-on btn-group btn" style="background: white;border: 0;margin-left: 1em;">
<% case form_file.privacy_type
when "public"
icon = "icons-earth"
when "logged_in"
icon = "icons-users"
end
%>
<i class="<%= icon %>"></i> <span class="caret"></span>
<ul class="dropdown-menu">
<li>
<a class="privacy-changer-btn" for="public"><i class="icons-earth"></i><%= t('privacy_type.public') %></a>
</li>
<li class="divider"></li>
<li>
<a class="privacy-changer-btn" for="logged_in"><i class="icons-users"></i><%= t('privacy_type.logged_in') %></a>
</li>
</ul>
<%= f.hidden_field :privacy_type, class: 'privacy_type' %>
</span>
</div>
</div>