Absent Member.. b460 Absent Member..
Absent Member..
991 views

Checking permission of record type / record

Hi,

 

Can anyone suggest the correct method in the COM SDK to check if a location has access to a record type or record?

 

For example, with the record type the only way I can think of is to check if the RecordType AccessControl string contains "denied":

 

Dim recordType As TRIMSDK.RecordType

If (recordType.AccessControl.Contains("denied")) Then
..
Else
..
End If

 

Any suggestions would be appreciated.

 

Thanks.

0 Likes
5 Replies
EWillsey Acclaimed Contributor.
Acclaimed Contributor.

Re: Checking permission of record type / record

The record type object has a "HasAccess" method you can call to see if a location can use it.  First parameter is the type of access control (can use, can update, can modify access, can delete).  Second parameter is the location in question.

---------
Erik
0 Likes
Mary Bray
New Member.

Re: Checking permission of record type / record

Remembering that you may also need to check security levels and caveats we use the following code in COM to see is a location (locTest) can access a record (rec) (in this case View metadata):

 

LoginCanAccess =

false; //assume they can't see it//check if the user has access to the record//first get their locations

ArrayListloginlocs = GetLoginLocations(locLogin);

 

//get the access control location list

TRIMSDK.

Locationsaccesslocs = db.MakeLocations();

 

asAccessControlSettings acs = asAccessControlSettings.asPrivate;

rec.GetAccessControlDetailsEx(

dxRecordAccess.dxViewRecord, out acs, outaccesslocs);

 

//do we have a match

if (accesslocs != null)

{

accesslocs.Start();

TRIMSDK.

LocationlocTest = accesslocs.Next();

 

while (locTest != null)

{

if(loginlocs.Contains(locTest.Uri))

{

LoginCanAccess =

true;

 

break;

}

locTest = accesslocs.Next();

}

locTest =

null;

}

accesslocs =

null;

0 Likes
Absent Member.. b460 Absent Member..
Absent Member..

Re: Checking permission of record type / record

Thanks for that, the issue is that I can't even access the members of the record without getting a NullReferenceException.

 

For example:

 

Dim record As TRIMSDK.Record

Dim test As Boolean = record.Item(count).HasAccess(dxRecordAccess.dxViewRecord, db.CurrentUser)

When the HasAccess method is called against the record, the NullReferenceException is thrown. The user location in question was successfully able to search for the records and 2 results were returned. But when iterating through the records result set to access the members of a particular record will through the exception.

 

Any ideas why?

0 Likes
Highlighted
Matt Bayliss Honored Contributor.
Honored Contributor.

Re: Checking permission of record type / record

records.Item(count) is actually out of bounds - the Item collection is zero indexed, from 0 to (count - 1), so that could be the NullReferenceException? Try something like the code at the end of this post. Try not to chain properties (ie records.Item(x).HasAccess), as the objects aren't disposed of correctly. Instead assign records.Item(x) to a variable, and then check the HasAccess property on that - the GarbageCollector can then clean up properly.

 

I think one of the devs here at iCog had a problem where even though the record came back in the search results, it was Nothing when iterating through the results, so maybe sure the record is not Nothing before checking HasAccess.

 

If it still fails the problem might be accessing the CurrentLocation - there's a TRIM Location permission "View User Profile Details" - but I think that permission affects accessing properties of the CurrentUser, not loading the CurrentUser itself.

 

Dim trim As Database = new Database()

Dim currentuser As Location = trim.CurrentUser

Dim recsearch As RecordSearch = trim.NewRecordSearch()
recsearch.AddTitleWordClause("product")

Dim results as Records = recsearch.GetRecords()

For r As Integer = 0 To results.count - 1
    Dim rec As Record = results.item(r)
    If Not rec Is Nothing Then
        If rec.HasAccess(dxRecordAccess.dxViewRecord, currentuser) Then
            Console.WriteLine("Can view record " & rec.Number)
        End If
    End If
Next

Console.ReadLine()

 Hope that helps!

 

 

Sonny_Lau Absent Member.
Absent Member.

Re: Checking permission of record type / record

How would I do this using the .NET SDK? I've noticed there's no HasAccess method for a record but there is an AccessAllowedForUser method in the AccessControlList. My issue with this function is that I'm not sure what I should be entering for the first parameter. Instead of asking for a RecordAccess it's asking for an int, defined with int forLocation and I can't tell what it wants from me.

 

Here's what I currently have.

record.AccessControlList.AccessAllowedForUser((int)RecordAccess.ViewRecord, user)

 

I'd also like to know how I could retrieve Caveats for a record and for users as well.

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.