Diff
Modified: trunk/app/controllers/application_controller.rb (3299 => 3300)
--- trunk/app/controllers/application_controller.rb 2013-01-15 12:05:20 UTC (rev 3299)
+++ trunk/app/controllers/application_controller.rb 2013-01-15 12:24:11 UTC (rev 3300)
@@ -183,19 +183,28 @@
# this method will return an error message is something goes wrong (empty string in case of success)
error_msg = ""
-
# BEGIN validation and initialisation
-
+
+ # If a group policy was selected, use that, and delete the old custom one (if there was one).
+ if params[:policy_type] == "group"
+ if contributable.contribution.policy && !contributable.contribution.policy.group_policy?
+ contributable.contribution.policy.delete
+ end
+ contributable.contribution.policy_id = params[:group_policy]
+ contributable.contribution.save
+ return
+ end
+
# This variable will hold current settings of the policy in case something
# goes wrong and a revert would be needed at some point
last_saved_policy = nil
return if params[:sharing].nil? or params[:sharing][:class_id].blank?
-
+
sharing_class = params[:sharing][:class_id]
updating_class = (params[:updating] and !params[:updating][:class_id].blank?) ? params[:updating][:class_id] : "6"
-
+
# Check allowed sharing_class values
return unless [ "0", "1", "2", "3", "4", "7" ].include? sharing_class
@@ -211,9 +220,9 @@
# BEGIN initialisation and validation
- unless contributable.contribution.policy
+ if contributable.contribution.policy.nil? || contributable.contribution.policy.group_policy?
last_saved_policy = Policy._default(current_user, nil) # second parameter ensures that this policy is not applied anywhere
-
+
policy = Policy.new(:name => 'auto',
:contributor_type => 'User', :contributor_id => current_user.id,
:share_mode => sharing_class,
@@ -256,10 +265,25 @@
policy.delete_all_user_permissions
end
-
+
# Process explicit Group permissions now
+ process_permissions(policy, params)
+
+ logger.debug("------ Workflow create summary ------------------------------------")
+ logger.debug("current_user = #{current_user.id}")
+ logger.debug("updating_class = #{updating_class}")
+ logger.debug("sharing_class = #{sharing_class}")
+ logger.debug("policy = #{policy}")
+ logger.debug("group_sharing = #{params[:group_sharing]}")
+ logger.debug("-------------------------------------------------------------------")
+
+ # returns some message in case of errors (or empty string in case of success)
+ return error_msg
+ end
+
+ def process_permissions(policy, params)
if params[:group_sharing]
-
+
# First delete any Permission objects that don't have a checked entry in the form
policy.permissions.each do |p|
params[:group_sharing].each do |n|
@@ -271,17 +295,17 @@
end
end
end
-
+
# Now create or update Permissions
params[:group_sharing].each do |n|
-
+
# Note: n[1] is used because n is an array and n[1] returns it's value (which in turn is a hash)
# In this hash, is a value with key 'id' is present then the checkbox for that group was checked.
if n[1][:id]
-
+
n_id = n[1][:id].to_i
level = n[1][:level]
-
+
unless (perm = Permission.find(:first, :conditions => ["policy_id = ? AND contributor_type = ? AND contributor_id = ?", policy.id, 'Network', n_id]))
# Only create new Permission if it doesn't already exist
p = Permission.new(:policy => policy, :contributor => (Network.find(n_id)))
@@ -290,31 +314,20 @@
# Update the 'level' on the existing permission
perm.set_level!(level) if level
end
-
+
else
-
+
n_id = n[0].to_i
-
+
# Delete permission if it exists (because this one is unchecked)
if (perm = Permission.find(:first, :conditions => ["policy_id = ? AND contributor_type = ? AND contributor_id = ?", policy.id, 'Network', n_id]))
perm.destroy
end
-
+
end
-
+
end
end
-
- logger.debug("------ Workflow create summary ------------------------------------")
- logger.debug("current_user = #{current_user.id}")
- logger.debug("updating_class = #{updating_class}")
- logger.debug("sharing_class = #{sharing_class}")
- logger.debug("policy = #{policy}")
- logger.debug("group_sharing = #{params[:group_sharing]}")
- logger.debug("-------------------------------------------------------------------")
-
- # returns some message in case of errors (or empty string in case of success)
- return error_msg
end
def update_credits(creditable, params)
@@ -1004,15 +1017,20 @@
#Applies the layout for the Network with the given network_id to the object (contributable)
def update_layout(object,network_id)
+ if object.is_a?(Policy)
+ policy = object
+ else
+ policy = object.contribution.policy
+ end
if network_id.blank? || network_id == "Default"
- object.contribution.layout = nil
- object.contribution.save
+ policy.layout = nil
+ policy.save
else
network = Network.find(network_id.to_i)
# Have to call .reload on permissions or the cached permissions from before "update_policy" was called are used
- if network && find_permission_for_contributor(object.contribution.policy.permissions.reload, "Network", network_id.to_i)
- object.contribution.layout = network.layout_name
- object.contribution.save
+ if network && find_permission_for_contributor(policy.permissions.reload, "Network", network_id.to_i)
+ policy.layout = network.layout_name
+ policy.save
else
object.errors.add_to_base("You may only choose layouts for groups that this #{object.class.name.downcase} is shared with.")
end
Modified: trunk/app/controllers/blobs_controller.rb (3299 => 3300)
--- trunk/app/controllers/blobs_controller.rb 2013-01-15 12:05:20 UTC (rev 3299)
+++ trunk/app/controllers/blobs_controller.rb 2013-01-15 12:24:11 UTC (rev 3300)
@@ -164,13 +164,12 @@
@blob.contribution.update_attributes(params[:contribution])
policy_err_msg = update_policy(@blob, params)
- update_layout(@blob, params[:layout])
-
+
update_credits(@blob, params)
update_attributions(@blob, params)
if policy_err_msg.blank?
-
+ update_layout(@blob, params[:layout]) unless params[:policy_type] == "group"
@version = @blob.find_version(1)
format.html {
@@ -229,9 +228,10 @@
policy_err_msg = update_policy(@blob, params)
update_credits(@blob, params)
update_attributions(@blob, params)
- update_layout(@blob, params[:layout])
-
+
if policy_err_msg.blank?
+ update_layout(@blob, params[:layout]) unless params[:policy_type] == "group"
+
format.html {
if @blob.new_version_number
Copied: trunk/app/controllers/group_policies_controller.rb (from rev 3290, trunk/app/controllers/group_announcements_controller.rb) (0 => 3300)
--- trunk/app/controllers/group_policies_controller.rb (rev 0)
+++ trunk/app/controllers/group_policies_controller.rb 2013-01-15 12:24:11 UTC (rev 3300)
@@ -0,0 +1,120 @@
+# myExperiment: app/controllers/group_policies_controller.rb
+#
+# Copyright (c) 2013 University of Manchester and the University of Southampton.
+# See license.txt for details.
+
+class GroupPoliciesController < ApplicationController
+
+ include ApplicationHelper
+
+ before_filter :login_required
+ before_filter :find_group
+ before_filter :find_policy, : [:show, :edit, :update, :destroy]
+ before_filter :check_admin
+
+ def index
+ @policies = Policy.find_all_by_contributor_type_and_contributor_id('Network', @group.id)
+
+ respond_to do |format|
+ format.html
+ end
+ end
+
+ def show
+ respond_to do |format|
+ format.html { render :action ="" "edit" }
+ end
+ end
+
+ def new
+ @policy = Policy.new
+ end
+
+ def edit
+
+ end
+
+ def create
+ @policy = Policy.new(:name => params[:name],
+ :contributor => @group,
+ :share_mode => params[:share_mode],
+ :update_mode => 6
+ )
+
+ respond_to do |format|
+ if @policy.save
+ process_permissions(@policy, params)
+ update_layout(@policy, params[:layout])
+ flash[:notice] = 'Policy was successfully created.'
+ format.html { redirect_to network_policies_path(@group) }
+ else
+ format.html { render :action ="" "new" }
+ end
+ end
+ end
+
+ def update
+ respond_to do |format|
+ if @policy.update_attributes(:name => params[:name], :share_mode => params[:share_mode])
+ process_permissions(@policy, params)
+ update_layout(@policy, params[:layout])
+ flash[:notice] = 'Policy was successfully updated'
+ format.html { redirect_to network_policies_path(@group) }
+ else
+ format.html { render :action ="" "edit" }
+ end
+ end
+ end
+
+ def destroy
+ if @policy.contributions.size == 0
+ @policy.destroy
+
+ respond_to do |format|
+ flash[:notice] = "Policy was successfully deleted"
+ format.html { redirect_to network_policies_path(@group) }
+ end
+ else
+ error("This policy is being used by address@hidden resources and may not be deleted.")
+ end
+ end
+
+
+ protected
+
+ def find_group
+ begin
+ @group = Network.find(params[:network_id])
+ rescue ActiveRecord::RecordNotFound
+ error("Group couldn't be found")
+ end
+ end
+
+ def find_policy
+ begin
+ @policy = Policy.find(params[:id])
+ rescue ActiveRecord::RecordNotFound
+ error("Policy couldn't be found")
+ end
+ end
+
+
+ def check_admin
+ unless @group.administrator?(current_user.id)
+ error("Only group administrators are allowed to manage policies")
+ end
+ end
+
+ private
+
+ def error(message)
+ flash[:error] = message
+ return_to_path = @group.nil? ? networks_path : network_policies_path(@group)
+
+ respond_to do |format|
+ format.html { redirect_to return_to_path }
+ end
+ end
+
+
+end
Modified: trunk/app/controllers/packs_controller.rb (3299 => 3300)
--- trunk/app/controllers/packs_controller.rb 2013-01-15 12:05:20 UTC (rev 3299)
+++ trunk/app/controllers/packs_controller.rb 2013-01-15 12:24:11 UTC (rev 3300)
@@ -131,9 +131,8 @@
# update policy
policy_err_msg = update_policy(@pack, params)
- update_layout(@pack, params[:layout])
-
if policy_err_msg.blank?
+ update_layout(@pack, params[:layout]) unless params[:policy_type] == "group"
flash[:notice] = 'Pack was successfully created.'
format.html { redirect_to pack_url(@pack) }
else
@@ -160,9 +159,8 @@
if @pack.update_attributes(params[:pack])
@pack.refresh_tags(convert_tags_to_gem_format(params[:pack][:tag_list]), current_user) if params[:pack][:tag_list]
policy_err_msg = update_policy(@pack, params)
- update_layout(@pack, params[:layout])
-
if policy_err_msg.blank?
+ update_layout(@pack, params[:layout]) unless params[:policy_type] == "group"
flash[:notice] = 'Pack was successfully updated.'
format.html { redirect_to pack_url(@pack) }
else
Modified: trunk/app/controllers/workflows_controller.rb (3299 => 3300)
--- trunk/app/controllers/workflows_controller.rb 2013-01-15 12:05:20 UTC (rev 3299)
+++ trunk/app/controllers/workflows_controller.rb 2013-01-15 12:24:11 UTC (rev 3300)
@@ -352,12 +352,11 @@
update_credits(@workflow, params)
update_attributions(@workflow, params)
- update_layout(@workflow, params[:layout])
-
# Refresh the types handler list of types if a new type was supplied this time.
WorkflowTypesHandler.refresh_all_known_types! if params[:workflow][:type] == 'other'
if policy_err_msg.blank?
+ update_layout(@workflow, params[:layout]) unless params[:policy_type] == "group"
flash[:notice] = 'Workflow was successfully created.'
format.html {
if (@workflow.get_tag_suggestions.length > 0 || (@workflow.body.nil? || @workflow.body == ''))
@@ -530,9 +529,8 @@
update_credits(@workflow, params)
update_attributions(@workflow, params)
- update_layout(@workflow, params[:layout])
-
if policy_err_msg.blank?
+ update_layout(@workflow, params[:layout]) unless params[:policy_type] == "group"
flash[:notice] = 'Workflow was successfully updated.'
format.html { redirect_to workflow_url(@workflow) }
else
Modified: trunk/app/helpers/application_helper.rb (3299 => 3300)
--- trunk/app/helpers/application_helper.rb 2013-01-15 12:05:20 UTC (rev 3299)
+++ trunk/app/helpers/application_helper.rb 2013-01-15 12:24:11 UTC (rev 3300)
@@ -769,7 +769,7 @@
when "transfer_ownership"
return "famfamfam_silk/key_go.png"
when "content"
- return "famfamfam_silk/application_side_list.png"
+ return "famfamfam_silk/application_side_list.png"
else
return Conf.label_icons[method.to_s] if Conf.label_icons[method.to_s]
end
@@ -1590,11 +1590,11 @@
if params["layout_preview"]
layout = Conf.layouts[params["layout_preview"]]
- elsif contributable && contributable.contribution
- layout = Conf.layouts[contributable.contribution.layout]
+ elsif contributable && contributable.contribution && contributable.contribution.policy
+ layout = Conf.layouts[contributable.contribution.policy.layout]
if layout.nil?
logger.error("Missing layout for #{contributable.class.name} #{contributable.id}: "+
- "#{contributable.contribution.layout}")
+ "#{contributable.contribution.policy.layout}")
end
elsif @network
layout = @network.layout
Modified: trunk/app/models/network.rb (3299 => 3300)
--- trunk/app/models/network.rb 2013-01-15 12:05:20 UTC (rev 3299)
+++ trunk/app/models/network.rb 2013-01-15 12:24:11 UTC (rev 3300)
@@ -19,6 +19,7 @@
has_many :blobs, :as => :contributor
has_many :blogs, :as => :contributor
has_many :workflows, :as => :contributor
+ has_many :policies, :as => :contributor
acts_as_solr(:fields => [ :title, :unique_name, :owner_name, :description, :tag_list ],
:include => [ :comments ]) if Conf.solr_enable
Modified: trunk/app/models/policy.rb (3299 => 3300)
--- trunk/app/models/policy.rb 2013-01-15 12:05:20 UTC (rev 3299)
+++ trunk/app/models/policy.rb 2013-01-15 12:24:11 UTC (rev 3300)
@@ -61,4 +61,8 @@
end
end
end
+
+ def group_policy?
+ contributor_type == "Network"
+ end
end
Modified: trunk/app/views/contributions/_sharing_form.rhtml (3299 => 3300)
--- trunk/app/views/contributions/_sharing_form.rhtml 2013-01-15 12:05:20 UTC (rev 3299)
+++ trunk/app/views/contributions/_sharing_form.rhtml 2013-01-15 12:24:11 UTC (rev 3300)
@@ -6,6 +6,10 @@
<% perms = [] %>
<% perms = contributable.contribution.policy.permissions if edit %>
+<% applicable_networks = (current_user.networks + current_user.networks_owned) %>
+<% group_policies = applicable_networks.map {|n| n.policies}.flatten %>
+<% using_group_policy = edit && contributable.contribution.policy.group_policy? %>
+<% group_policies = group_policies | [contributable.contribution.policy] if using_group_policy %>
<div class="fold">
@@ -22,29 +26,76 @@
</div>
<div class="foldContent" style="display: none;">
-
<div class="box_infotext">
- <p>
- Here you can specify who can <b>view</b> and <b>download</b> this <%= c_type %> on <%= Conf.sitename %>.
- </p>
-
- <% if update_perms -%>
- <p>
- You can also set <b>update</b> permissions for this <%= c_type %>.
- <%= link_to_function "Click here" + expand_image, visual_effect(:toggle_blind, "update_perms_info", :duration => 0.3) %> for more information.
- </p>
- <div id="update_perms_info" class="box_simple" style="display: none; margin: 0.5em 0;">
- <%= update_perms_info_text(contributable) -%>
- </div>
- <% end -%>
-
- <p>
- You can also explicitly share this <%= c_type %> with your Groups.
- </p>
- </div>
+ <p>
+ Here you can specify who can <b>view</b> and <b>download</b> this <%= c_type %> on <%= Conf.sitename %>.
+ </p>
+ <% if update_perms -%>
+ <p>
+ You can also set <b>update</b> permissions for this <%= c_type %>.
+ <%= link_to_function "Click here" + expand_image, visual_effect(:toggle_blind, "update_perms_info", :duration => 0.3) %> for more information.
+ </p>
+ <div id="update_perms_info" class="box_simple" style="display: none; margin: 0.5em 0;">
+ <%= update_perms_info_text(contributable) -%>
+ </div>
+ <% end -%>
+
+ <p>
+ You can also explicitly share this <%= c_type %> with your Groups.
+ </p>
+ </div>
+
+ <% if group_policies.size > 0 %>
+ <br/>
+ <div class="box_infotext">
+ <p>
+ One or more of your groups has a <strong>Group Policy</strong> defined.
+ A Group Policy is a pre-defined set of sharing rules that can be applied to this <%= c_type -%> instead of manually managing permissions.
+ </p>
+ <p>
+ Select whether you wish you use a Group Policy or manually manage permissions below.
+ </p>
+ </div>
+ <p><strong>How do you wish to manage the sharing rules for this <%= c_type -%>?</strong></p>
+ <div class="box_editing" style="padding-left: 1em; font-size: 93%;">
+ <p>
+ <input type="radio" name="policy_type" value="custom" id="policy_option_custom"
+ <%= 'checked="checked"' if !using_group_policy -%>
+ <label for="" permissions manually</label>
+ </p>
+
+ <p>
+ <input type="radio" name="policy_type" value="group" id="policy_option_group"
+ <%= 'checked="checked"' if using_group_policy -%>
+ <label for="" a Group Policy</label>
+ </p>
+ </div>
+ <% else %>
+ <input type="hidden" name="policy_type" value="custom"/>
+ <% end %>
+
<br/>
-
+
+ <div id="group_policy" <%= 'style="display: none"' if !using_group_policy-%>>
+ <p><strong>Which Group Policy do you wish to apply to this <%= c_type -%>?</strong></p>
+ <div class="box_editing" style="padding-left: 1em; font-size: 93%;">
+ <select name="group_policy">
+ <% group_policies.group_by {|p| p.contributor.title}.each do |network, policies| %>
+ <% unless policies.empty? %>
+ <optgroup label="<%= h network -%>">
+ <% policies.each do |policy| %>
+ <option value="<%= policy.id -%>"><%= policy.name -%></option>
+ <% end %>
+ </optgroup>
+ <% end %>
+ <% end %>
+ </select>
+ </div>
+ </div>
+
+ <div id="custom_policy" <%= 'style="display: none"' if using_group_policy-%>>
+
<!-- View/Download Permissions -->
<p><strong>Who can view and download this <%= c_type %> on <%= Conf.sitename %>?</strong></p>
@@ -141,7 +192,7 @@
<br/>
- <% unless (applicable_networks = (current_user.networks + current_user.networks_owned)).empty? %>
+ <% unless applicable_networks.empty? %>
<!-- Explicit Group Permissions -->
<p><strong>Share with my Groups:</strong></p>
@@ -174,9 +225,9 @@
visiting the 'edit' page.
</p>
</div>
- <% selected_option = (Conf.layouts[contributable.contribution.layout]["network_id"] unless
- (contributable.contribution.nil? || contributable.contribution.layout.nil? ||
- Conf.layouts[contributable.contribution.layout].nil?)) %>
+ <% selected_option = (Conf.layouts[contributable.contribution.policy.layout]["network_id"] unless
+ (contributable.contribution.nil? || contributable.contribution.policy.nil? ||
+ contributable.contribution.policy.layout.nil? || Conf.layouts[contributable.contribution.policy.layout].nil?)) %>
<%= select_tag "layout", "<option value="">Default</option>" +
options_from_collection_for_select(applicable_networks.select {|n| n.layout_name if Conf.layouts[n.layout_name]},
'id','title', selected_option) %>
@@ -184,6 +235,8 @@
<% end %>
</div>
<% end %>
+
+ </div>
</div>
</div>
Added: trunk/app/views/group_policies/_breadcrumbs.html.erb (0 => 3300)
--- trunk/app/views/group_policies/_breadcrumbs.html.erb (rev 0)
+++ trunk/app/views/group_policies/_breadcrumbs.html.erb 2013-01-15 12:24:11 UTC (rev 3300)
@@ -0,0 +1,13 @@
+<li><%= link_to 'Groups', networks_path -%></li>
+<li><b><%= link_to h(@group.title), network_path(@group) -%></b></li>
+<li><b><%= link_to "Group Policies", network_policies_path(@group) -%></b>
+
+<% if ["show", "new", "edit"].include? controller.action_name.to_s -%>
+ <% case controller.action_name.to_s; when "show", "edit" -%>
+ <li><%= truncate(h(@policy.name), :length => 50) -%></li>
+ <% when "new" -%>
+ <li>New Policy</li>
+ <% else -%>
+ <!-- no specific breadcrumb for other actions -->
+ <% end -%>
+<% end -%>
Added: trunk/app/views/group_policies/_form.html.erb (0 => 3300)
--- trunk/app/views/group_policies/_form.html.erb (rev 0)
+++ trunk/app/views/group_policies/_form.html.erb 2013-01-15 12:24:11 UTC (rev 3300)
@@ -0,0 +1,95 @@
+<%= error_messages_for 'policy' %>
+
+<h3>Policy Name</h3>
+<%= text_field_tag :name, @policy.name-%>
+
+<h3>Group Permissions</h3>
+<% unless (applicable_networks = (current_user.networks + current_user.networks_owned)).empty? %>
+ <p>Resources using this policy will be shared with the selected groups, with the specified permissions:</p>
+
+ <div id="group_sharing_box" class="box_editing" style="padding-left: 1em; font-size: 93%;">
+ <% applicable_networks.each do |n| %>
+ <p>
+ <% perm = find_permission_for_contributor(@policy.permissions, "Network", n.id) if edit -%>
+ <label for="" n.id %>">
+ <input class="group_sharing" <%= 'checked="checked"' if perm || n.id == @group.id %>
+ <%= 'readonly="readonly"' if n.id == @group.id %> style="margin-right: 0.3em;"
+ value="<%= n.id %>" type="checkbox" name="group_sharing[<%= n.id %>][id]" id="cb_group_sharing_<%= n.id %>"
+ this.checked);"/>
+ <%= h(n.title) %> Members
+ </label>
+ <select name="group_sharing[<%= n.id %>][level]" style="font-size: 85%; margin: 0 0.5em;">
+ <option value="0" <%= 'selected="selected"' if perm and perm.level == 0 %>>View</option>
+ <option value="1" <%= 'selected="selected"' if !edit or !perm or (perm and perm.level == 1) %>>View and Download</option>
+ <option value="2" <%= 'selected="selected"' if perm and perm.level == 2 %>>View, Download and Update</option>
+ </select>
+ </p>
+ <% end %>
+ </div>
+<% end %>
+
+<h3>Public Permissions</h3>
+<p>Resources using this policy will have the following visibility for users not in the above groups:</p>
+
+<div class="box_editing" style="padding-left: 1em; font-size: 93%;">
+ <p><label for=""
+ <input <%= 'checked="checked"' if @policy.share_mode == 0 %> id="sharing_option_1" name="share_mode"
+ value="0" type="radio"/>
+ - Anyone can view and download.
+ </label></p>
+
+ <p><label for=""
+ <input <%= 'checked="checked"' if @policy.share_mode == 2 %> id="sharing_option_9" name="share_mode"
+ value="2" type="radio"/>
+ - Anyone can view, but not download.
+ </label></p>
+
+ <p><label for=""
+ <input <%= 'checked="checked"' if @policy.share_mode == 7 %> id="sharing_option_7" name="share_mode"
+ value="7" type="radio"/>
+ - Private - only the uploader and specified groups can view and download.
+ </label></p>
+</div>
+
+<h3>Styling</h3>
+<p>Resources using this policy will inherit the styling from the following group:</p>
+<% selected_option = (Conf.layouts[policy.layout]["network_id"] unless (policy.layout.nil? || Conf.layouts[policy.layout].nil?)) %>
+<%= select_tag "layout", "<option value="">Default</option>" +
+ options_from_collection_for_select(applicable_networks.select {|n| n.layout_name if Conf.layouts[n.layout_name]},
+ 'id','title', selected_option) %>
+
+
+
+<script type="text/_javascript_">
+
+ function toggle_layout_option(id, enable) {
+ var option = $$('select#layout option[value=' + id + ']').first();
+
+ if(option != null) {
+ //If a "share with group" box is unticked, and that group's layout is selected, go to default.
+ if(!enable){
+ if($('layout').selectedIndex == option.index){
+ $('layout').selectedIndex = 0;
+ }
+ }
+
+ //Disable/enable option in dropdown menu
+ option.disabled = !enable;
+
+ //If all options except "default" are disabled, hide the layout option box
+ if($$('select#layout option[disabled]').size() == ($$('select#layout option').size() - 1)) {
+ $('layout_options_box').hide();
+ }
+ else {
+ $('layout_options_box').show();
+ }
+ }
+ }
+
+ //Initial state
+ document.observe("dom:loaded", function() {
+ $$('input.group_sharing').each (function (box) {
+ toggle_layout_option(box.value, box.checked);
+ });
+ });
+</script>
\ No newline at end of file
Added: trunk/app/views/group_policies/edit.html.erb (0 => 3300)
--- trunk/app/views/group_policies/edit.html.erb (rev 0)
+++ trunk/app/views/group_policies/edit.html.erb 2013-01-15 12:24:11 UTC (rev 3300)
@@ -0,0 +1,18 @@
+<h1>Policy: <%= @policy.name -%></h1>
+<ul class="sectionIcons">
+ <% if @policy.contributions.size == 0 -%>
+ <li>
+ <%= icon('destroy', network_policy_path(@group, @policy), nil, { :confirm => 'Are you sure you wish to delete this policy?', :method => :delete }, 'Delete Policy') %>
+ </li>
+ <% end -%>
+</ul>
+<h3>Usage</h3>
+<%= @policy.contributions.size -%> resources using this policy
+<br/>
+<% form_tag network_policy_path(@group, @policy), :method => :put do -%>
+ <%= render :partial => 'form', :locals => { :policy => @policy, :edit => true } %>
+ <br/>
+ <p>
+ <%= submit_tag "Save" -%>
+ </p>
+<% end -%>
\ No newline at end of file
Added: trunk/app/views/group_policies/index.html.erb (0 => 3300)
--- trunk/app/views/group_policies/index.html.erb (rev 0)
+++ trunk/app/views/group_policies/index.html.erb 2013-01-15 12:24:11 UTC (rev 3300)
@@ -0,0 +1,20 @@
+<h1>Group Policies</h1>
+<ul class="sectionIcons">
+ <li><%= icon('new', new_network_policy_path, nil, nil, 'Create New Policy') %></li>
+</ul>
+<div class="box_infotext">
+ <p></p><strong>Group Policies</strong> are pre-made sets of rules governing who can view, download and modify resources that they are associated with.
+ When uploading a new workflow, file or creating a new pack, <strong>group members</strong> can choose to apply a Group Policy
+ rather than managing permissions manually.</p>
+
+ <p>Group Policies may be created and modified by <strong>group administrators</strong>. If a Group Policy is being used by one or more resources,
+ it may not be deleted. If a Group Policy is modified, the changes will affect all resources using it.</p>
+</div>
+<ul>
+ <% @policies.each do |policy| %>
+ <li>
+ <%= link_to policy.name, edit_network_policy_path(@group, policy) %>
+ - Used by <%= policy.contributions.size -%> resources
+ </li>
+ <% end %>
+</ul>
\ No newline at end of file
Added: trunk/app/views/group_policies/new.html.erb (0 => 3300)
--- trunk/app/views/group_policies/new.html.erb (rev 0)
+++ trunk/app/views/group_policies/new.html.erb 2013-01-15 12:24:11 UTC (rev 3300)
@@ -0,0 +1,8 @@
+<h1>New Group Policy</h1>
+<% form_tag network_policies_path(@group), :method => :post do %>
+ <%= render :partial => 'form', :locals => { :policy => @policy, :edit => false } %>
+ <br/>
+ <p>
+ <%= submit_tag "Create" -%>
+ </p>
+<% end %>
\ No newline at end of file
Modified: trunk/app/views/networks/show.rhtml (3299 => 3300)
--- trunk/app/views/networks/show.rhtml 2013-01-15 12:05:20 UTC (rev 3299)
+++ trunk/app/views/networks/show.rhtml 2013-01-15 12:24:11 UTC (rev 3300)
@@ -26,6 +26,7 @@
<% if @network.administrator?(current_user.id) %>
<li><%= icon('announcement', new_group_announcement_path(@network), 'Make a new Group Announcement', nil, 'Make a Group Announcement') -%></li>
<li><%= icon('network-invite', invite_network_path(@network), 'Invite People', nil, 'Invite People') -%></li>
+ <li><%= icon('policy', network_policies_path(@network), 'Group Policies', nil, 'Group Policies') -%></li>
<% end %>
<% if mine? @network %>
<li><%= icon('edit', edit_network_path(@network), 'Edit', nil, 'Edit Group') %></li>
Modified: trunk/config/routes.rb (3299 => 3300)
--- trunk/config/routes.rb 2013-01-15 12:05:20 UTC (rev 3299)
+++ trunk/config/routes.rb 2013-01-15 12:24:11 UTC (rev 3300)
@@ -264,6 +264,7 @@
:tag => :post } do |network|
network.resources :group_announcements, :as => :announcements, :name_prefix => nil
network.resources :comments, :collection => { :timeline => :get }
+ network.resources :policies, :controller => 'group_policies'
end
# The priority is based upon order of creation: first created -> highest priority.
Added: trunk/db/migrate/20130114091326_move_layout_to_policy.rb (0 => 3300)
--- trunk/db/migrate/20130114091326_move_layout_to_policy.rb (rev 0)
+++ trunk/db/migrate/20130114091326_move_layout_to_policy.rb 2013-01-15 12:24:11 UTC (rev 3300)
@@ -0,0 +1,20 @@
+class MoveLayoutToPolicy < ActiveRecord::Migration
+ def self.up
+ # Add column to policies
+ add_column :policies, :layout, :string
+ # Copy values
+ ActiveRecord::Base.record_timestamps = false
+ execute 'UPDATE policies,contributions SET policies.layout = contributions.layout WHERE policies.id = contributions.policy_id'
+ ActiveRecord::Base.record_timestamps = true
+ # Remove column from contributions
+ remove_column :contributions, :layout
+ end
+
+ def self.down
+ add_column :contributions, :layout, :string
+ ActiveRecord::Base.record_timestamps = false
+ execute 'UPDATE policies,contributions SET contributions.layout = policies.layout WHERE policies.id = contributions.policy_id'
+ ActiveRecord::Base.record_timestamps = true
+ remove_column :policies, :layout
+ end
+end
Modified: trunk/db/schema.rb (3299 => 3300)
--- trunk/db/schema.rb 2013-01-15 12:05:20 UTC (rev 3299)
+++ trunk/db/schema.rb 2013-01-15 12:24:11 UTC (rev 3300)
@@ -9,7 +9,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20121126095828) do
+ActiveRecord::Schema.define(:version => 20130114091326) do
create_table "activity_limits", :force => true do |t|
t.string "contributor_type", :null => false
@@ -40,6 +40,11 @@
t.datetime "updated_at"
end
+ create_table "auto_tables", :force => true do |t|
+ t.string "name"
+ t.text "schema"
+ end
+
create_table "blob_versions", :force => true do |t|
t.integer "blob_id"
t.integer "version"
@@ -138,6 +143,13 @@
add_index "comments", ["user_id"], :name => "index_comments_on_user_id"
+ create_table "component_profiles", :force => true do |t|
+ t.string "name"
+ t.string "url"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ end
+
create_table "concept_relations", :force => true do |t|
t.integer "subject_concept_id"
t.string "relation_type"
@@ -190,7 +202,6 @@
t.integer "site_downloads_count", :default => 0
t.integer "site_viewings_count", :default => 0
t.string "label"
- t.string "layout"
end
add_index "contributions", ["contributable_id", "contributable_type"], :name => "index_contributions_on_contributable_id_and_contributable_type"
@@ -490,6 +501,11 @@
t.integer "user_id"
end
+ create_table "plugin_schema_info", :id => false, :force => true do |t|
+ t.string "plugin_name"
+ t.integer "version"
+ end
+
create_table "policies", :force => true do |t|
t.integer "contributor_id"
t.string "contributor_type"
@@ -500,6 +516,7 @@
t.integer "update_mode"
t.boolean "public_download", :default => false
t.boolean "public_view", :default => false
+ t.string "layout"
end
create_table "predicates", :force => true do |t|
@@ -825,8 +842,6 @@
t.text "body_html"
t.datetime "created_at"
t.datetime "updated_at"
- t.string "license"
- t.integer "preview_id"
t.string "image"
t.string "svg"
t.text "revision_comments"
@@ -834,10 +849,10 @@
t.string "file_ext"
t.string "last_edited_by"
t.integer "content_type_id"
+ t.string "license"
+ t.integer "preview_id"
end
- add_index "workflow_versions", ["workflow_id"], :name => "index_workflow_versions_on_workflow_id"
-
create_table "workflows", :force => true do |t|
t.integer "contributor_id"
t.string "contributor_type"
@@ -847,15 +862,15 @@
t.string "unique_name"
t.text "body"
t.text "body_html"
- t.integer "current_version"
- t.integer "preview_id"
t.datetime "created_at"
t.datetime "updated_at"
+ t.integer "current_version"
t.integer "content_blob_id"
t.string "file_ext"
t.string "last_edited_by"
t.integer "content_type_id"
t.integer "license_id"
+ t.integer "preview_id"
end
create_table "wsdl_deprecations", :force => true do |t|
Modified: trunk/lib/rest.rb (3299 => 3300)
--- trunk/lib/rest.rb 2013-01-15 12:05:20 UTC (rev 3299)
+++ trunk/lib/rest.rb 2013-01-15 12:24:11 UTC (rev 3300)
@@ -997,8 +997,7 @@
:download => privileges["download"],
:edit => privileges["edit"])
unless (use_layout = permission.find_first('use-layout/text()')).nil?
- ob.contribution.layout = network.layout_name if use_layout.to_s == 'true'
- ob.contribution.save
+ ob.contribution.policy.layout = network.layout_name if use_layout.to_s == 'true'
end
end
end
Modified: trunk/public/stylesheets/styles.css (3299 => 3300)
--- trunk/public/stylesheets/styles.css 2013-01-15 12:05:20 UTC (rev 3299)
+++ trunk/public/stylesheets/styles.css 2013-01-15 12:24:11 UTC (rev 3300)
@@ -1010,7 +1010,7 @@
width: 100%;
padding: 0.5em 0.5em;
*padding: 0.2em 0.5em;
- line-height: 1.0;
+ line-height: 2.5;
text-decoration: none;
border: 1px solid #BBBBBB;
background-color: #EEF6FF;
@@ -2388,3 +2388,7 @@
border-radius: 3px;
margin-bottom: 1em;
}
+
+input[type="radio"], input[type="checkbox"] {
+ vertical-align: top;
+}
\ No newline at end of file
Modified: trunk/test/fixtures/blob_versions.yml (3299 => 3300)
--- trunk/test/fixtures/blob_versions.yml 2013-01-15 12:05:20 UTC (rev 3299)
+++ trunk/test/fixtures/blob_versions.yml 2013-01-15 12:24:11 UTC (rev 3300)
@@ -72,3 +72,27 @@
content_type_id: 1
content_blob_id: 1
+group_file_one_v1:
+ id: 7
+ blob_id: 7
+ version: 1
+ revision_comments: some revision comment
+ local_name: file_picture.png
+ title: for protected policy
+ body: some text
+ created_at: 2008-04-22 15:32:01
+ content_type_id: 1
+ content_blob_id: 1
+
+group_file_two_v1:
+ id: 8
+ blob_id: 8
+ version: 1
+ revision_comments: some revision comment
+ local_name: file_picture.png
+ title: for protected policy
+ body: some text
+ created_at: 2008-04-22 15:32:01
+ content_type_id: 1
+ content_blob_id: 1
+
Modified: trunk/test/fixtures/blobs.yml (3299 => 3300)
--- trunk/test/fixtures/blobs.yml 2013-01-15 12:05:20 UTC (rev 3299)
+++ trunk/test/fixtures/blobs.yml 2013-01-15 12:24:11 UTC (rev 3300)
@@ -78,3 +78,29 @@
content_type_id: 1
content_blob_id: 1
+group_file_one:
+ id: 7
+ current_version: 1
+ contributor_id: 1
+ contributor_type: User
+ local_name: file_picture.png
+ title: A file with a Group Policy
+ body: some text
+ created_at: 2008-04-22 15:32:01
+ license_id: 2
+ content_type_id: 1
+ content_blob_id: 1
+
+group_file_two:
+ id: 8
+ current_version: 1
+ contributor_id: 1
+ contributor_type: User
+ local_name: file_picture.png
+ title: Another file with a Group Policy
+ body: some text
+ created_at: 2008-04-22 15:32:01
+ license_id: 2
+ content_type_id: 1
+ content_blob_id: 1
+
Modified: trunk/test/fixtures/contributions.yml (3299 => 3300)
--- trunk/test/fixtures/contributions.yml 2013-01-15 12:05:20 UTC (rev 3299)
+++ trunk/test/fixtures/contributions.yml 2013-01-15 12:24:11 UTC (rev 3300)
@@ -111,11 +111,24 @@
id: 10
contributor_id: 1
contributor_type: User
- contributable_id: 6
+ contributable_id: 7
contributable_type: Blob
- policy_id: 6
+ policy_id: 7
created_at: 2007-08-07 23:53:46
updated_at: 2007-08-07 23:53:46
downloads_count: 1
viewings_count: 1
+contribution_for_group_file_one:
+ id: 11
+ contributor_id: 1
+ contributor_type: User
+ contributable_id: 8
+ contributable_type: Blob
+ policy_id: 7
+ created_at: 2007-08-07 23:53:46
+ updated_at: 2007-08-07 23:53:46
+ downloads_count: 1
+ viewings_count: 1
+
+
Modified: trunk/test/fixtures/permissions.yml (3299 => 3300)
--- trunk/test/fixtures/permissions.yml 2013-01-15 12:05:20 UTC (rev 3299)
+++ trunk/test/fixtures/permissions.yml 2013-01-15 12:24:11 UTC (rev 3300)
@@ -43,3 +43,13 @@
created_at: 2008-04-06 14:13:12
updated_at: 2008-04-06 14:13:12
+permission_for_group_policy:
+ id: 5
+ contributor_id: 4
+ contributor_type: Network
+ policy_id: 7
+ download: true
+ edit: true
+ view: true
+ created_at: 2008-04-06 14:13:12
+ updated_at: 2008-04-06 14:13:12
\ No newline at end of file
Modified: trunk/test/fixtures/policies.yml (3299 => 3300)
--- trunk/test/fixtures/policies.yml 2013-01-15 12:05:20 UTC (rev 3299)
+++ trunk/test/fixtures/policies.yml 2013-01-15 12:24:11 UTC (rev 3300)
@@ -59,3 +59,22 @@
created_at: 2007-10-22 18:54:22
updated_at: 2008-01-09 12:12:12
+group_policy:
+ id: 7
+ contributor_id: 4
+ contributor_type: Network
+ name: Group Policy
+ share_mode: 0
+ update_mode: 0
+ created_at: 2007-10-22 18:54:22
+ updated_at: 2008-01-09 12:12:12
+
+unused_group_policy:
+ id: 8
+ contributor_id: 4
+ contributor_type: Network
+ name: Unused Group Policy
+ share_mode: 0
+ update_mode: 0
+ created_at: 2007-10-22 18:54:22
+ updated_at: 2008-01-09 12:12:12
\ No newline at end of file
Modified: trunk/test/functional/blobs_controller_test.rb (3299 => 3300)
--- trunk/test/functional/blobs_controller_test.rb 2013-01-15 12:05:20 UTC (rev 3299)
+++ trunk/test/functional/blobs_controller_test.rb 2013-01-15 12:24:11 UTC (rev 3300)
@@ -68,4 +68,46 @@
assert_equal old_count-1, Blob.count
assert_redirected_to blobs_path
end
+
+ def test_should_apply_group_policy
+ login_as(:john)
+ old_policy_id = policies(:john_policy).id
+ assert_difference("Policy.count", -1) do
+ put :update, :id => 1, :blob => { :title => 'Test blob - updated', :body => 'updated test test test' },
+ :credits_me => 'false',
+ :credits_users => '',
+ :credits_groups => '',
+ :attributions_workflows => '',
+ :attributions_files => '',
+ :policy_type => "group",
+ :group_policy => "7"
+
+ assert_redirected_to blob_path(assigns(:blob))
+ assert_equal 7, assigns(:blob).contribution.policy_id
+ assert_nil Policy.find_by_id(old_policy_id) # Old, custom policy should be deleted
+ end
+ end
+
+ def test_should_apply_custom_policy
+ login_as(:john)
+
+ blob = blobs(:group_file_one)
+
+ assert_difference("Policy.count", 1) do
+ put :update, :id => blob.id, :blob => { :title => 'Updated', :body => 'updated test test test' },
+ :credits_me => 'false',
+ :credits_users => '',
+ :credits_groups => '',
+ :attributions_workflows => '',
+ :attributions_files => '',
+ :policy_type => "custom",
+ :sharing => {:class_id => "1"},
+ :updating => {:class_id => "1"}
+ assert_not_equal 7, assigns(:blob).contribution.policy_id
+ assert_equal 7, blobs(:group_file_two).contribution.policy_id
+ assert_equal 0, blobs(:group_file_two).contribution.policy.share_mode
+ assert_equal 1, assigns(:blob).contribution.policy.share_mode
+ end
+
+ end
end
Added: trunk/test/functional/group_policies_controller_test.rb (0 => 3300)
--- trunk/test/functional/group_policies_controller_test.rb (rev 0)
+++ trunk/test/functional/group_policies_controller_test.rb 2013-01-15 12:24:11 UTC (rev 3300)
@@ -0,0 +1,59 @@
+require File.dirname(__FILE__) + '/../test_helper'
+require 'group_policies_controller'
+
+class GroupPoliciesControllerTest < ActionController::TestCase
+ fixtures :policies, :blobs, :permissions, :networks, :users
+
+ def test_administrators_can_view
+ login_as(:john)
+ get :index, :network_id => networks(:exclusive_network).id
+ assert_response :success
+ end
+
+ def test_non_admins_cannot_view
+ login_as(:jane)
+ get :index, :network_id => networks(:exclusive_network).id
+ assert_response :redirect
+ end
+
+ def test_can_create
+ login_as(:john)
+
+ assert_difference("Policy.count", 1) do
+ post :create, :network_id => networks(:exclusive_network).id,
+ :name => "New Policy", :share_mode => 0
+ end
+ end
+
+ def test_can_delete_if_not_used
+ login_as(:john)
+
+ assert_difference("Policy.count", -1) do
+ delete :destroy, :network_id => networks(:exclusive_network).id, :id => policies(:unused_group_policy).id
+ assert_response :redirect
+ end
+ end
+
+ def test_cannot_delete_if_used
+ login_as(:john)
+
+ assert_no_difference("Policy.count") do
+ delete :destroy, :network_id => networks(:exclusive_network).id, :id => policies(:group_policy).id
+ assert_response :redirect
+ end
+ end
+
+ def test_can_update
+ login_as(:john)
+
+ assert_equal 0, policies(:group_policy).share_mode
+
+ put :update, :network_id => networks(:exclusive_network).id, :id => policies(:group_policy).id,
+ :share_mode => 2
+
+ assert_response :success
+
+ assert_equal 2, assigns(:policy).share_mode
+ end
+
+end
\ No newline at end of file