If the user creates a web part page in SharePoint and then adds one of my custom web parts to it, I would like to completely hide a web part depending on a particular users permissions.
For example, I have a reporting web part some users have access to reports and some don't, I don't even want some users to know that reports exist.
I have a custom security API that use to determine if security is allowed or denied, I would love to say:
protected override void OnInit(EventArgs e) {
bool allowed = PermissionServices.IsAllowed("Reports");
if (!allowed) {
this.Hide();
// Where 'this' is the web part
}
base.OnInit(e);
}
I don't control the page code so it has to be in the web part.