Topic
  • 11 replies
  • Latest Post - ‏2014-08-06T17:53:05Z by llandale
SystemAdmin
SystemAdmin
3180 Posts

Pinned topic Public View

‏2013-01-09T03:35:16Z |
Hello,

What would be the best way to change all views that have been made public within the database so anyone can modify those views (Delete, etc.) My goal is only to change public views and leave private views alone. Any help would be appreciated.

-Jim
Updated on 2013-01-10T17:53:39Z at 2013-01-10T17:53:39Z by SystemAdmin
  • llandale
    llandale
    3035 Posts

    Re: Public View

    ‏2013-01-09T14:14:07Z  
    "Public"/"Private" settings are inadequate. When you create a view only the creator has modify rights; "Public" provides universal "R", "Private" provides universal "None". It is thus a good idea after creating a view, to right away Manage Views and provide more suitable access (which becomes shown as "Custom").

    To answer your question, the DOORS super-user "Administrator" will need to plow through the views and provide "Everyone else" "RMCD" or "RMCDA" access. That is not hard with a script.

    It seems better to me though to just change the view to have "Inherited" access.

    Better still would be for there to be a set of Project approved views that only the Project admins may modify.

    -Louie
  • SystemAdmin
    SystemAdmin
    3180 Posts

    Re: Public View

    ‏2013-01-09T14:43:24Z  

    Hello,

    I found the below code on the internet and made modifications to it. Does anyone see logic errors? Thank you.

    -Jim
     

    // 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
     
    DB  dbMain      = null
    DBE dbeResults  = null
     
    Buffer buf = create
     
    /*********************************
            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)
    {
            AccessRec ar = null
            int count = 0
            bool def = false
     
            for ar in v do
            {
                    //if no user or group assigned to AR, then must be the default "Everyone else" group
                    uName = username ar
     
            if(null uName) 
                    {
                            uName = "Administrator"
     
                if(getAccessRecord(ar) != "None"){def = true}
                    }
            }
     
            return(def)
    }
     
    /*********************************
            getPublicViews
    *********************************/
    void getPublicViews(string mName, Buffer resBuf)
    {
            Module m = null
            string vn = ""
            string uName = ""
            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))
                    {
                            resBuf += name(m) " has public view \"" vn "\" owned by " uName ".\n"
                            noneFound = false
                            
                            View v = view vn
                            unsetAll (v)    
                            set (v, control | delete, "") // give everyone control permissions
                    }
            }
     
            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)
    }
     
    /*********************************
            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)
     
            dbeResults = text(dbMain, "Results:", "", 600, 150, true)
     
            apply(dbMain, "Run", doRun)
     
            realize(dbMain)
     
            show(dbMain)
    }
     
    /*********************************
            MAIN
    *********************************/
    listPublicViews()
    
    Updated on 2014-01-09T00:46:22Z at 2014-01-09T00:46:22Z by iron-man
  • llandale
    llandale
    3035 Posts

    Re: Public View

    ‏2013-01-09T21:52:00Z  

    Hello,

    I found the below code on the internet and made modifications to it. Does anyone see logic errors? Thank you.

    -Jim
     

    <pre class="javascript dw" data-editor-lang="js" data-pbcklang="javascript" dir="ltr">// 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 DB dbMain = null DBE dbeResults = null Buffer buf = create /********************************* 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) { AccessRec ar = null int count = 0 bool def = false for ar in v do { //if no user or group assigned to AR, then must be the default "Everyone else" group uName = username ar if(null uName) { uName = "Administrator" if(getAccessRecord(ar) != "None"){def = true} } } return(def) } /********************************* getPublicViews *********************************/ void getPublicViews(string mName, Buffer resBuf) { Module m = null string vn = "" string uName = "" 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)) { resBuf += name(m) " has public view \"" vn "\" owned by " uName ".\n" noneFound = false View v = view vn unsetAll (v) set (v, control | delete, "") // give everyone control permissions } } 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) } /********************************* 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) dbeResults = text(dbMain, "Results:", "", 600, 150, true) apply(dbMain, "Run", doRun) realize(dbMain) show(dbMain) } /********************************* MAIN *********************************/ listPublicViews() </pre>

    I believe the rules are; in order of precedence:

    • "Custom" - There is an access-record other than the current user and the default access-records
    • "Private" - the default access-record is "None"
    • "Public" - the default access-record includes "R".


    I assert that the "default" access record has name "Everyone else" in the GUI, and has null name "" using DXL.

    I think that, for purposes of this script, we should ignore "Custom" views and define "Private" as being the default with "none".

    If so then function isPublic() is wrong; reference to the "Administrator" is hopeless, and it should look like:

     

    bool isPublic(View v, string &uName)
    {
        AccessRec ar = null
            bool def = false
     
            for ar in v do
            {
                    //if no user or group assigned to AR, then must be the default "Everyone else" group
                    uName = username ar
                    if(null uName) 
                    {
                            if(getAccessRecord(ar) != "None"){def = true}
                    }
            }
            return(def)
    }
    


    -Louie

     

    Updated on 2014-01-09T00:47:06Z at 2014-01-09T00:47:06Z by iron-man
  • llandale
    llandale
    3035 Posts

    Re: Public View

    ‏2013-01-09T21:56:51Z  
    • llandale
    • ‏2013-01-09T21:52:00Z

    I believe the rules are; in order of precedence:

    • "Custom" - There is an access-record other than the current user and the default access-records
    • "Private" - the default access-record is "None"
    • "Public" - the default access-record includes "R".


    I assert that the "default" access record has name "Everyone else" in the GUI, and has null name "" using DXL.

    I think that, for purposes of this script, we should ignore "Custom" views and define "Private" as being the default with "none".

    If so then function isPublic() is wrong; reference to the "Administrator" is hopeless, and it should look like:

     

    <pre class="javascript dw" data-editor-lang="js" data-pbcklang="javascript" dir="ltr">bool isPublic(View v, string &uName) { AccessRec ar = null bool def = false for ar in v do { //if no user or group assigned to AR, then must be the default "Everyone else" group uName = username ar if(null uName) { if(getAccessRecord(ar) != "None"){def = true} } } return(def) } </pre>


    -Louie

     

    Incidentally, some version of DOORS v7x had a bug where when the Adminsitrator indeed made a view, that an AccessRecord for the "Administrator" was created. This created havok for Admins looking at views since they had no access to the Administrator's privaleged user account. I'm guessing the code you found was written in that version and feebly attempted to accomondate.

    I note that since the Administrator has default RMCDA to EVERYTHING, there is no need nor should never be any AccessRecord named "Administrator". I wonder what it could possibly mean.

    -Louie
  • Tony_Goodman
    Tony_Goodman
    270 Posts

    Re: Public View

    ‏2013-01-10T10:26:31Z  

    Hello,

    I found the below code on the internet and made modifications to it. Does anyone see logic errors? Thank you.

    -Jim
     

    <pre class="javascript dw" data-editor-lang="js" data-pbcklang="javascript" dir="ltr">// 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 DB dbMain = null DBE dbeResults = null Buffer buf = create /********************************* 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) { AccessRec ar = null int count = 0 bool def = false for ar in v do { //if no user or group assigned to AR, then must be the default "Everyone else" group uName = username ar if(null uName) { uName = "Administrator" if(getAccessRecord(ar) != "None"){def = true} } } return(def) } /********************************* getPublicViews *********************************/ void getPublicViews(string mName, Buffer resBuf) { Module m = null string vn = "" string uName = "" 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)) { resBuf += name(m) " has public view \"" vn "\" owned by " uName ".\n" noneFound = false View v = view vn unsetAll (v) set (v, control | delete, "") // give everyone control permissions } } 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) } /********************************* 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) dbeResults = text(dbMain, "Results:", "", 600, 150, true) apply(dbMain, "Run", doRun) realize(dbMain) show(dbMain) } /********************************* MAIN *********************************/ listPublicViews() </pre>

    You broke my script!

    The logic behind the isPublic function is that public views have exactly two access records. One is for READ for Everyone Else, and the other is RMCDA for the owner.
     

    /*********************************  
        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)  
    }
    

     


    Tony Goodman, www.smartdxl.com

     

    Updated on 2014-01-09T00:51:22Z at 2014-01-09T00:51:22Z by iron-man
  • SystemAdmin
    SystemAdmin
    3180 Posts

    Re: Public View

    ‏2013-01-10T17:53:39Z  

    You broke my script!

    The logic behind the isPublic function is that public views have exactly two access records. One is for READ for Everyone Else, and the other is RMCDA for the owner.
     

    <pre class="javascript dw" data-editor-lang="js" data-pbcklang="javascript" dir="ltr">/********************************* 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) } </pre>

     


    Tony Goodman, www.smartdxl.com

     

    if you create the view as the "Administrator" you only have one access record. (Everyone R)

    -Jim
  • Chris Annal
    Chris Annal
    24 Posts

    Re: Public View

    ‏2014-07-28T15:40:56Z  

    You broke my script!

    The logic behind the isPublic function is that public views have exactly two access records. One is for READ for Everyone Else, and the other is RMCDA for the owner.
     

    <pre class="javascript dw" data-editor-lang="js" data-pbcklang="javascript" dir="ltr">/********************************* 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) } </pre>

     


    Tony Goodman, www.smartdxl.com

     

    Hi Tony,

    Your scripts are excellent and I've used many of them for various tasks. I did discover one corner case where this script produces an error. Apparently, if a user created a view and that user is no longer in the database, the script will toss an error at the line

    u = find (uName)

    and later lines in the script that rely on that line. Should their be a break statement for that corner case?

  • llandale
    llandale
    3035 Posts

    Re: Public View

    ‏2014-07-28T20:44:58Z  

    Hi Tony,

    Your scripts are excellent and I've used many of them for various tasks. I did discover one corner case where this script produces an error. Apparently, if a user created a view and that user is no longer in the database, the script will toss an error at the line

    u = find (uName)

    and later lines in the script that rely on that line. Should their be a break statement for that corner case?

    Run the script as the "Administrator".

    Seems to me you'd need to do that anyway, adding your "DB Admins" group to all the views.  And folders modules that are not Inherited.

  • ChrisAnnal
    ChrisAnnal
    64 Posts

    Re: Public View

    ‏2014-07-28T21:15:37Z  
    • llandale
    • ‏2014-07-28T20:44:58Z

    Run the script as the "Administrator".

    Seems to me you'd need to do that anyway, adding your "DB Admins" group to all the views.  And folders modules that are not Inherited.

    You're right about a script that intends to modify the access to a View (if the user who created it didn't bother to make any changes to the default access), However, this script is simply listing those views that fall into that category - so you don't have to be an Administrator to run it.

    In other words, a user named "vCreator" created a Public View named "MyView". The default access to that view is:

    vCreator = RMCDA

    Everyone Else = R

    ...and you have to be an Administrator in order to change that access if user vCreator is no longer in the database.

    What I'm saying is that if user vCreator is no longer in the database, the script fails at the line:

    u = find (uName)

    This is regardless of who runs the script.

  • Chris Annal
    Chris Annal
    24 Posts

    Re: Public View

    ‏2014-08-05T15:14:02Z  

    You're right about a script that intends to modify the access to a View (if the user who created it didn't bother to make any changes to the default access), However, this script is simply listing those views that fall into that category - so you don't have to be an Administrator to run it.

    In other words, a user named "vCreator" created a Public View named "MyView". The default access to that view is:

    vCreator = RMCDA

    Everyone Else = R

    ...and you have to be an Administrator in order to change that access if user vCreator is no longer in the database.

    What I'm saying is that if user vCreator is no longer in the database, the script fails at the line:

    u = find (uName)

    This is regardless of who runs the script.

    I found a workaround that works for my purposes, anyway. I just created a string to catch "uName" instead of looking for a user from the database. Since the email portion is also using a user from the database, I worked around that by hard-coding the email address. It assumes "ViewOwner" is the name of the user without actually verifying it in the database. This avoids the error when a user has been disabled or purged from the database...

    *********************************/
    bool isPublic(View v, string &uName, string &uEmail)
    {
     AccessRec ar = null
     string ViewOwner = null //added to avoid error in "u.name" if user is no longer in database.
     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 "" != "")
        {
         ViewOwner = uName "" //changed from "u.name" to string "ViewOwner" since users no longer in DB caused errors
        }

        if (!null u)
        {
         uEmail = ViewOwner"@yourcompany.com" //modified to allow for users no longer in database (error now caught by Outlook)
        }
       }
      }

      return(def && !null u)
     }

     return(false)
    }

  • llandale
    llandale
    3035 Posts

    Re: Public View

    ‏2014-08-06T17:53:05Z  

    You're right about a script that intends to modify the access to a View (if the user who created it didn't bother to make any changes to the default access), However, this script is simply listing those views that fall into that category - so you don't have to be an Administrator to run it.

    In other words, a user named "vCreator" created a Public View named "MyView". The default access to that view is:

    vCreator = RMCDA

    Everyone Else = R

    ...and you have to be an Administrator in order to change that access if user vCreator is no longer in the database.

    What I'm saying is that if user vCreator is no longer in the database, the script fails at the line:

    u = find (uName)

    This is regardless of who runs the script.

    I check for the existence first with one or both of these:

    bool existsGroup(string name)

    bool existsUser(string name)

    You can also trap the error:

    string Name = "zz"
    noError()
    User u = find(Name)
    string ErrMess = lastError()
    if (!null ErrMess) //
    then print (null u) "\t" Name "\tNo such user\t[" ErrMess "]"
    else
    {} 

    Curious, "u" comes back non-null so you need ErrMess.

    -Louie

    Updated on 2014-08-06T17:56:23Z at 2014-08-06T17:56:23Z by llandale