-
Notifications
You must be signed in to change notification settings - Fork 116
Allow admins to combine and delete CCLAs #521
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4480062
allow admins to combine and delete CCLAs
raskchanky 6fd354e
adding a search scope to CclaSignature
raskchanky 73893a9
refactor the combine! method
raskchanky 75230f9
Style organization management view
tristanoneil ea84d48
ensure no duplicate contributors
raskchanky 9697602
strip admin privileges of incoming contributors
raskchanky File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| $(function () { | ||
| var settings = { | ||
| placeholder: 'Search for an organization', | ||
| minimumInputLength: 3, | ||
| width: '100%', | ||
| ajax: { | ||
| url: function () { | ||
| return $(this).data('url'); | ||
| }, | ||
| dataType: 'json', | ||
| quietMillis: 200, | ||
| data: function (term, page) { | ||
| return { q: term }; | ||
| }, | ||
| results: function (data, page) { | ||
| return {results: data}; | ||
| } | ||
| }, | ||
| formatSelection: function(obj, container) { | ||
| return obj.company; | ||
| }, | ||
| formatResult: function(obj, container) { | ||
| return obj.company; | ||
| } | ||
| } | ||
|
|
||
| $('.transfer-ccla-organization').select2(settings); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,6 +32,10 @@ | |
| } | ||
| } | ||
| } | ||
|
|
||
| .select2-container { | ||
| margin-bottom: rem-calc(20); | ||
| } | ||
| } | ||
|
|
||
| .cla_signers_list { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| class OrganizationsController < ApplicationController | ||
| before_filter :authenticate_user!, except: [:index] | ||
| before_filter :find_organization, except: [:index] | ||
| skip_before_filter :verify_authenticity_token, only: [:index] | ||
|
|
||
| # | ||
| # GET /organizations | ||
| # | ||
| # Lists out all organizations. | ||
| # | ||
| def index | ||
| organizations = if params[:q] | ||
| CclaSignature.search(params[:q]) | ||
| else | ||
| Organization.includes(:ccla_signatures) | ||
| end | ||
|
|
||
| respond_to do |format| | ||
| format.json do | ||
| render json: organizations.to_json(only: [:id], methods: [:company]) | ||
| end | ||
| end | ||
| end | ||
|
|
||
| # | ||
| # GET /organizations/:id | ||
| # | ||
| # Shows the management page for an organization, allowing deletion and | ||
| # merging with other organizations. | ||
| # | ||
| def show | ||
| authorize! @organization | ||
| end | ||
|
|
||
| # | ||
| # DELETE /organizations/:id | ||
| # | ||
| # Deletes an organization | ||
| # | ||
| def destroy | ||
| authorize! @organization | ||
| @organization.destroy | ||
|
|
||
| redirect_to root_path | ||
| end | ||
|
|
||
| # | ||
| # PUT /organizations/:id/combine | ||
| # | ||
| # Combines two organizations together into one. | ||
| # | ||
| def combine | ||
| authorize! @organization | ||
| org_to_combine = Organization.find(params[:organization][:combine_with_id]) | ||
| @organization.combine!(org_to_combine) | ||
|
|
||
| redirect_to @organization | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def find_organization | ||
| @organization = Organization.find(params[:id]) | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| module CclaSignaturesHelper | ||
| # | ||
| # Generates the HTML for a tab in the organization partial, with conditional | ||
| # logic to make it active if it's the current page. | ||
| # | ||
| # @param txt [String] the text for the link | ||
| # @param path [String] the path for the link | ||
| # | ||
| # @return [String] HTML representing a tab | ||
| # | ||
| def organization_tab(txt, path) | ||
| cls = current_page?(path) ? 'active' : nil | ||
| content_tag :dd, class: cls do | ||
| link_to txt, path | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,15 @@ | ||
| <dl class="tabs"> | ||
| <% if policy(ccla_signature.organization).view_cclas? %> | ||
| <dd class="<%= "active" if current_page?(ccla_signature_path(ccla_signature)) %>"><%= link_to 'View Signature', ccla_signature %></dd> | ||
| <%= organization_tab('View Signature', ccla_signature_path(ccla_signature)) %> | ||
| <% end %> | ||
|
|
||
| <dd class="<%= "active" if current_page?(contributors_ccla_signature_path(ccla_signature)) %>"><%= link_to "View Contributors", contributors_ccla_signature_path(ccla_signature) %></dd> | ||
| <%= organization_tab('View Contributors', contributors_ccla_signature_path(ccla_signature)) %> | ||
|
|
||
| <% if policy(ccla_signature.organization).manage_contributors? %> | ||
| <dd class="<%= "active" if current_page?(organization_invitations_path(ccla_signature.organization)) %>"><%= link_to 'Manage Contributors', organization_invitations_path(ccla_signature.organization) %></dd> | ||
| <%= organization_tab('Manage Contributors', organization_invitations_path(ccla_signature.organization)) %> | ||
| <% end %> | ||
|
|
||
| <% if policy(ccla_signature.organization).manage_organization? %> | ||
| <%= organization_tab('Manage Organization', organization_path(ccla_signature.organization)) %> | ||
| <% end %> | ||
| </dl> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -84,6 +84,5 @@ | |
| </tbody> | ||
| </table> | ||
| </div> | ||
|
|
||
| </div> | ||
| </div> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| <%= provide(:title, "CCLA Invitations for #{@organization.name}") %> | ||
|
|
||
| <div class="page"> | ||
| <div class="cla"> | ||
| <h1><%= @organization.name %> Organization Management</h1> | ||
|
|
||
| <%= render "ccla_signatures/organization_tabs", ccla_signature: @organization.latest_ccla_signature %> | ||
|
|
||
| <p>As an admin you may combine an organization with another in the event that a duplicate organization was created in error. Note that all contributors will be transferred to the selected organization and this organization will be deleted. Alternatively you can simply delete this organization.</p> | ||
|
|
||
| <%= form_for @organization, url: { action: 'combine' }, method: :put do |f| %> | ||
| <div class="row collapse"> | ||
| <div class="small-10 columns"> | ||
| <%= f.hidden_field :combine_with_id, class: 'transfer-ccla-organization', 'data-url' => organizations_path %> | ||
| </div> | ||
| <div class="small-2 columns"> | ||
| <%= f.submit 'Combine', class: 'button postfix radius' %> | ||
| </div> | ||
| </div> | ||
| <% end %> | ||
|
|
||
| <%= link_to 'Delete this Organization', organization_path(@organization), method: :delete, data: { confirm: 'This will permanently delete this organization and all of its signatures. Are you sure?' }, class: 'button alert radius small' %> | ||
| </div> | ||
| </div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| class MakeContributorsUnique < ActiveRecord::Migration | ||
| def change | ||
| add_index :contributors, [:user_id, :organization_id], unique: true | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If an admin issues two identical requests to combine, the second will fail. As such, I think this should be apostinstead of aput.Ack! I fell into the idempotency trap! Disregard, please.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.