GithubHelp home page GithubHelp logo

Comments (6)

the-teacher avatar the-teacher commented on August 21, 2024

Hello! Give me a time to analyze your situation. I'll try to help

from the_role.

danevron avatar danevron commented on August 21, 2024

I didn't mean to to upset you.
I'm rather new to Github and I was under the impression that this is the way to ask questions.
Sorry

from the_role.

the-teacher avatar the-teacher commented on August 21, 2024

I think, in code your situation looks like that:

class User < AR
  has_many :expense_reports
end

class ExpenseReport < AR
  belongs_to :user
end

and I think you want to render list of expense_reports of user (for example with ID 567) with URL

/users/567/expense_reports

You should not to check ownership of user to each object (@owner_check_object can't to help you). Because you should only render a list of expense_reports of this current_user

This story out of scope of TheRole. TheRole should not to resolve situation when User 1 try to see Index action of User 2. That is why you cant to find solution in TheRole documentaion.

This situation should be resolved manually with your code. There is part of my current project

class ApplicationController < ActionController::Base
  before_action :define_user

  private

  def define_user
    @root   = User.root
    @user   = current_user

    user_id = params[:user_id]
    @user = User.find(user_id) if user_id
  end
class PagesController < ActionController::Base
  before_action :check_for_list_owner, only: [:manage]

  def manage; end

  private

  def check_for_list_owner
    unless (current_user == @user || current_user.admin?)
        redirect_to root_path, flash: { error: "Access denide" } 
    end
  end
end

Can it be solution for your story?

from the_role.

danevron avatar danevron commented on August 21, 2024

Yes.
This is what I was looking for.
I can protect all the user's nested objects with this solution.
Thanks man!

from the_role.

seuros avatar seuros commented on August 21, 2024

@danevron he is not upset just Russian. ;)

from the_role.

the-teacher avatar the-teacher commented on August 21, 2024

@seuros 😄

from the_role.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.