logo

Warning: The forum is now for consultation only. Please use GitHub Discussions to post any questions or comments.


Welcome Guest ! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
cyracks  
#1 Posted : Friday, June 26, 2020 8:54:34 AM(UTC)
cyracks

Rank: Member

Groups: Registered
Joined: 6/5/2020(UTC)
Posts: 12
Slovenia

Thanks: 4 times
Hello,

what is the proper way to define class variable in razor scripts ? All the examples starts by defining a variable from a Model, which I assume is a "global" variable defined based on the context.
Quote:

@{
ReportModel model = Model;
...
}


For example I would like to use class SecurityUser in Pre SQL statement of MetaData/SQL model so I tried
https://sealreport.org/H...82-782d-08ed5f31692a.htm

Quote:

@using Seal.Model
@{
SecurityUser UserClass; // = ?
string result = "select '"+UserClass.WebUserName+'"';
}
@Raw(result)


But error "Use of unassigned local variable 'UserClass'" is shown.


ps: I am new to Seal Report and have no experience in Razor language

Edited by user Friday, June 26, 2020 9:25:04 AM(UTC)  | Reason: Not specified

epf  
#2 Posted : Saturday, June 27, 2020 3:39:36 PM(UTC)
epf

Rank: Administration

Groups: Administrators
Joined: 12/20/2013(UTC)
Posts: 1,209
Switzerland

Thanks: 14 times
Was thanked: 206 time(s) in 199 post(s)
A razor script is executed with one instance of an object class...
The type of the object depends on the script.

For the pre-sql statement, the object is a MetaTable,
if you want the security context from this when the table is involved in a query, you should adapt the following sample:
Code:
@{
    MetaTable table = Model;
    Environment.UserName; //This gives the windows user of the process running the engine
    if (table.Source.Report != null && table.Source.Report.SecurityContext != null)
    {
        var securityContext = table.Source.Report.SecurityContext; //User is logged through a Web Report Servert and has a context
        securityContext.Name; //Name of the user set during the login
        securityContext.WebUserName; //Name got from the login window
        //securityContext.SecurityGroups; //List of security groups set for the user
        if (securityContext.BelongsToGroup("Default Group")) { //Test if the user belongs to a group
            //Special restriction here
        }
    }
}


Got from https://sealreport.org/Recipes#lineDynamicSecurity

Edited by user Saturday, June 27, 2020 3:40:51 PM(UTC)  | Reason: Not specified

thanks 1 user thanked epf for this useful post.
cyracks on 6/28/2020(UTC)
Users browsing this topic
Guest (2)
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.