private RoleBE GetRoleFromUrl(bool mustExist) { RoleBE r; string roleid = DreamContext.Current.GetParam("roleid"); // Double decoding of name is done to work around a mod_proxy issue that strips out slashes roleid = XUri.Decode(roleid); if (roleid.StartsWith("=")) { string name = roleid.Substring(1); r = PermissionsBL.GetRoleByName(name); if (r == null && mustExist) { throw new SiteRoleNameNotFoundException(name); } } else { uint roleIdInt; if (!uint.TryParse(roleid, out roleIdInt)) { throw new SiteRoleIdInvalidArgumentException(); } r = PermissionsBL.GetRoleById(roleIdInt); if (r == null && mustExist) { throw new SiteRoleIdNotFoundException(roleIdInt); } } return(r); }
public static XDoc GetGroupXmlVerbose(GroupBE group, string relation) { XDoc groupXml = GetGroupXml(group, relation); ServiceBE authService = ServiceBL.GetServiceById(group.ServiceId); if (authService != null) { groupXml.Add(ServiceBL.GetServiceXml(authService, "authentication")); } groupXml.Start("users"); if (group.UserIdsList != null) { groupXml.Attr("count", group.UserIdsList.Length); } groupXml.Attr("href", DekiContext.Current.ApiUri.At("groups", group.Id.ToString(), "users")); groupXml.End(); //Permissions for the group RoleBE role = PermissionsBL.GetRoleById(group.RoleId); groupXml.Add(PermissionsBL.GetRoleXml(role, "group")); return(groupXml); }
public static XDoc GetUserXmlVerbose(UserBE user, string relationAttr, bool showPrivateInfo, bool showGroups, bool showProperties) { XDoc userXml = GetUserXml(user, relationAttr, showPrivateInfo); userXml.Elem("date.created", user.CreateTimestamp); if (!IsAnonymous(user)) { PageBE homePage = GetHomePage(user); if (homePage != null && homePage.ID != 0) { userXml.Add(PageBL.GetPageXml(homePage, "home")); } } userXml.Start("status").Value(user.UserActive ? "active" : "inactive").End(); userXml.Start("date.lastlogin").Value(user.Touched).End(); userXml.Start("language").Value(user.Language).End(); userXml.Start("timezone").Value(user.Timezone).End(); ServiceBE authService = ServiceBL.GetServiceById(user.ServiceId); if (authService != null) { userXml.Add(ServiceBL.GetServiceXml(authService, "authentication")); } //Permissions for the user from user role userXml.Add(PermissionsBL.GetRoleXml(PermissionsBL.GetRoleById(user.RoleId), "user")); ulong effectivePermissions = PermissionsBL.CalculateEffectiveUserRights(user); //Effective permissions for the user from the role + group roles. userXml.Add(PermissionsBL.GetPermissionXml(effectivePermissions, "effective")); // Set of permissions revoked from the user userXml.Add(PermissionsBL.GetPermissionsRevokedXml(user)); // check if groups should be included if (showGroups) { userXml.Start("groups"); IList <GroupBE> groups = DbUtils.CurrentSession.Groups_GetByUser(user.ID); if (null != groups) { foreach (GroupBE g in groups) { userXml.Add(GroupBL.GetGroupXmlVerbose(g, null)); } } userXml.End(); } // retrieve properties for current user while providing an href for other users. if (showProperties && (DekiContext.Current != null && DekiContext.Current.User != null && DekiContext.Current.User.ID == user.ID)) { IList <ResourceBE> props = PropertyBL.Instance.GetUserProperties(user.ID); userXml = PropertyBL.Instance.GetPropertyXml(props, GetUri(user), null, null, userXml); } else { userXml.Start("properties").Attr("href", GetUri(user).At("properties")).End(); } // TODO Max: get <subscriptions> (watchlist) not implemented return(userXml); }