cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
diegomarino
Level: Powered On

restrict access to single record by user

Hi i read something to restrict access based on user

my question is a bit different from the stuff i found

 

may i restrict access for a single record to users except me (the admin)?

thanks

4 REPLIES 4
Super User
Super User

Re: restrict access to single record by user

Yes, you can as long as the record you want to return can be uniquely tied to that user.  Email address is the most reliable linkage to use because email address is always unique even though name may not be.  You can obtain the identity of the individual who is logged on to the application with User().Email.

 

I currently have an application that allows a user to submit and update their resume. When the user accesses the application, the only thing they will ever see is their own resume and associated information stored about themselves.  They cannot see anything else.  If an admin logs on they can see the records for any individual in the system.

diego_marino
Level: Powered On

Re: restrict access to single record by user

thanks for the answer

yes, i'd like to have some records visible only by me (admin)

i know the user().email...but how may i set a record visible only by me? 

Super User
Super User

Re: restrict access to single record by user

The exact syntax is going to depend on the specifics of your application, but in mine, it's done with the filter on the gallery.  My app actually presents different information based on 3 different personnas:  an individual consultant, a manager or a resource manager.  I have a series of checks that set global variables that tell me if the person is a manager or resource manager, then I have an If statement that looks at those global variables and performs the right filter.  A very simplified version of my code would be something like this. 

//* check to see if the person has been identified as a resource manager
If (IsResourceManager, 
         Filter(ListOfData, <list of conditions>, 
//* if they weren't a resource manager, check to see if they are a manager
    IsManager, 
         Filter(colResources, Email4Resource in AllReports.userPrincipalName || 
                 Email4Resource in AllReports.UserPrincipalName,
//* if they weren't a resource manager or a manager, they must be an individual
    Filter(colResources,Email4Resource = CurrentUserEmail))

My data is loaded into a collection (colResources) and I have a second collection I have built which lists the identities of the manager's direct reports (AllReports).

diego_marino
Level: Powered On

Re: restrict access to single record by user

thanks very much

i decided to add a yes/no field called manager, if is true my collaborator cannot see the record

If(
    User().FullName = "diego marino";
    Filter(
        Candidati;
        StartsWith(
            ComuneDesc;
            TBcandidatifiltrocomune.Text
        ) && (IsBlank(TBcandidatifiltroptftrasferibile.Text) || DPcandidatifiltroptftrasferibile.Selected.Value = "=" && 'Ptf trasferibile personale' = Value(TBcandidatifiltroptftrasferibile.Text) || DPcandidatifiltroptftrasferibile.Selected.Value = ">=" && 'Ptf trasferibile personale' >= Value(TBcandidatifiltroptftrasferibile.Text) || DPcandidatifiltroptftrasferibile.Selected.Value = "<=" && 'Ptf trasferibile personale' <= Value(TBcandidatifiltroptftrasferibile.Text)) && (StartsWith(
            Cognome;
            TBcercacandidato.Text
        )) && (IsBlank(TBcandidatifiltroptfbanca.Text) || DPcandidatifiltroptfbanca.Selected.Value = "=" && 'Ptf banca personale' = Value(TBcandidatifiltroptfbanca.Text) || DPcandidatifiltroptfbanca.Selected.Value = ">=" && 'Ptf banca personale' >= Value(TBcandidatifiltroptfbanca.Text) || DPcandidatifiltroptfbanca.Selected.Value = "<=" && 'Ptf banca personale' <= Value(TBcandidatifiltroptfbanca.Text))
    );
    Filter(
        Candidati;
        StartsWith(
            ComuneDesc;
            TBcandidatifiltrocomune.Text
        ) && (Manager <> true) && (IsBlank(TBcandidatifiltroptftrasferibile.Text) || DPcandidatifiltroptftrasferibile.Selected.Value = "=" && 'Ptf trasferibile personale' = Value(TBcandidatifiltroptftrasferibile.Text) || DPcandidatifiltroptftrasferibile.Selected.Value = ">=" && 'Ptf trasferibile personale' >= Value(TBcandidatifiltroptftrasferibile.Text) || DPcandidatifiltroptftrasferibile.Selected.Value = "<=" && 'Ptf trasferibile personale' <= Value(TBcandidatifiltroptftrasferibile.Text)) && (StartsWith(
            Cognome;
            TBcercacandidato.Text
        )) && (IsBlank(TBcandidatifiltroptfbanca.Text) || DPcandidatifiltroptfbanca.Selected.Value = "=" && 'Ptf banca personale' = Value(TBcandidatifiltroptfbanca.Text) || DPcandidatifiltroptfbanca.Selected.Value = ">=" && 'Ptf banca personale' >= Value(TBcandidatifiltroptfbanca.Text) || DPcandidatifiltroptfbanca.Selected.Value = "<=" && 'Ptf banca personale' <= Value(TBcandidatifiltroptfbanca.Text))
    )
)

i tried to add a single condition between the other to save code but didn't work

 

Filter(
    Candidati;
    StartsWith(
        ComuneDesc;
        TBcandidatifiltrocomune.Text
    ) && (User().FullName = "Diego marino" || Manager <> true) && (IsBlank(TBcandidatifiltroptftrasferibile.Text) || DPcandidatifiltroptftrasferibile.Selected.Value = "=" && 'Ptf trasferibile personale' = Value(TBcandidatifiltroptftrasferibile.Text) || DPcandidatifiltroptftrasferibile.Selected.Value = ">=" && 'Ptf trasferibile personale' >= Value(TBcandidatifiltroptftrasferibile.Text) || DPcandidatifiltroptftrasferibile.Selected.Value = "<=" && 'Ptf trasferibile personale' <= Value(TBcandidatifiltroptftrasferibile.Text)) && (StartsWith(
        Cognome;
        TBcercacandidato.Text
    )) && (IsBlank(TBcandidatifiltroptfbanca.Text) || DPcandidatifiltroptfbanca.Selected.Value = "=" && 'Ptf banca personale' = Value(TBcandidatifiltroptfbanca.Text) || DPcandidatifiltroptfbanca.Selected.Value = ">=" && 'Ptf banca personale' >= Value(TBcandidatifiltroptfbanca.Text) || DPcandidatifiltroptfbanca.Selected.Value = "<=" && 'Ptf banca personale' <= Value(TBcandidatifiltroptfbanca.Text))
)

 

 

 

Helpful resources

Announcements
thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

Top Kudoed Authors
Users Online
Currently online: 171 members 5,006 guests
Please welcome our newest community members: