MonoX support board

Start the conversation, ask questions and share tips and solutions with fellow developers.

Non-registered users can only browse through our support boards. Please register now if you want to post your questions. It takes a second and it is completely free. Alternatively, you can log in without registration using your credentials at major sites such as Google, Microsoft Live, OpenId, Facebook, LinkedIn or Yahoo.

Uses PrivacyEditor(PrivacyManager) for fields in extended MonoX profile (Closed) (Mono Support )

Viewed 52517 time(s), 8 post(s) 12/1/2011 4:48:58 PMby DenisMaltsev
DenisMaltsev

DenisMaltsev

12/2/2011 8:10:35 AM
Hi,

I'am extend MonoX profile based on this post:
http://www.mono-software.com/blog/post/Mono/98/How-to-Extend-MonoX-and-ASP-NET-Profile/

I add several(about 10) custom fields(gender, height, education etc.).

Now I want to add ability to manipulate privacy for these fields (but not for all):
Question 1: How can I do this? Should I use PrivacyEditor or PrivacyManager?
Question 2: How does PrivacyEditor and PrivacyManager is working?


At first,
I try to use PrivacyManager in following way
control markup(*.ascx):
<MonoX:PrivacyManager ID="uxPrivacyManager" runat="server" ImageButtonCssClass="privacy-button"
    CssClass="privacy-content"/>

code-behind:
privacyManager.UserId = SecurityUtility.GetUserId();
privacyManager.ObjectTypeFullName = typeof(MainContentTemplate).FullName;
privacyManager.PrivacyButtonImageUrl = Paths.App_Themes.img.privacy_icon_png;
privacyManager.PrivacyButtonHoverImageUrl = Paths.App_Themes.img.privacy_icon_hover_png;
privacyManager.Visible = !IsPreviewMode;
....
privacyManager.CurrentDataManager = DataManagerMain;

After that I look into my page and see PrivacyEditor for all my fields.

For example,
Question 3: How can I catch event changing privacy for some fields?
I not found any event for this.

At second,
I try use only PrivacyEditor
control markup:
<monox:PrivacyEditor id="privacyEditor" runat="server" CssClass="privacy-content"></monox:PrivacyEditor>
code-behind:
UserProfileRepository instance = UserProfileRepository.GetInstance();
privacyEditor.UserId = SecurityUtility.GetUserId();
privacyEditor.ObjectTypeFullName = typeof(MainContentTemplate).FullName;
privacyEditor.FieldName = "Gender";
privacyEditor.PrivacyLevels = instance.GetPrivacyLevelIds(privacyEditor.UserId, privacyEditor.ObjectTypeFullName, privacyEditor.FieldName);
 
privacyEditor.ConfirmPrivacy += privacyEditor_ConfirmPrivacy;
....
 void privacyEditor_ConfirmPrivacy(object sender, MonoSoftware.Core.CancelEventArgs<Guid[]> e)
        {
            PrivacyEditorEditTemplate privacyEditorEditTemplate = (PrivacyEditorEditTemplate)sender;
            UserProfileRepository instance = UserProfileRepository.GetInstance();
            instance.UpdatePrivacyLevelDefinitions(privacyEditorEditTemplate.UserId, privacyEditorEditTemplate.ObjectTypeFullName, privacyEditorEditTemplate.FieldName, e.Value);           
        }

Question 4: When ConfirmPrivacy event occurs? I didn't get code inside my event handler

And last my question:
Question 5: How privacy information store in database?
I look into MonoX database and find table PrivacyLevelDefinition I suppose that this table uses for store privacy information. Also I found row with information about privacy of my field "Gender". I think this row was insert after exucuting this line:
privacyEditor.PrivacyLevels = instance.GetPrivacyLevelIds(privacyEditor.UserId, privacyEditor.ObjectTypeFullName, privacyEditor.FieldName);

P.S. Thank you for your help and any information about my questions.

Best regards,
Denis.
This content has not been rated yet. 
39 Reputation 4 Total posts
khorvat

khorvat

12/2/2011 8:44:52 AM
Hi,

Question 1: How can I do this? Should I use PrivacyEditor or PrivacyManager?
You should use the PrivacyManager so you can easily implement this functionality.

Question 2: How does PrivacyEditor and PrivacyManager is working?
We will provide you with an answer soon

Question 3: How can I catch event changing privacy for some fields?
You will have to attach to a PrivacyManager event called PrivacyBindingCreating or PrivacyBindingCreated, there you will have an access to a PrivacyManagerBinding which has reference to ControlPrivacyEditor which has an event that you need and it is called ConfirmPrivacy.

Question 4: When ConfirmPrivacy event occurs? I didn't get code inside my event handler
It occurs when user clicks on the radio button item in the Privacy pop-up

We will provide you with more detailed guidelines soon.

BTW: Do you have a Priority Support and MonoX Source code package ?

Regards
This content has not been rated yet. 
15993 Reputation 2214 Total posts
DenisMaltsev

DenisMaltsev

12/2/2011 9:53:22 AM
Hi Kristijan,

Thank you for you answers and good advices.
I will try to use you advices.
And waiting more detailed guidelines.

"Do you have a Priority Support and MonoX Source code package ?"
No, I haven't.

Best regards,
Denis.
This content has not been rated yet. 
39 Reputation 4 Total posts
imarusic

imarusic

12/2/2011 5:12:43 PM
Hi,

as Kristijan suggested, you need to use PrivacyManager and set it's CurrentDataManager to your DataManager. An example:

//OnInit
dataManagerMain.DataBindings.Add(GPSLocation,
null, prevGPSLocation, null, "GPSLocation");
    dataManagerMain.DataBindings.Add(Hometown, null, prevHometown, null, "Hometown");


//OnInit         
privacyManager.CurrentDataManager = dataManager;
privacyManager.DataBind();

After this step privacy icon should be visible for both additional fields. In order to to disable PrivacyEditor for your custom fields you need to attach on PrivacyManager's PrivacyBindingCreating event:

//OnInit           
privacyManager.PrivacyBindingCreating += new EventHandler<MonoSoftware.Core.CancelEventArgs<PrivacyManagerBinding>>(privacyManager_PrivacyBindingCreating);

You can create an array which will hold values for the fields that should not have the privacy editor:

private static readonly string[] _nonPrivacyFields = new string[] { YoutProfileFields.HomeTown.Name  };
   private string[] NonPrivacyFields
   {
       get { return _nonPrivacyFields; }
   }

and do the rest in privacyManager_PrivacyBindingCreating method:

void privacyManager_PrivacyBindingCreating(object sender, MonoSoftware.Core.CancelEventArgs<PrivacyManagerBinding> e)
       {
           e.Cancel = NonPrivacyFields.Contains(e.Value.FieldName);
       }

Code which you've provided is fine:

privacyManager.UserId = SecurityUtility.GetUserId();
privacyManager.ObjectTypeFullName = typeof(MainContentTemplate).FullName;
privacyManager.PrivacyButtonImageUrl = Paths.App_Themes.img.privacy_icon_png;
privacyManager.PrivacyButtonHoverImageUrl = Paths.App_Themes.img.privacy_icon_hover_png;
privacyManager.Visible = !IsPreviewMode;
privacyManager.CurrentDataManager = DataManagerMain;


You are right regarding the PrivacyLevelDefinitions table, all the privacy definitions are stored in that table. Privacy is saved for each user and there are also ObjectName and FieldName columns which represents the key and PrivacyLevelId which represents the value.

Let us know about your progress if this helped you.

Regards


This content has not been rated yet. 
3016 Reputation 428 Total posts
DenisMaltsev

DenisMaltsev

12/5/2011 12:09:05 PM
Hi,
when I use code that you provide above I get error related to inserting data to database. Please see attachment.
This error occurs after Page_Load event. I can't catch this error in my code for this reason I can't give for you a more detailed description. I not have any code that insert data into aspnet_Users table.
What do you think it is possible that this error related to PrivacyManager?

Maybe reason of this error is PostBack which again initialize PrivacyManager. First time PrivacyManager initialized when I open my page, and second when I click Save button(Postback occurs).

Best regards,
Denis.
This content has not been rated yet. 
39 Reputation 4 Total posts
imarusic

imarusic

12/5/2011 11:51:15 AM
Hi,

you can always check the MonoX log file: '~\MonoX\ApplicationData\Logs\[yyyy-mm-dd]_MonoX.log'.

Yes, it might be the problem with postback, can you please try to set PrivacyManager only when page loads fo the first time and let us know if it works.

Regards.
This content has not been rated yet. 
3016 Reputation 428 Total posts
khorvat

khorvat

12/5/2011 4:22:08 PM
Hi,

one more thing that I had noticed from the error screenshot, this error is related to UserId database constraint and it seems to me that you are trying to use this functionality (saving data to database) when user isn't logged into a MonoX CMS. So you will get the Guid.Empty on this line privacyManager.UserId = SecurityUtility.GetUserId(); and then you will get the exception you have. 

Can you please confirm if this is your scenario ?

Regards
This content has not been rated yet. 
15993 Reputation 2214 Total posts
DenisMaltsev

DenisMaltsev

12/5/2011 4:28:46 PM
Hi Ivan and Kristijan,

thanks you for you quik help. Finally PrivacyManager is works. Regarding SQL exception this is my stupid mistake:
this line:
privacyManager.UserId = SecurityUtility.GetUserId();
should be placed before DataBind() method of PrivacyManager.

SQL Error I receive for reason privacyManager.UserId == Guid.Empty

Best regards,
Denis.
This content has not been rated yet. 
39 Reputation 4 Total posts