Implementing audit trail ms sql using stored procedure - sql-server

My application would be like having category and under category, products will be there.
Three types of admin will be there. super admin (more than one admin will be available), product admin (more than one product admin) and user.
Super admin and product admin can add/delete/update product.
User can view that.
Super admin and product admin can change the user permission.
Super admin can add users.
For this I need to add audit trail.
I have referred some sites like
best way to implement an audit trail in sql-server?
http://www.codeproject.com/Articles/21068/Audit-Trail-Generator-for-Microsoft-SQL
http://techbrij.com/audit-trail-microsoft-sql-server-quickly
My understanding from this.
This will write the audit trail whatever (based on our setting) action done to the table
For each table we need to have separate shadow table.
I have planned for the following implementation
I have audit trail types with the predefined message. For example I am having the following tables AuditTrailActions and AuditTrailMessages. My message template would be like the following,
Product {ProductName} [{PersonId}] has been created by {Username}
[{PersonId}]
Whenever the product is added successfully, I will call a stored procedure from there will call audit trail messages table to get the message and replace the necessary tags and update in AuditTrail Table
I will do like the same thing for all the actions.
Will be a good implementation?
If not can anyone suggest good implementation for my need?

Related

How can I know the list of user running Apex code in our org with their respective licence type?

I have been looking for ways to list/access the list of users with with their respective type licenses(Partner or Admin or Community) running/executing apex on our org but have not found anything explaining how I can do that.
Any help to help understand how I can achieve this will be greatly appreciated.
Unclear.
There's some tracking "user X used visualforce page/apex class Y" but Event Monitoring is a paid addon, bought separately or as part of Shield (better field history tracking and encryption). You should be able to experiment with it in your Developer Edition / Trailhead Playground before deciding to buy.
Without that... you'll have to marry few queries together but the results will be so-so.
SELECT Name, UserType, Profile.UserLicense.MasterLabel, Profile.UserLicense.LicenseDefinitionKey
FROM User
WHERE IsActive = true
for license types. This is about "main" user license. Your user can have "feature licenses" (Salesforce Content User, Marketing User, Knowledge User...) that are just checkboxes on user record. And can have permission sets assigned with some managed package licenses for example.
For async jobs (scheduled, queueable, batch, #future...) you should be able to query the AsyncApexJob (keeps logs for 1 week I think) or CronTrigger + CronJobDetail to see scheduled jobs. That'll include dashboard & report runs too though, filter them out using that cronjobdetail
Last but not least you can query who has access (via profile or permission sets) to run class X - but that doesn't mean they actually run it. For that you'd need to query. Some sample queries for that are in SetupEntityAccess documentation.

Dynamics CRM - Add companies that not exists when importing contacts

I'm migrating a customer CRM database to Dynamics CRM. It's about accounts, contacts, and activities. Unfortunately, the previous CRM was not really well used so the data are a bit confused:
While creating a contact, you have a field "Company" that is a "look up" field as we can find in Dynamics. But, if you write something in there and you don't look up for the company entity, the value entered becomes just a value of the field "COMPANY" in the "CONTACT" record.
That's why I have some contacts that are not really associated with companies.
In Dynamics, I'm using the Import Wizard to imports those entities. Is there a way to add the contact's company if it not already exists while importing contacts?
You need to handle this during the Create – by a plugin with a step, or by a workflow. Both works similarly to DB trigger. Plugin is basically .dll written in C#, running in a sandbox, using some of MS libraries. It is registered by external utility. Workflow is something you can do without programming right in the CRM UI. It is easier do deploy, but it has less possibilities. You can find enough information about both online.
I would recommend following process:
Create temporary custom text field on a Contact entity to store account name as a text.
Before the import, in the import file, create a copy of account column with another name.
One account column should be linked to account lookup (parent customer). This is for automatic joining contact and account. The other column is linked to the created field.
Your routine (workflow or plugin) to process this will have following condition to proceed: If account lookup is empty. Then you will create a new account by using information from Contact (mainly account name) and then associate the account and contact (update of the contact record). Optionally erase account text field on the Contact.
At the end, you should deactivate or remove the routine. If you’d use it more often, you need some condition to recognize records are created by import.

CakePHP filter queries by user's business accounts

I'm new to CakePHP 2.4 and trying to understand conceptually if I'm on the right track before I start building the following.
By default, when a User first logs in to his online account, he sees Orders, Invoices, and Documents for ALL ACCOUNTS that he has access to. Using an Account dropdown and the button "Go", he can filter Orders, Invoices, and Documents for only ONE ACCOUNT.
Currently, pre-CakePHP, this is all handled in query logic. The User-Account (N:N) relationship is in the database. Any active Account_Id is stored in the SESSION. What is the CakePHP to do this?
The Model looks like:
User hasAndBelongsToMany Accounts
Account hasMany Orders
Account hasMany Invoices
Account hasMany Documents
1.) Should I code the relationship between Users and Accounts in a Model (hasAndBelongsToMany) or in the ACL/Auth component (User is ARO, Account is ACO)?
2.) To show ALL ACCOUNTS, what is the best way to "query for" this filter and apply it to each Model. Or is that done automatically by the Model?... or by ACL/Auth?
3.) To show ONE ACCOUNT, is storing an Id in the Session still the best approach? ...or should I be thinking about a new set of actions in each of the Orders, Invoices, and Documents Controllers?
I will support you with set of links to CakePHP cookbook which clarifies all your queries:
First of all you should read about linking models.
Next thing is creating correct database and tables in there following CakePHP conventions
Another step is "baking" your models/controllers/ views
After that step all you need to do is just play arround with data you get from your models
To be honest you dont have to code any relations at all if you just correctly create your database with corect foreing key names which Cake will detect and build relations through interactive shell (you will be asked if you want console to create relation for you through cake bake ).
$this->ModelName->find('all')
will give you all data of given ModelName and also all related data,
using
$this->ModelName->recursive=-1
will make your model to retrive only data from ModelName without any related data.
In practice some things will probably work for you out of the box but some of things you will have to simply implement. Hope that helps.

How "Follow" button works in Graph DB

I am using Titan Graph DB. I want to implement "follow" button in my page i.e I a page update something, it should be know to all follower. I dont know how does this follow mechanism work.
In social networking when we follow something we keep getting all updates from that page. How does it work? What is the idea behind implementing this in Graph DB.
Suppose I am following a page XYZ and there happend one update on XYZ. then how does it sends its update info to all followers.
Is it something that it will store update info for all individual
user in graph DB
OR Is it like when a user login it will check all page that it follow
for any new update?
OR something else
The process to trigger the notification has nothing todo with the underlying database you use. This is part of your business logic, how you design your application and how you notify all the listeners about the change.
A graph database will give you the opportunity to store the information about your users and theire tweets, or your sites and the follower in a more natural and semantic way.
In a graph database, you can store your Persons, e.g. John and Doe as Vertices and a relation or edge between them, labeled with follows. In your SQL database, you would store them in a separate table plus a table for your joins to store all the followers.
If you now have a new tweet, you have to join your tables in your SQL table to find all followers to notify. In a graph database, you just have to check the incoming edges on the person who wrote the tweet. Also, in the graph database, you could store the tweet as well, where an extra edge from the person who wrote it goes to the tweet, to have all the necessary informations for your notification at one place, instead of lots of lookups in SQL tables.

Suggestions for creating a multi-blog site in CakePHP with ACL 'memberships'

I've been diving into CakePHP this year and I'm loving it! However, I've just run across a problem that I'm not sure how to handle. My database design is this--
USER can belong to one or more WEBSITE
A WEBSITE can have many USER
So I have a many-to-many relationship which is tracked in MEMBERSHIP
MEMBERSHIP also tracks what group_id the USER has for that WEBSITE.
For example, if user1 joins website3 as an administrator and website5 as a editor, then the MEMBERSHIP table has an entry reflecting both those roles.
Basically my problem is Cake's ACL. In the above-mentioned model, user1's group_id would change depending on which WEBSITE he's selected after logging in. (And he could subsequently change to even more websites within the dashboard by changing the group_id again and again). Cake's ACL appears to only handle 'user belongs to one group' period.
Can I trick the ACL by giving it the group_id from the session every time its changed and then reload the AROs? Would it make more sense to scrap ACL and create my own permissions module?
Any suggestions or ideas to point me in the right direction would be GREATLY appreciated!
i think it will be the best way to create your own permission module.
the reasons are quite simple:
you can modify/extend it in any way YOU want
you will not break any cakePHP specifications

Resources