Programatically delete a user in Orchard - orchardcms

I am not an Orchard guru. I am a desktop apps guy with a lot of responsibilities that inherited a big blob of Orchard code and have been tasked with a few maintenance tools. I have tried googling the interwebs to no avail, so I am turning to Stack in a desperate attempt that someone has the easy button...
Basically (and this is an over-simplified use case) - we frequently have users that signup with a mistyped email address or forget their account information within a day or signup again but fat finger the password and then signup a third time, etc...
I have a maintenance console that allows an administrator to 'locate' data (in our own non-orchard sql tables) associated with the first or second accounts (in my example) and re-associate that data with the third 'current/correct' account.
At the conclusion of this re-mapping, I would like to programmatically clean-up (read: delete) the Orchard logins for the first two accounts which are now officially kruft.
I found some information on Stack here that talks about Orchard user accounts:
Users are content types and Orchard creates content items for each
user. When you create a new user Orchard adds records to
xxx_Orchard_Users_UserPartRecord,
xxx_Orchard_Framework_ContentItemRecord,
xxx_Orchard_Framework_ContentItemVersionRecord and
xxx_Orchard_Roles_UserRolesPartRecord if you linked any roles to the
user.
The xxx_Orchard_Framework_ContentItemVersionRecord table keeps track
of the version number and whether or not a content item is published
or not and which version of the published content item is the latest.
When you delete the user Orchard does not delete the records from the
tables, but simply creates a new version record and sets Published and
Latest columns to 0 for the new version and the old version. Because
there is no published and latest version the content item does not
show up on the list of users.
I understand this conceptually, but I can't believe to delete a user that I would be required to delete the records from each of these 'private' tables in orchard. Instead, I expect there is a class/method/technique for deleting the Content Type or Part or Record or whatever (I'm still haven't quite got Orchard object naming straight in my head).
Can anyone share an example of deleting a user in code (by Id or Username or Email)? Or point me at the relevant documentation? I'm fumbling around like a fish outta water here...
As always, thanks in advance!

So as you say, within Orchard most deletes from the UI are soft deletes, keeping all the data and setting a flag in the database to say this guy is deleted. To do this programmatically, where _contentManager is an instance of IContentManager.
var userItem = _contentManager.Get<IUser>(userId);
_contentManager.Remove(userItem);
To do a hard delete, which will delete the item record, all item version records and all content part records (titlepart, userpart etc.)
var userItem = _contentManager.Get<IUser>(userId);
_contentManager.Destroy(userItem);
This was added to orchard in version 1.9.

Related

SharePoint 2013 people picker retrieves user's old information

I have imported users from AD and keep syncing them for a while. Today two of users' display names have been changed on AD and SharePoint synced them correctly. Just to be sure, I checked users from User Profile Service App which looks OK. New names are appearing correctly.
Yet when I try to add a list item and select user from people picker, I get old user info. This also happens when I try to insert a list item programmatically.
Tried to delete users from SharePoint, however I still get same old users. Do you have any idea for solving this situation?
Thanks in advance.
I found the solution. There was an another User Profile Service Application which was not used and not properly configured. Weird point is, that malconfigured app was not listed on service applications. I found it by using Get-SPServiceApplication cmdlet and removed it. After removal, did a full synchronization and voila! Now I can get current information.
This is may be because entry in SharePoint's hidden user-list - User Information List.
Browse to this list - http://{SiteCollectionURL}/_catalogs/users/detail.aspx
Check for the display name of the users you have updated. If you see old user name instead of new/updated, delete these users from this list.
After this ask user to login to the same site again.

You don't have sufficient privileges to open lookup dialog box error in CRM Online 2016

I have exported a solution from one of my existing CRM Online instance, and imported to another new instance which is also CRM Online 2016.
The solution contains customized Opportunity entity (forms, views, fields, processes, etc), and a custom Security role.
The solution contains one custom field "Follow up Contact" which is of lookup type and referencing to Users entity.
After importing the solution, I have assigned one of the user to the custom security role in new instance.
Now, when I try to create a new opportunity, and try selecting "Follow up Contact", I am seeing no user in the list, whereas the associated view is expected to display at least 5 users. Also, when I try clicking on "Look for more records", I get following error -
"You do not have sufficient privileges to open this Lookup dialog box."
Whereas, users with same security role in the source solution can see the items in the "Follow up Contact" dropdown, and also that "Look for more records", work fine for them.
Any idea what could be the possible reason? Are there any changes in terms of security roles in latest upgrade of CRM Online?
Well strange things do happen!!
I opened the form in designer mode.. disabled the execution of the particular method which contains scripts for setting default value to the lookup control.
Published the solution.
Then again, enabled the script execution...
and to my surprise, the lookup field started working...
Just had this problem and here is what worked for us.
We had a custom entity that was related to the out-of-the-box Account entity. We had 3 lookups on that custom entity to Account. Even with System Administrator role, none of our users could get any records to return from the lookup search and we got the error message specified in the title.
We ended up deleting ONE of the lookup fields (picked the one with least dependencies). We added that field and its dependencies back in. It was annoying manual process, but after this all THREE of our lookup fields were fixed.
I'm guessing the Account-Custom Entity relationship XML behind the scenes was corrupted somehow, and deleting/recreating cleaned it up.

How to change a default name of the folder that CRM creates to Sharepoint

I'm completely new to Sharepoint so keep that in mind when answering or assuming things.
Anyways, we have a CRM 2015 Online Update 1 and Sharepoint Online and those are integrated (not by me). Now when an end-user goes to Account -> Documents the CRM will automatically ask if the user wants to create a folder to Sharepoint. That's fine, but naming convention seems to be "AccountName_AccountGuid". We would like to change that to "AccountName_OurOwnID" where OurOwnID is a custom field in CRM that is unique for every account.
So my question is how would one do this?
EDIT: All I can think of now is to create a plugin that'll be launched when ever a sharepointdocumentlocation entity is created and basically create a new folder with wanted name and then delete the original folder in Sharepoint and then connect the new folder with sharepointdocumentlocation.
Sub-question: Is there a way to tell CRM to stop asking if the user wants to create a new folder? In my case it's unwanted feature but since it is there at least we should make sure that names of the folders will be ok.
The folder name with the guid is default behavior which cannot be altered.
If you want to develop a plugin, look at this post: https://crmconsultancy.wordpress.com/2011/10/27/crm-2011-integration-with-sharepoint-custom-document-management/
Keep in mind, if you want to create objects in SharePoint from CRM online you have two options:
Add the SharePoint.Client assembly with ILMerge. Officialy this is not supported.
Or use the rest endpoint of SharePoint. This is an interesting post to read: https://bingsoft.wordpress.com/2013/06/19/crm-online-to-sharepoint-online-integration-using-rest-and-adfs/

Restricting Views of users on Sharepoint lists

I am developing a sharepoint 2010 project.
I want to restrict users view on lists based on their identity. (e.g. the branch of organization they work in, but in fact the ristrictions can be more complicated).
What solutions do you recommend?
With out of the box features this is not possible. You can go to great lengths to remove the list's view selectors and other navigational elements that let people cruise around a the schema and metadata for a list but it is not a security mechanism.
If a user has read permissions to an item, they'll have read access to all the fields of that item.
There is an outside chance that it you disabled all RPC mechanisms, SOAP, RESTful web services, Client Object Model and the office clients that you might be able to claim this as a security mechanism. If you don't there will always be a way around your "security" scheme.
This feature can't be implemented by SharePoint by now and I think neither for the next version
You can use a third part tool to achieve it, such as BoostSolutions' Column/View Permission or LightningTools' DeliverPoint
BTW, I work for BoostSolutions and I mentioned our own product because it works for your issue. Hope it helps :)
create sharepoint groups based upon your requirement or diffrent type of user base and accordingly give them rights may be item level or on complete list
and while doing these things just go through the following posts
http://blogs.gartner.com/neil_macdonald/2009/02/25/sharepoint-security-best-practices/
http://weblogs.asp.net/erobillard/archive/2008/09/11/sharepoint-security-hard-limits-and-recommended-practices.aspx
Not 100% sure on SharePoint 2010, but definitley for SharePoint 2007, there is not a way to do this, especially if the views are corresponding to security requirements on the columns users are able to see.
One way to work around this is have the list be not accessible by users, and then have code logic allow for access to the data creating the different "views" on the data in something like a Web Part. The downsides to this is search becomes an issue (since the data is hidden) and having multiple "views" of the data (if necessary) is also another item to work through.
I know its a very old question but posting it as it might help someone.
There is an work around to do it as described here
I find it easier, if possible, to create the view and lock it with the filters on the list settings page.
For example, I have a list of employees that includes their employee IDs. I use that list on other pages to gather data in other webparts. So I filter the employee list to [ME]. So the data is available to the page needing it to filter others and they cannot see anything else.
Now, what about the person who needs to manage that page? I create a view, call it HR. That view can see everything. Then I export that webpart with that list view on it through the designer. I then delete the HR view from the employee list.
This leaves no way for anyone to switch views and see everything again. I create a webpart page for the person who manages it, and I upload that webpart and set the view of the webpart to HR. In the end, I have a page that I lock down instead of trying to lock down views or list permissions separately.
Would you be able to have two lists that are joined. One that all users have access to and another that only certain people have access to, and then join them? Then maybe the people that don't have access to the other table it doesn't pull the information? Not sure, but I'll try that out later today.

How can I programmatically determine the creator of a Domino database?

I'm using the built-in Domain Catalog database to list all the databases on a particular Domino server. I'm creating a custom view to show certain information about each database. What I'd like to have is a column that displays the creator of each database. However, if the Domain Catalog is keeping track of this information, I can't find it.
Is there a field in the Domain Catalog that provides this information that I just haven't been able to find? Is there some other way I might find this information and get it into this view? #DBlookup and related functions don't work in column formulas.
That information is not stored in the catalog, and is probably not stored in the database either (It's not shown on any of the property tabs).
You would probably need to get/write a server add-in to monitor database creation and store that data somewhere. Then you'd need to account for databases created by adminp/replication - your add-in might pick them up as having been created by a server.
This question was also asked in the R4/R5 forums in 1998 and received no answer.
Interesting question. There is no such attribute for database, but you can dig for some clues.
New databases: use NotesNoteCollection and look for some specific design element (icon, for example) and look for first element in $UpdatedBy field.
New copies/from templates: above mentioned method won't work. It will return info from original/template, not current database. In this case, try using Created property of DB and check user footprints after that date - in ACL log (he probably altered ACL immediately after copy), new design elements (probably made new view, folder, agent...) or profile documents.
What Frantisek said. Looking in the log archive (ugh!) may tell you who deployed it, but in a well run environment that won't be who developed it. A list of $UpdatedBy(0) for all design notes should give you a good idea. The catch will be that it mayl be people who left the company years ago. : )

Resources