'build lists of what the user can read / write / create
quirks:
read_only => Not in Search
in_create => Not in create'

def build_permissions(self):

    self.build_doctype_map()
    self.build_perm_map()
    user_shared = frappe.share.get_shared_doctypes()
    no_list_view_link = []
    active_modules = (frappe.get_active_modules() or [])
    for dt in self.doctype_map:
        dtp = self.doctype_map[dt]
        p = self.perm_map.get(dt, {})
        if ((not p.get(u'read')) and (dt in user_shared)):
            p[u'read'] = 1
        if (not dtp.get(u'istable')):
            if (p.get(u'create') and (not dtp.get(u'issingle'))):
                if dtp.get(u'in_create'):
                    self.in_create.append(dt)
                else:
                    self.can_create.append(dt)
            elif p.get(u'write'):
                self.can_write.append(dt)
            elif p.get(u'read'):
                if dtp.get(u'read_only'):
                    self.all_read.append(dt)
                    no_list_view_link.append(dt)
                else:
                    self.can_read.append(dt)
        if p.get(u'cancel'):
            self.can_cancel.append(dt)
        if p.get(u'delete'):
            self.can_delete.append(dt)
        if (p.get(u'read') or p.get(u'write') or p.get(u'create')):
            if p.get(u'report'):
                self.can_get_report.append(dt)
            for key in (u'import', u'export', u'print', u'email', u'set_user_permissions'):
                if p.get(key):
                    getattr(self, (u'can_' + key)).append(dt)
            if (not dtp.get(u'istable')):
                if ((not dtp.get(u'issingle')) and (not dtp.get(u'read_only'))):
                    self.can_search.append(dt)
                if (dtp.get(u'module') not in self.allow_modules):
                    if (active_modules and (dtp.get(u'module') not in active_modules)):
                        pass
                    else:
                        self.allow_modules.append(dtp.get(u'module'))
    self.can_write += self.can_create
    self.can_write += self.in_create
    self.can_read += self.can_write
    self.shared = frappe.db.sql_list(u'select    distinct    share_doctype    from    `tabDocShare`\n DCTB  DCTB  DCTB where    `user`=%s    and    `read`=1', self.name)
    self.can_read = list(set((self.can_read + self.shared)))
    self.all_read += self.can_read
    for dt in no_list_view_link:
        if (dt in self.can_read):
            self.can_read.remove(dt)
    if (u'System    Manager' in self.get_roles()):
        self.can_import = filter((lambda d: (d in self.can_create)), frappe.db.sql_list(u'select    name    from    `tabDocType`    where    allow_import    =    1'))
