private string CreateGrantLine(GrantPermissions.PermSet permissionSet, string username, bool isReadonly) { StringBuilder stringBuilder = new StringBuilder(); if (permissionSet.Permissions.Length == 0) { return(string.Empty); } stringBuilder.Append("GRANT "); bool flag = false; if (this.HasPermission(Permission.Select, permissionSet)) { if (flag) { stringBuilder.Append(","); } flag = true; stringBuilder.Append("SELECT"); } if (!isReadonly) { if (this.HasPermission(Permission.Insert, permissionSet)) { if (flag) { stringBuilder.Append(","); } flag = true; stringBuilder.Append("INSERT"); } if (this.HasPermission(Permission.Update, permissionSet)) { if (flag) { stringBuilder.Append(","); } flag = true; stringBuilder.Append("UPDATE"); } if (this.HasPermission(Permission.Delete, permissionSet)) { if (flag) { stringBuilder.Append(","); } flag = true; stringBuilder.Append("DELETE"); } } if (!flag) { return(string.Empty); } stringBuilder.Append(" ON ").Append(permissionSet.Table.Name).Append(" TO ").Append(username).Append(";").Append(Environment.NewLine); return(stringBuilder.ToString()); }
private bool HasPermission(Permission perm, GrantPermissions.PermSet permissionSet) { foreach (Permission permission in permissionSet.Permissions) { if (permission == perm) { return(true); } } return(false); }