How do I get "Active" Courses from Desire2Learn Valence API? - desire2learn

Is there any way to check if a course is Active.
I currently retrieve a list of courses for an instructor by:
GET /d2l/api/lp/(/D2LVERSION: //version/)/enrollments/users/(/D2LID: //userId/)/orgUnits/
Once I have the list of enrollments for the user, I can filter which
ones the user is an Instructor in.
Once I have the courses the user is an Instructor in, how can I check
which ones are active?
I see that the data MyOrgUnitInfo may be available in the call:
GET /d2l/api/lp/(/D2LVERSION: //version/)/enrollments/myenrollments/
However, this is not applicable to me, as I am getting enrollments based
on a userId

If you are not able to use the "myenrollments" call to retrieve the enrollments within the instructor's calling user context, then the route to find out which courses within an identified user's enrollments are active is a bit more complex.
1) You can first use
/d2l/api/lp/{ver}/enrollments/user/{userId}/orgUnits&roleId={roleId}&orgUnitTypeId={orgUnitType}
to filter the list of returned enrollments by role and by org unit type: use the "instructor" role ID and the org unit type ID for course offerings in the call.
This will fetch you back a paged list of OrgUnitInfo structures, which in turn contain the org unit ID for all the org units.
2) Once you have this list of org unit IDs, you can test each one in the list to see if its active with
/d2l/api/lp/{ver}/courses/{orgUnitId}
This will fetch back the CourseOffering structure for each course, containing an IsActive property telling you if the course offering is active or not.

Related

Updating a base entity that has many to many relation without retrieving the data in the junction table

I have a Users table, along with Roles table with many to many relation
Users
Id, Name, Password, ICollection<Role> ....
Roles
Id, Name
and UsersRoles
UserId, RoleId
Now if I retrieve a user object from the database and modify the Password field of example, an exception will occur if i don't load the roles even though I'm not touching the roles of the user.
So the question is: how can I update the Users table without retrieving all the roles every time?

Access Groups Associated with Project Role Using Atlassian API

I am currently developing a plugin that allows project administrators to manage users in groups. I have been combing through the api reference documentation and I cannot seem to find any calls that I can make that will allow me to see the groups associated with a particular project.
I have looked through the API's at every location that is relevant to what I am searching for to no avail.
I currently have a database query that provides me what I am looking for.
SELECT ROLETYPEPARAMETER AS "Groups"
FROM projectrole PROJECT_ROLE,
projectroleactor PROJECT_ROLE_ACTOR
JOIN project PROJECT
ON PROJECT.id = PROJECT_ROLE_ACTOR.PID
JOIN cwd_group
ON group_name = roletypeparameter
WHERE PROJECT_ROLE_ACTOR.projectroleid = PROJECT_ROLE.id
AND PKEY = <projectkey>;
I would prefer to manipulate this data through the API if at all possible.
All the other pieces are available for me to complete the plugin to add, remove users from groups.
I know the information that I am looking for is available. If you navigate to the roles page you have both the users in roles, and also the groups in roles. I'm sure i'm overlooking something minor with the API to give me the groups associated with the project.
After implementing my database route, I came back to a non-database approach. This is the implementation that solves the problem.
The way the groups are implemented is as a role actor as a set underneath the project roles. One more level down you have your group names as a descriptor to the role actor.
//Create TreeMap to Store the Role-Group association. Note a role can have more than one group
TreeMap<String,Collection<String>> projectGroups = new TreeMap<String,Collection<String>>();
//Get all the project roles
Collection<ProjectRole> projectRoles = projectRoleManager.getProjectRoles();
//Iterate through each role and get the groups associated with the role
for (ProjectRole projectRole : projectRoles)
{
//Get the role actors for the project role
ProjectRoleActors roleActors = projectRoleManager.getProjectRoleActors(projectRole, project);
//Create an iterator to grab all of the groups for this project role
Iterator <RoleActor> roleActorIterator = roleActors.getRoleActors().iterator();
//Create a collection of strings to store all of the group's roles to put in the map
Collection <String> groupRoles = new ArrayList<String>();
//Iterate the role actors to get the groups
while (roleActorIterator.hasNext())
{
//Add the group by string name into collection
groupRoles.add(roleActorIterator.next().getDescriptor());
}//END While
//Add that role, and the associated groups to that role into our map.
projectGroups.put(projectRole.getName(), groupRoles);
}//END For
The output of this will look similarly to this
{Administrators=[jira-administrators], Developers=[jira-developers, jira-users], Users=[jira-users]}

Valence enrollments in orgUnit with incorrect roleId parameter

I'm using /enrollments/orgUnits/{orgUnitid}/users/?roleid=XXX
Works correctly with numeric roleId (both existing and not existing).
When roleId is not numeric (eg "Instructor") the call doesn't throw an error and returns all enrollments in the OU.
That clearly sounds like a defect; I would encourage you to contact D2L's support desk and report it as such (so that you can provide details of your back-end service, like version and service-pack level).

How to retrieve user data from two different tables using entity framework

I want to retrieve data of particular user from two different tables such as "Organizations" and "SystemUsers" in which the company details are stored in "Organizations" & his personal info. is stored in "Systemusers" like emailid,password etc..
But what my requirement is I want to retrieve that particular user organization details as well as personal info like emailid, using entityframework in asp.net mvc. Can anyone suggest me the query to do this.
Table: Organizations
public string CompanyName {get; set;}
Table : Systemusers
public string Email {get; set;}
So, I want to retrieve the user company details as well as personal details from two tables so as to display them in search form.Can anyone suggest me query for this????
going by your description and lack of code im assuming that every user will have 0 or 1 organization.
so 1. you will have to make a one to 0 or 1 relation between user and organization then a simple query on the SystemUser table will retrieve the Users personal info and because now in this table you will have a foreign key (assuming name to be Organization) you can retrieve the organiation info using .Organization property of the retrieved SystemUser

ASP.NET MVC: relationship between models and MembershipUsers

I have a model, Docs, with a guid column, author_id, which should reference a MembershipUser.
I'm using the standard MembershipProvider (I only changed the db name), and of course I haven't a model for MembershipUsers.
I can easily define some methods in class Docs to get MembershipUser for a Doc and all Docs for a MembershipUser, but some things are tricky (listing users, show how many docs each user has); furthermore, I feel I'm using MVC in an odd way: it seems to me that it would be easier if I had a MembershipUsers model...
How can I implement this relationship? Should I implement a model for MembershipUsers?
thanks
update: I realize I wasn't clear at all.
Say I want to list all my users and their docs.
One way to do this is:
ViewModel model = new ViewModel()
{
Users = from MembershipUser user in Membership.GetAllUsers(page, pagesize, out totalusers)
select new UserWithDocs
{
User = user,
Docs = context.Docs.Where(c => c.author_id == (Guid) user.ProviderUserKey)
},
UsersCount = totalusers
};
This works, but generates one separate query for each user.
I could get an array of users' guids and then query for Docs where author_id IN list_of_guids, but then I should manually associate each doc to its author.
What is a better solution?
not sure if i understand you correctly, but you can use the MembershipUser class as your model for users. if you want to reference user to your "doc" model, you can simply add a property "Author" to you model class and when you fetch the model from DB you can get the user as well.
the Membership class contains some static methods to list all users, add/delete users etc.

Resources