Find Public Views

Public views are a menace. They clutter up the drop down view list and can only be deleted by the owner or the Adminsitrator. This script demonstrates how you can identify public views.

Public views can be identified by looking at thier access records. They will have exactly two access records, one will be RMCDA for the view owner, and the other will be read-only for everyone else.

This example checks modules in the current folder and gives you the option to send an email to the owners asking that they make their views private.

// List Public Views

/*
	Lists public views found in modules.

	Reports public views found in modules together with the owner
	and their email address.

	24-MAY-2011		Tony Goodman
*/

pragma runLim, 0

string ccEmail = "yourname@yourdomain.com"

string MESSAGE = "Dear DOORS User,

This \"Public View\" is owned by you. Public views are reserved for project/department-wide purposes and should only be created following agreement with the Requirements Manager. Please can you change the view to a \"Private View\" as soon as possible. This will not impact the view contents in any way, but will mean that only you can see the view.
We need to take this disciplined approach as too many views clutter up the DOORS module and can cause confusion. Unfortunately DOORS defaults new views to public views and this cannot be re-configured, so whenever you create a new view please remember to set it to a private view.

To make a view private:

1. open the module
2. select Views > Manage Views...
3. select the view in the list
4. open the Access tab
5. select Everyone else
6. click on Edit..
7. select None
8. click OK
9. click OK

Many thanks.

Your Name

"

DB  dbMain      = null
DBE dbeResults  = null
DBE dbeSendEmails = null
DBE dbeMessage = null

Buffer buf = create

bool sendEmails = false

targetAddresses = createString
ccAddresses = createString

User u = find()
string myEmail = u.email

/*********************************
	getAccessRecord
*********************************/
string getAccessRecord(AccessRec ar)
{
	string r = ((read ar)    ? "R" : "")
	string m = ((modify ar)  ? "M" : "")
	string c = ((create ar)  ? "C" : "")
	string d = ((delete ar)  ? "D" : "")
	string a = ((control ar) ? "A" : "")

	string accessStr =  r m c d a ""

	if (null accessStr)
	{
		accessStr = "None"
	}

	return(accessStr)
}

/*********************************
	isPublic
*********************************/
bool isPublic(View v, string &uName, string &uEmail)
{
	AccessRec ar = null
	User u = null
	int count = 0
	bool def = false

	for ar in v do
	{
		count++
	}

	if (count == 2)
	{
		for ar in v do
		{
			if (getAccessRecord(ar) == "R")
			{
				def = true
			}
			else if (getAccessRecord(ar) == "RMCDA")
			{
				uName = username ar

				if (uName "" != "")
				{
					u = find(uName)
				}

				if (!null u)
				{
					uEmail = u.email
				}
			}
		}

		return(def && !null u)
	}

	return(false)
}

/*********************************
	getPublicViews
*********************************/
void getPublicViews(string mName, Buffer resBuf)
{
	Module m = null
	string vn = ""
	string uName = ""
	string uEmail = ""
	string res = ""
	string msg = ""
	bool noneFound = true

	m = read(mName, false)

	if (null m)
	{
		resBuf += "ERROR: Failed to open module " mName ".\n"
		return
	}

	(current ModuleRef__) = m

	for vn in views m do
	{
		if (isPublic(view vn, uName, uEmail))
		{
			if (sendEmails)
			{
				if (uEmail "" != "")
				{
					delete(targetAddresses)
					targetAddresses = createString
					put(targetAddresses, uEmail, uEmail)
					delete(ccAddresses)
					ccAddresses = createString
					put(ccAddresses, ccEmail, ccEmail)

					res = sendEMailMessage(myEmail, targetAddresses, ccAddresses, "Public View \"" vn "\" in DOORS module " name(m), MESSAGE)

					if (res "" == "")
					{
						msg = "An Email has been sent to " uEmail ""
					}
					else
					{
						msg = "Error sending email to " uEmail "." res
					}
				}
				else
				{
					msg = "Could not send Email - Email address unknown!"
				}
			}
			else
			{
				msg = uEmail
			}

			resBuf += name(m) " has public view \"" vn "\" owned by " uName " (" msg ").\n"
			noneFound = false
		}
	}

	if (noneFound)
	{
		resBuf += name(m) " does not have any public views.\n"
	}

	close(m)
}

/*********************************
	doRun
*********************************/
void doRun(DB db)
{
	Item i
	setempty(buf)
	int pCount = 0
	int pLimit = 0

	for i in current Folder do
	{
		if (type(i) != "Formal") continue

		pLimit++
	}

	if (pLimit == 0)
	{
		buf += "No modules found.\n"
	}
	else
	{
		//buf += pLimit " modules found.\n"

		if (!confirm("You are about to search for public views in " pLimit " modules\nAre you sure you want to continue?"))
		{
			buf += "Command aborted by user.\n"
		}
		else
		{
			progressStart(dbMain, "Checking modules", "Checking modules", pLimit)

			for i in current Folder do
			{
				if (type(i) != "Formal") continue

				pCount++
				progressRange("Checking module " pCount " of " pLimit ".", pCount, pLimit)

				getPublicViews(fullName(i), buf)
			}

			progressStop()
		}
	}

	set(dbeResults, buf)
}

/*********************************
	toggleEmails
*********************************/
void toggleEmails(DBE dbe)
{
	sendEmails = get(dbeSendEmails)

	if (sendEmails)
	{
		active(dbeMessage)
	}
	else
	{
		inactive(dbeMessage)
	}
}

/*********************************
	listPublicViews
*********************************/
void listPublicViews()
{
	dbMain = create(dbExplorer, "List Public Views", styleCentered|styleFloating)

	label(dbMain, "This utility allows you identify public views, and their owners, contained in modules below the current folder.")

	field(dbMain, "Folder:", fullName(current Folder), 50, true)

	dbeSendEmails = toggle(dbMain, "Send Emails to View Owners", sendEmails)

	dbeMessage = text(dbMain, "Message:", MESSAGE, 600, 100, false)

	dbeResults = text(dbMain, "Results:", "", 600, 150, true)

	apply(dbMain, "Run", doRun)

	realize(dbMain)

	set(dbeSendEmails, toggleEmails)
	inactive(dbeMessage)

	show(dbMain)
}

/*********************************
	MAIN
*********************************/
listPublicViews()