Skip to content
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

Scope resources under organization resource #250

Open
wants to merge 11 commits into
base: develop
Choose a base branch
from

Conversation

enricostano
Copy link
Contributor

@enricostano enricostano commented Jun 15, 2017

This is a first attempt at scoping all the resources related to an organization under the organization scope.

For instance /organization/27/offer/12.

More info in community thread: http://community.coopdevs.org/t/scope-todos-los-recursos-de-organization-bajo-organizations/25

This is still a work in progress, but @sseerrggii should be able to test it :trollface:

TODO:

  • offers
  • inquiries
  • users/members
  • statistics
  • reports
  • organizations
  • tags

<li class="<%= "active" if current_page?(inquiries_path) %>">
<%= link_to inquiries_path do %>
<li class="<%= "active" if current_page?(organization_inquiries_path(organization_id: @organization.id)) %>">
<%= link_to organization_inquiries_path(organization_id: @organization.id) do %>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be possible to directly use the shorter form organization_inquiries_path(@organization).

@sseerrggii
Copy link
Contributor

👍 Testeo un poco

@sauloperez
Copy link
Collaborator

is there any special reason why we need this scoping?

@@ -1,5 +1,11 @@
class HomeController < ApplicationController

# TODO: what happens when the user doesn't pertain to any organization?
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would redirect them to a page where we tell them to join some organization. Do we have something alike @sseerrggii ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ping @sseerrggii 😬

raise not_found unless @organization

@organization
end
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could achive the same behaviour without needing this code if we rescued ActiveRecord::RecordNotFound in a rescue_from block. Furthermore, this would work for any model.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, sure. We need to move somewhere else and DRY it a bit firts though.

class OffersController < PostsController
def model
Offer
end

def dashboard
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not used?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not anymore.

def load_organization
@organization = Organization.find_by_id(params[:organization_id])

raise not_found unless @organization
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

def resources
controller_name
end

def set_user_id(p)
if current_user.manages?(current_organization)
if current_user.manages?(@organization)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could avoid lots of these ivar changes by implemanting the getter method in the application controller as:

def current_organization
  @organization
end

This would reduce the number of changes considerably and increase the readability of this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep this is part of the abstracion part, moving the loading/authorizing of the organization somewhere else and DRY it.

@@ -34,11 +46,11 @@ def toggle_active
private

def find_member
@member ||= current_organization.members.find(params[:id])
@member ||= @organization.members.find(params[:id])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

find_by_id or rescue meee 🎤

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uff this repo is full of this kind of stuff :(

Yep, will do. but maybe once I finish to move the resources under the /organizations scope.

@enricostano
Copy link
Contributor Author

enricostano commented Jun 18, 2017

is there any special reason why we need this scoping?

@sauloperez basically we already do some kind of scoping storing the current organization in the browser session... let's use the URL instead.

EDIT: I added link to discussion in community in PR description.

@sseerrggii
Copy link
Contributor

Tener en cuenta que los links de ofertas/demandas en los mails también tienen que cambiar

Estaría bien que los links viejos, tipo https://www.timeoverflow.org/offers/19721 sigan funcionando, ya que al saber el id de post (oferta/demanda) podemos saber la organización

@enricostano enricostano force-pushed the feature/scope-resources-under-org branch from 23ea2f0 to 86cc250 Compare August 4, 2017 15:20
@enricostano enricostano force-pushed the feature/scope-resources-under-org branch from 912a2f1 to a56dab6 Compare August 16, 2017 10:15
@mllocs
Copy link
Collaborator

mllocs commented May 22, 2018

Is this still in progress? cc @enricostano @Morantron

@enricostano
Copy link
Contributor Author

Yes, I need to work on it ASAP. We're prioritizing push notifications.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants