Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeDevelopment and...Development and...DNN Platform (o...DNN Platform (o...DeleteUserRole Obsolete or Not?DeleteUserRole Obsolete or Not?
Previous
 
Next
New Post
10/15/2013 5:42 PM
 

I need to delete a role from a user. The DeleteUserRole methods are in RoleController. My site is using DNN 7.0

The method signatures are shown below. The one current method says it takes a UserInfo as the first param. However, I get an error saying it is expecting an int. Is there a problem in this code in DNN 7.0? Can someone verify if it is fixed in 7.1?

public static bool DeleteUserRole(UserInfo objUser, RoleInfo role, PortalSettings portalSettings, bool notifyUser);

 

[Obsolete("Deprecated in DotNetNuke 6.2.")]
public static bool DeleteUserRole(int userId, RoleInfo role, PortalSettings portalSettings, bool notifyUser);
[Obsolete("Deprecated in DotNetNuke 6.2.")]
public static bool DeleteUserRole(int roleId, UserInfo user, PortalSettings portalSettings, bool notifyUser);
[Obsolete("Deprecated in DotNetNuke 6.2.")]
public bool DeleteUserRole(int portalId, int userId, int roleId);

 

 
New Post
10/15/2013 6:28 PM
 

Hello,

I apologise for the poor obsolete text, those methods should detail the new API methods to use - however if you look at the internals you'll notice that they do call the relevant new bits

[Obsolete("Deprecated in DotNetNuke 6.2.")]

public static bool DeleteUserRole(int userId, RoleInfo role, PortalSettings portalSettings, bool notifyUser)

{

UserInfo objUser = UserController.GetUserById(portalSettings.PortalId, userId);

return DeleteUserRole(objUser, role, portalSettings, notifyUser);

}

[Obsolete("Deprecated in DotNetNuke 6.2.")]

public static bool DeleteUserRole(int roleId, UserInfo user, PortalSettings portalSettings, bool notifyUser)

{

RoleInfo role = TestableRoleController.Instance.GetRole(portalSettings.PortalId, r => r.RoleID == roleId);

return DeleteUserRole(user, role, portalSettings, notifyUser);

}

[Obsolete("Deprecated in DotNetNuke 6.2.")]

public bool DeleteUserRole(int portalId, int userId, int roleId)

{

return DeleteUserRoleInternal(portalId, userId, roleId);

}

you'll notice that the first two use the new API as expected (the 3rd uses an internal method as it's particularly old). The API method you should use is -if it's reporting that the first item should be an int then you are not calling the method with the correct 4 parameters and it's trying to use one of the old obsolete methods

public static bool DeleteUserRole(UserInfo objUser, RoleInfo role, PortalSettings portalSettings, bool notifyUser)

 

 


Buy the new Professional DNN7: Open Source .NET CMS Platform book Amazon US
 
New Post
10/16/2013 10:44 AM
 

Thanks for the help. It turns out I was accessing the method improperly which was leading to confusion.

Like the other methods I was using I accessed them from an instance of RoleController. Like this:

var roleController = new RoleController();
roleController.DeleteUserRole(UserInfo, ownerRole, PortalSettings, false);

However I should have been accessing it through the static class.

RoleController.DeleteUserRole(UserInfo, ownerRole, PortalSettings, false);

Now, the problem I find is that it seems a user can't delete themselves from a role unless they are an admin. Which is odd because they can add themselves to a role. Anyway, I will look into updating the expire date and hoping that is enough.


 
New Post
10/16/2013 11:01 AM
 

Hmmmm. Not seeing a way to have code run a user's context remove themselves from a role without direct database manipulation. Oh well. I guess I cannot rely on Roles to do what I need.

 
New Post
10/16/2013 11:22 AM
 

Actually I got DeleteUserRole to work. I had another error in my logic that was not calling  DeleteUserRole.

 
Previous
 
Next
HomeHomeDevelopment and...Development and...DNN Platform (o...DNN Platform (o...DeleteUserRole Obsolete or Not?DeleteUserRole Obsolete or Not?


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out