How to check the run-time user?

I want to have different information presented for different users upon login (and one user who can see the whole information but not being able to alter it)?
I have tried to make it for a group with the can-read property, but I am not sure how to get the current run-time user?
This is a piece of code that I currently have with some try-outs.

users
    dynamic: .'Users'

    user-initializer: (
        'Type' = create 'Unknown' ( )
    )

    passwords: .'Passwords'
        password-value: .'Data'.'Password'
        password-status: .'Data'.'Active'
            active: 'Yes' ( )
            reset: 'No' ( )
        password-initializer: (
            'Data' = ( )
        )

interfaces

root {
	'Users': collection ['Name'] {
		'Name': text
		'Type': stategroup (
			'Admin' { }
			'Unknown' { }
		)
	}

	'Passwords': collection ['User'] {
		'User': text -> ^ .'Users'[]
		'Data': group {
			can-update: user is ( ^ >'User' )
			'Password': text
			'Active': stategroup (
				'No' { }
				'Yes' { }
			)
		}
	}
	 'Company information': group {
		// can-read: user is ( ^ .'Passwords'.'User' )
	 	// can-read: user is (  ^ .'Passwords'[] > 'User' )
	 	// can-read: ^ .'Passwords' [ user .'Name']
		// can-read: user is ( ^ .'Passwords' [ user .'Name'] )
	 	'Name': text
	 	'Address': text
	 	'Number of employees': number 'employee'
	}

With user, you get the signed-in user at runtime, if any. You do not need to do anything with the Passwords collection for can-read. Suppose that you want only Admin users to read Company information, you could write this:

can-read: user .'Type'?'Admin'

You can find more examples in the documentation.

1 Like

Thank you for the fast reply, I understand that based on the type I can filter what one user can read, but my problem is how to differentiate the information shown between different users?
I have also searched in the documentation, but could not find anything regarding this.
Basically, I want a user to see only the information they have created and not the other users’ information while keeping the template the same (collection, groups and so on), just upon login different information to be presented regarding the type of the user.

I am not exactly sure what you are trying to achieve. If you want Users to only see data they created themselves, you need to store that information. For example, if you only want Users to be able to read and update their own posts, you need to store a Creator:

'Posts': collection ['Post'] {
	can-read: user is ( >'Creator' )
	can-update: user is ( >'Creator' )

	'Post': text
	'Creator': text -> ^ .'Users'[]
}

This way, upon login the signed-in user will only see their Posts.

Note that your application model specifies all data for a single application for all application users. I hope this helps.

1 Like

On second thought: configuring a landing-page may also help you achieve your goal. Suppose that a user represents a Company that has its own Application Data:

'Company Data': collection ['Company'] {
	can-read: user is ( >'Company' )
	can-update: user is ( >'Company' )

	'Company': text -> ^ .'Users'[]
	'Company information': group {
		'Name': text
		'Address': text
		'Number of employees': number 'employee'
	}
}

If you want the user to see their specific Application Data when signing in, you can add this line to the end of the settings.alan file of your auto-webclient system (./systems/client/settings.alan in the default online IDE project):

landing-page: root .'Company Data' [ user ] open entity

In the client settings grammar you can find all available options for configuring a landing page (and other parts of the settings.alan file).