/// <summary> /// Constructor to initialize a new comment based on its minimal required inputs /// Other fields like the comment id and dates are initialized based on those inputs. /// </summary> /// <param name="docid">id of the document to which the comment is attached</param> /// <param name="message">textual content of the comment</param> /// <param name="user">principal of the author of the comment</param> /// <param name="replyto">optional id of the parent comment, if this is a reply</param> public Comment(string docid, string message, CCPrincipal user, string replyto) { creation = Dat.ToUtc(DateTime.Now); commentid = $"{docid}|{Str.Md5(user.UserId + creation.ToBinary())}"; this.docid = docid; this.message = message; userid = user.UserId; username = user.FullName; if (Str.IsEmpty(username)) { username = user.Name; } modified = creation; likes = new ListStr(); likedByUser = false; this.replyto = replyto; deleted = false; }
public static bool GetUserRightsAsSqlStr(string userNameOrId, string domainName, SecuritySyntax securitySyntax, out CCPrincipal principal, out string userRights) { userRights = null; principal = CC.Current.GetPrincipalAny(userNameOrId, domainName); if (principal == null) { Sys.LogError($"Cannot load user with Id or Name [{userNameOrId}] in domain [{domainName}]"); return(false); } long pid = CC.Current.NativeDomains.GetPrincipalByUserId(principal.UserId); if (pid == 0) { Sys.LogError($"Cannot get principal ID from native domains , user name [{principal.Name}]"); return(false); } if (securitySyntax == SecuritySyntax.Engine) { userRights = RightsAsSqlStrXb(principal.UserId, new ListStr(), new ListStr()); } else if (securitySyntax == SecuritySyntax.Legacy) { int flags = NativeDomains.UR_USE_CACHE | NativeDomains.UR_DO_USER_LSTSTR | NativeDomains.UR_DO_USER_SQLSTR; if (!CC.Current.NativeDomains.CalculateUserRightsWithCache(pid, null, null, flags, out ListStr user_list, out ListStr field_list, out string user_rights_sql, out string xfield_parts, out string fingerprint)) { Sys.LogError($"Cannot calculate user rights from native domains for user name [{principal.Name}]"); return(false); } userRights = RightsAsSqlStr(user_rights_sql); } if (userRights == null) { Sys.LogError($"Cannot build SQL rights for user name [{principal.Name}]"); return(false); } return(true); }