On The Mark

Contributing to the vast web, 1 blog post at a time – blogs by Mark Monica

Browsing Posts in Programming

Scenario

 

On machines where Vista/W7 is installed there appears to be an issue when checking to see if a user is in a role.  User Account Control (UAC) must be on to reproduce the issue.  The result is that the value returned is always FALSE even when the user does belong to the group.

 

Sample Code (UAC must be on to produce error)

 

If My.User.IsInRole(“My Domain\My Group”) Then

     Return True

Else

     Return False

End If

Workaround

 

To get around this I created a function using other .Net functions.

Public Function IsInUserRole(ByVal RoleToFind As String) As Boolean

    Dim id As WindowsIdentity = WindowsIdentity.GetCurrent
    Dim irc As IdentityReferenceCollection

    ‘ Gets a SID list of groups the user belongs to

    irc = id.Groups

    For Each ir As IdentityReference In irc

        ‘ Need to convert the SID to plain english

Technorati Tags: ,,


        Dim act As NTAccount = CType(ir.Translate(Type.GetType("System.Security.Principal.NTAccount")), NTAccount)

        If act.Value = RoleToFind Then

            Return True

        End If

    Next

    Return False

End Function

Next week I’ll be attending RailsConf 09 in Las Vegas, NV. Since I’m still pretty new to Rails I’m taking one of the tutorial classes “A-Z Intro to Rails Tutorial” and the presenter has already provided info from his site. Cool!

Background

Upon continuing a Ruby on Rails project after a few months delay, Aptana Studio’s RadRails editor installed some updates.  I suspect something that  changed in Rails itself (GEM update) caused the error I received.

Error Message

undefined method `include_root_in_json=’ for ActiveRecord::Base:Class (NoMethodError)

Solution

To fix this error rename the config/initializers/new_rails_defaults.rb to config/initializers/new_rails_defaults.rb.bak.

It appears that the old code placed in these files no longer works with ROR 2.0.2.

# These settings change the behavior of Rails 2 apps and will be defaults
# for Rails 3. You can remove this initializer when Rails 3 is released.

# Include Active Record class name as root for JSON serialized output.
ActiveRecord::Base.include_root_in_json = true

# Store the full class name (including module namespace) in STI type column.
ActiveRecord::Base.store_full_sti_class = true

# Use ISO 8601 format for JSON serialized times and dates.
ActiveSupport.use_standard_json_time_format = true

# Don’t escape HTML entities in JSON, leave that for the #json_escape helper.
# if you’re including raw json in an HTML page.
ActiveSupport.escape_html_entities_in_json = false

The file now created in a new project appears as follows:

# These settings change the behavior of Rails 2 apps and will be defaults
# for Rails 3. You can remove this initializer when Rails 3 is released.

if defined?(ActiveRecord)
# Include Active Record class name as root for JSON serialized output.
ActiveRecord::Base.include_root_in_json = true

# Store the full class name (including module namespace) in STI type column.
ActiveRecord::Base.store_full_sti_class = true
end

# Use ISO 8601 format for JSON serialized times and dates.
ActiveSupport.use_standard_json_time_format = true

# Don’t escape HTML entities in JSON, leave that for the #json_escape helper.
# if you’re including raw json in an HTML page.
ActiveSupport.escape_html_entities_in_json = false

Footnotes

See  http://www.hostingrails.com/1461/dbmigrate-undefined-method-include_root_in_json for more help with this error.

Eye-tracking studies are hot in the web design world, but it can be hard to figure out how to translate the results of these studies into real design implementations. These are a few tips from eye-tracking studies that you can use to improve the design of your blog or site.

read more | digg story

Powered by WordPress Web Design by SRS Solutions © 2010 On The Mark Design by SRS Solutions