Displaying 20 results from an estimated 300 matches similar to: "before_filter with multiple roles"
2007 Jul 24
6
Mocking Access Control
I''m trying to jump on the TDD/BDD bandwagon, but am having trouble
understanding how i should mock my user. The user has a habtm
relationship to a roles model (acl_system2 plugin), but I''m not sure
how to tell rspec about a model.
My code:
describe UsersController do
integrate_views
before(:each) do
@user = mock_model(User)
2009 Feb 25
3
Secure but elegant destruction method
Hi,-
I am looking for a clean and secure way for an ActiveRecord instance to
delete itself. Say I have a User model in my app. Then the destructive
action would be /users/user_id/destroy. If this action is not secured by
a filter like:
(*) before_filter :check_administrator_role, :only => :destroy
then any user could potentially log in and start issuing:
/users/1/destroy
/users/2/destroy
.
2006 Apr 09
6
Write/Display AR query as Grouped Results?
I''ve got a publications table that contains an author_id foreign key and
a pubrole_id foreign key. What I want to do is query the DB using AR so
that I can get a list of all publications that belong_to a particular
author, and group the results by the pubrole.role_name (Author, Joint
Author, Editor, etc.) so that the results look something like:
Author
book1 info
book2 info
etc.
2008 Jul 06
1
ActionView::Base.field_error_proc not getting an error field
In my User form I have standard field to get user record attributes
(first_name, last_name and email)
I also have a select drop_down to choose a role from an array
first_name, last_name and email are user record attributes, but I
defined the role name as a virtual attribute
validates_presence_of :email, :last_name
attr_accessor :role_name
validates_presence_of :role_name, :if
=>
2009 May 12
4
has_many :through and scopes: how to mutate the set of associated objects?
I have a model layer containing Movie, Person, Role, and RoleType,
making it possible to express facts such as "Clint Easterbunny is
director of the movie Gran Milano".
The relevant model and associations look like this
class Movie < ActiveRecord::Base
has_many :roles, :include => :role_type, :dependent => :destroy
has_many :participants, :through => :roles, :source
2006 Oct 09
5
Problem setting variables in ApplicationController.
I''m dynamically generating menu options based on the currently logged
in user: current_user.
My menus are setup on the applicatin.rhtml file. The current_user is
defined in the application controller. But, attempting to assign it a
value while in the application controller results in an ''undefined
method'' error.
ApplicationController ....
def current_user
@cu =
2006 Jul 11
1
Problems using the authorization plugin from Bill Katz
Hello everyone,
I was trying to set up access control in a new application Im working on,
I''m trying to use the excellent authorization plugin from Bill Katz,
Its pretty straight forward to setup and should be to use.
But when i try to give the same permission on two differents users on
the same object i get an error.
(Well , Im kinda new to all this rails stuff)
r = Red.find(1)
u1 =
2007 Aug 10
1
How to spec a model method
Still new to Specs...
How do I create a spec to test a model method? Specifically, here is my
spec:
#testing model
describe User do
it "should have many user roles" do
User.reflect_on_association(:user_roles).should_not be_nil
end
it "should have many roles though user roles" do
User.reflect_on_association(:roles).should_not be_nil
end
it "should know
2010 Jan 27
1
around_filter and with_scope
i got two controller (with restful actions) where my code is quite
ugly and not very dry. every action looks quite like this:
if @logged_user.has_role?("admin")
User.find(params[:id)
else
@logged_user.group.user.find(params[:id])
this is a security check that enforce a simple spec: normal user
should read/write information only about their group''s users, but
2009 Jun 05
6
rails 2.3.2
Hi all,
I am using rails v.2.3.2 and if I put following line to my
ApplicationController:
include LoginSystem
and I moved my login_system.rb to lib folder:
module LoginSystem
protected
def is_logged_in?
@logged_in_user = User.find(session[:user]) if session[:user]
end
def logged_in_user
return @logged_in_user if is_logged_in?
end
def logged_in_user=(user)
if
2009 Apr 29
7
problem with nil.user
Hi all, I''ve put new code into my app so that an administrator will have
extra privileges (administer users, edit pages). The error is:
''Couldn''t find User without an ID''
So the app is looking for a logged in user when the homepage is
accessed.
Heres my code:
site/index view:
<% if is_logged_in? and logged_in_user.has_role?(''Moderator'')
2009 Mar 14
9
null object pattern
I am trying to create a null object in my application. I would like to
assigned a null user object for anonymous/ mot-logged-in user, i.e. if
session variable has nil data.
In my User model, I have created a subclass like this:
class UnassignedUser < User
def save
false
end
def update
false
end
def username
"Unassigned"
end
def county_id
2006 Feb 09
1
R, Rcmdr crash on WinXP PRO laptop (PR#8583)
My system is a Dell laptop running Win XP Pro with SP2 and all current
updates. R is version 2.2.1, Rcmdr is version 1.1-6 (also happens with 1.1-5).
First attempt to import data from text file (in Rcmdr) works correctly with
no errors or warnings. Second, third or fourth attempt to load same data or
a similar dataset will cause all R windows, including Rcmdr and R console
windows, to
2005 Aug 09
5
RGUI crash when opening script in XP Home enviroment
If there is a helpfile open (f.e ?glm) and it is the top window, then
an exception error occurs (closing RGUI)
when I hit the open file button.
If the helpfile is not the top window (of the RGUI) I am able to open a
new script without any error.
The RGUI is not closing complete there is a blank screen left which I
have to close with the X Button or Taskmanager
Windows XP Home - German Version
2008 Oct 25
1
Returning a variable to before_filter
I know its probably doesnt sound right, but I am trying to call a
before_filter method that will check whats the user role and then
based on that return a string / hash / array to the before_filter
something like this:
class MonqiClassesController < ResourceController::Base
before_filter :check_user_access_level , grant_access
def check_user_access_level
if
2001 Dec 10
2
Corrupt .RData
I'm using R 1.3.1 on a Windows NT 4.0 machine. As you might
guess my machine crashes on me from time to time :-| So far,
forcing a reboot via the Taskmanager has worked reasonably
well: any open R session would enquire politely whether to
save, and do so if requested.
This time, it has not worked out. I get a 'Fatal Error:
unable to restore saved data in .RData' message and
R
2006 Feb 15
4
problem with saving id''s in a join table
hello,
I''am new to ROR and I have a problem.
I have to models "rights" and "roles" on a has_and_belongs_to_many
relationship, through "roles_rights" table. When I try to add a new role
although I put in my form fields for each right, a record is added to
table roles but none to roles_rights.
I am using Ruby 1.8.4 rails 1.0 mysql 5.0
here is my code:
2008 Sep 18
13
Re: Autocad 2008 and wine
[quote="Dotan Cohen"]
Of course they will not rewrite the software in another technology.
However, had they known that running AutoCAD in Wine was important,
they might not have switched to .NET 3.0 before it runs in Wine.
Likewise, if you start letting them know _now_ that there is demand
for AutoCAD on Linux, then in the future they won't switch from .NET
3.0 to .NET 4.0 before it
2006 Jul 02
3
2 before_filters, only want one to render something
I have two before_filters for a few of my controllers. They are running
my own methods authorize and admin_authorize. authorize is called on
just about every action to make sure that a user is logged in.
admin_authorize is called on about 80% of the actions and is used to
make sure that a user is an administrator. If a user tries to access an
admin_authorize protected action without being
2006 May 02
4
How to extend rails rake tasks?
Does anyone know how to extend the buit-in rake tasks like test:unit.
I want to custom load some fixtures in a particular order.
Thanks,
Zack