How to get all rolegroups in dotnetnuke - dotnetnuke

RoleController.GetRoleGroups(portalid); is giving only user created group not Global Roles Group that is created by default.

You can use RoleController.GetRoleGroups() for this :-
var arrGroups = RoleController.GetRoleGroups(portalSettings.PortalId);
foreach (RoleGroupInfo roleGroup in arrGroups)
{
//Your Logic goes here :-
}
You can use RoleController.GetRoles() for this :-
There are two overload of this method :-
IList<RoleInfo> GetRoles(int portalId, Func<RoleInfo, bool> predicate);
IList<RoleInfo> GetRoles(int portalId);
You can see the Source code here :-
This is how you can use the method :-
foreach (var role in TestableRoleController.Instance.GetRoles(portalId))
{
// you can Put your Logic here :-
}

The global role group is really the absence of a role group. So, the "global" group is roles with a group ID of -1.

Related

How do I get the AD group and add users to it?

I haven't done this in so long and I simply want to get the group CoreControls and add a user or another group. How do I write the FindByIdentity? It always return null. The domain is crp.name.local
using (PrincipalContext pc = new PrincipalContext(
ContextType.Domain,
"crp",
username,
password))
{
// group is null and I've tried many examples...
var group = GroupPrincipal.FindByIdentity(pc, "ou=CoreControls");
group.Members.Add(pc, IdentityType.UserPrincipalName, userId);
group.Save();
}
I think the problem is CoreControls is not actually a group, but an OU. So you cannot use GroupPrincipal here. Try this PrincipalContext overload instead:
using (PrincipalContext pc = new PrincipalContext(
ContextType.Domain,
"crp",
"OU=CoreControls,OU=Security,OU=Global Groups,DC=crp,DC=local"
username,
password))
You will have to fiddle with the container parameter to get it just right.

Adding multiple owners for Google App Maker records

I need help with Google App Maker data model security. I want to set multiple owners for a single record. Like the current user + the assigned admin + super admin.
I need this because all records can have different owners and super-owners/admins.
I know that we can point google app maker to a field containing record owner's email and we can set that field to the current user at the time of the creation of the record.
record.Owner = Session.getActiveUser().getEmail();
I want to know if it is possible to have field owners or have multiple fields like owner1, owner2 and then assign access levels to owner1, owner2...
Or how can we programmatically control the access/security/permissions of records?
The solution I'd use for this one definitely involves a field on the record that contains a comma separated string of all the users who should have access to it. I've worked on the following example to explain better what I have in mind.
I created a model and is called documents and looks like this:
In a page, I have a table and a button to add new document records. The page looks like this:
When I click on the Add Document button, a dialog pops up and looks like this:
The logic on the SUBMIT button on the form above is the following:
widget.datasource.item.owners = app.user.email;
widget.datasource.createItem(function(){
app.closeDialog();
});
That will automatically assign the creator of the record the ownership. To add additional owners, I do it on an edit form. The edit form popus up when I click the edit button inside the record row. It looks like this:
As you can see, I'm using a list widget to control who the owners are. For that, it is necessary to use a <List>String custom property in the edit dialog and that will be the datasource of the list widget. In this case, I've called it owners. I've applied the following to the onClick event of the edit button:
var owners = widget.datasource.item.owners;
owners = owners ? owners.split(",") : [];
app.pageFragments.documentEdit.properties.owners = owners;
app.showDialog(app.pageFragments.documentEdit);
The add button above the list widget has the following logic for the onClick event handler:
widget.root.properties.owners.push("");
The TextBox widget inside the row of the list widget has the following logic for the onValueEdit event handler:
widget.root.properties.owners[widget.parent.childIndex] = newValue;
And the CLOSE button has the following logic for the onClick event handler:
var owners = widget.root.properties.owners || [];
if(owners && owners.length){
owners = owners.filter(function(owner){
return owner != false; //jshint ignore:line
});
}
widget.datasource.item.owners = owners.join();
app.closeDialog();
Since I want to create a logic that will load records only for authorized users, then I had to use a query script in the datasource that will serve that purpose. For that I created this function on a server script:
function getAuthorizedRecords(){
var authorized = [];
var userRoles = app.getActiveUserRoles();
var allRecs = app.models.documents.newQuery().run();
if(userRoles.indexOf(app.roles.Admins) > -1){
return allRecs;
} else {
for(var r=0; r<allRecs.length; r++){
var rec = allRecs[r];
if(rec.owners && rec.owners.indexOf(Session.getActiveUser().getEmail()) > -1){
authorized.push(rec);
}
}
return authorized;
}
}
And then on the documents datasource, I added the following to the query script:
return getAuthorizedRecords();
This solution will load all records for admin users, but for non-admin users, it will only load records where their email is located in the owners field of the record. This is the most elegant solution I could come up with and I hope it serves your purpose.
References:
https://developers.google.com/appmaker/models/datasources#query_script
https://developers.google.com/appmaker/ui/binding#custom_properties
https://developers.google.com/appmaker/ui/logic#events
https://developers-dot-devsite-v2-prod.appspot.com/appmaker/scripting/api/client#Record

How to add currentUser to scope using angular-fullstack

I am using angular-fullstack which comes packed with Authentication already set up. there is a handy function getCurrentUser() which allows me to do something like:
<input ng-bind="getCurrentUser.name"/>
And I will get the name of the active user.
What I would like to do is attach the users name to another object in my scope. Something like this:
$scope.activeUser = $scope.getCurrentUser();
However I am not sure how to go about joining active user with the getCurrentUser() function.
Define activeUser as an array of elements then add only the ids. When needed do something like this:
$scope.activeUser = [];
if (isActive()) {
var currentUser = $scope.getCurrentUser();
$scope.activeUser.push(currentUser.id);
}
isActive() is a function you should create to define if the user is active or not.
Then you need another condition or a "else" to remove user isn't active anymore.
EDIT: of course you can add the entire object if needed to the array you do that with:
$scope.activeUser[currentUser.id] = currentUser;
Then you can get it back on the view with:
<span>{{ activeUser[TheId] }}</span

Creating an array of SelectOption Lists

Im trying to set up an online test, using a visualforce page that pulls data from 3 objects in salesforce COPE_Tests__C, COPE_Questions__C, and COPE_Options__c. Once the user selects the specific test, I thought I would be able to make a call like this to get all the other data:
questions = [select id, name, question_body__c,
(select id, name, option_body__c from COPE_options__r order by name ASC)
from COPE_questions__c where COPE_test__c = :tid];
And then use apex:repeat and apex:selectRadio/apex:selectOption to generate the actual test form. But for some reason it would not render the radioboxes. So it would seem I need to create selectOption lists and then use apex:selectOptions. But im not sure how to set this up . How can I have it create a public list<selectOption> automatically for each question?
Is there a way to set up an array of list<selectOption>?
I don't know about creating it automatically but going over your question object in a loop should be pretty easy, something over the lines of
List<List<SelectOption> options = new List<List<SelectOption>;
for(COPE_Questions__C q : questions){
List<SelectOption> list = new List<SelectOption>();
for(COPE_options__r op : q.COPE_options__r){
list.add(new SelectOption(op.id, op.option_body__c);
}
options.add(list);
}
Hope it helps.

Symfony2 mapping between 3 entities

I have three entities : Event, Photo and User.
Three main relations :
An Event has 0 or more photos (blue relation, OneToMany)
An Event has been created by one photo, which I call the firstPhoto (red relation,
OneToOne)
A user can create 0 or more photos (violet relation,
OneToMany)
What I want is to map the relation between an Event and the User who created it, without adding or changing my database. It means the user that created the firstPhoto of the Event.
I'm not looking for a SQL query which I succed to do but really a mapping in my User.php Entity.
$user->getEvents() would give the events the user created.
I can't success to do so... any idea ? Am I obliged to add or change something in my database ?
I see 2 ways of doing that:
1) make a named native query http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/native-sql.html#named-native-query
2) write something like
public function getEvents()
{
$res = array();
$photos = $this->getPhotos();
foreach($photos as $photo) {
$res[] = $photo->getEvent();
}
return $res;
}

Resources