0

I'm trying to filter records from a C1 CMS data folder in the Console as part of a staff profile system on my website. What I'd like to do is show a single profile record for the staff member who is logged into the C1 Console, so that they can only edit their own staff profile and nobody else's. To do this, I'd like to match up the username they logged in with with a field in the data folder for the profiles.

So far I've created the datatype BaileyWeb.University.People, some sample records, and have added tree file:

<?xml version="1.0" encoding="UTF-8"?>
<ElementStructure xmlns="http://www.composite.net/ns/management/trees/treemarkup/1.0" xmlns:f="http://www.composite.net/ns/function/1.0">
  <ElementStructure.AutoAttachments>
    <NamedParent Name="Content" Position="Bottom"/>
  </ElementStructure.AutoAttachments>
  <ElementRoot>
    <Children>
      <Element Label="My Profile Function" Id="MyProfileRoot" Icon="user-group">
        <Children>
          <DataElements Type="BaileyWeb.University.People" Label="${C1:Data:BaileyWeb.University.People:DisplayName}" Icon="user">
            <Actions>
              <EditDataAction Label="Edit My Profile" />
              <DeleteDataAction Label="Delete My Profile" />
            </Actions>
            <Filters>
              <FunctionFilter>
                <f:function name="BaileyWeb.University.Data.MyProfile.MyFilter" xmlns:f="http://www.composite.net/ns/function/1.0" />
              </FunctionFilter>
            </Filters>
          </DataElements>
        </Children>
      </Element>
    </Children>
  </ElementRoot>
</ElementStructure>

In my C# function, I do the filtering, as per the documentation:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Web;

namespace BaileyWeb.University.Data
{
    public class MyProfile
    {
        public static Expression<Func<BaileyWeb.University.People, bool>> MyFilter()
        {
            Expression<Func<BaileyWeb.University.People, bool>> filter = f => f.UserId.Contains(System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString());
            return filter;
        }
    }
}

Unfortunately, this doesn't work, and I'm not sure why.

I'm NOT using the Active Directory login add-on, so domain logins aren't being used here. I've tried swapping out System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString() for a simple string of "admin" (which is used as a UserID for one record in the datatype) to test it, but this also fails to return a result.

When I went back to the basic tree filtering:

<Filters>
              <ParentIdFilter ParentType="BaileyWeb.University.People" ReferenceFieldName="UserId" />
              <FieldFilter FieldName="UserId" FieldValue="admin"/>
            </Filters>

... I got a result displayed, but this was for a static username value of "admin".

Can anyone help me solve this problem?

David Bailey
  • 77
  • 1
  • 8

1 Answers1

0

Did you ask for logged C1 username?

Composite.C1Console.Security.UserValidationFacade.GetUsername()
Nime Cloud
  • 6,162
  • 14
  • 43
  • 75
  • I've tried changing the code to: `public static Expression> MyFilter() { string MyUsername = Composite.C1Console.Security.UserValidationFacade.GetUsername(); Expression> filter = f => f.UserId.Equals(MyUsername); return filter; }` ... but still get no results. – David Bailey Nov 05 '21 at 11:42
  • Even setting `string MyUsername = "admin"` yields no results. What is going wrong here? – David Bailey Nov 05 '21 at 12:00