Esempio n. 1
0
def isAllowedToWriteObject(user, servico, registry_id, nomeobj=""):
    perm_id = "%s/%s/%s" % (servico, registry_id, nomeobj)
    
    _perm = permission.model.Permission().retrieve(perm_id)
         
    if not _perm: 
        if servico in ["evaluation", "videoaula", "quiz", "question"]:
            # "acesso_privado"  
            return (isUserOrOwner(user, registry_id))       
        else:
            # "acesso_comunidade"            
            return (isUserOrMember(user, registry_id))
                    
    if _perm.escopo_W == "acesso_privado":
        return (user == _perm.owner or isUserOrOwner(user, registry_id))  
          
    if _perm.escopo_W == "acesso_grupos":
        # permite acesso ao dono do objeto e ao dono/admin da comunidade
        if (user == _perm.owner or isUserOrOwner(user, registry_id)):
            return True
        
        # permite acesso aos participantes dos grupos selecionados
        _reg = core.model.Registry().retrieve(registry_id)
        if not _reg:
            return False
        for group in _perm.grupos_W:
            if user in _reg.getGroups[group]:
                return True
        return False
     
    if _perm.escopo_W == "acesso_comunidade":
        # aqui pode ser isUserorMember pois não deixamos amigos escreverem em objetos de amigos
        return (isUserOrMember(user, registry_id))
    
    return False
Esempio n. 2
0
    def get(self, registry_id):
        user = self.get_current_user()
        page = int(self.get_argument("page","1"))

        bookm_count = model.Bookmarks.countBookmarksByRegistryId(registry_id)
        # Se forem todas as tags da página mostrada
        #(bookmarks, tags_list) = model.Bookmarks.listBookmarks(user, registry_id, page, NUM_MAX_FAVORITOS, all_tags=False)
        # Se forem todas as tags
        bookmarks = model.Bookmarks.listBookmarks(user, registry_id, page, NUM_MAX_FAVORITOS)

        tags_list = model.Bookmarks.listAllTags(registry_id)
        links = []
        if isAllowedToWriteObject(user, "bookmarks", registry_id):
            links.append((u"Criar novo favorito", "/static/imagens/icones/new32.png", "/bookmarks/new/"+registry_id))
        if isUserOrOwner(user, registry_id):
            links.append((u"Alterar permissões dos Favoritos", "/static/imagens/icones/permissions32.png", "/permission/bookmarks/"+registry_id, "", "", True))

        log.model.log(user, u'acessou os favoritos de', objeto=registry_id, tipo="bookmarks", news=False)
        
        self.render("modules/bookmarks/bookmarks-list.html", NOMEPAG='favoritos', \
                    REGISTRY_ID=registry_id, CRIAR=isUserOrMember(user,registry_id), \
                    TAG=None, LINKS=links, \
                    FOTO=False, \
                    BOOKMARKS=bookmarks, BOOKM_COUNT=bookm_count, \
                    TAGS = tags_list, \
                    PAGE=page, PAGESIZE=NUM_MAX_FAVORITOS, \
                    TITLE="Favoritos de %s"%registry_id, \
                    MSG="")
Esempio n. 3
0
    def get(self, registry_id):
        user = self.get_current_user()
        page = int(self.get_argument("page","1"))
        letra = self.get_argument("letra","")

        glossary = model.Glossary.listGlossary(user, registry_id, page, NUM_MAX_ITENS_GLOSSARIO)
        glossary_count = model.Glossary.countGlossaryByRegistryId(registry_id)
        tags_list = model.Glossary.listAllTags(registry_id)
        links = []
        if isAllowedToWriteObject(user, "glossary", registry_id):
            links.append((u"Criar novo termo", "/static/imagens/icones/new32.png", "/glossary/new/"+registry_id))
        if isUserOrOwner(user, registry_id):
            links.append((u"Alterar permissões deste Glossário", "/static/imagens/icones/permissions32.png", "/permission/glossary/"+registry_id, "", "", True))

        log.model.log(user, u'acessou o glossário de', objeto=registry_id, tipo="glossary", news=False)
                
        self.render("modules/glossary/glossary-list.html", NOMEPAG=NOME_PAG_CLOSSARIO, \
                    REGISTRY_ID=registry_id, CRIAR=isUserOrMember(user,registry_id), \
                    TAG=None, LINKS=links, \
                    FOTO=False, \
                    GLOSSARY=glossary, GLOSSARY_COUNT=glossary_count, \
                    TAGS_LIST = tags_list , \
                    PAGE=page, PAGESIZE=NUM_MAX_ITENS_GLOSSARIO, \
                    TITLE=u"Glossário de %s"%registry_id, \
                    MSG="")
Esempio n. 4
0
    def get(self, registry_id):
        user = self.get_current_user()
        if not isUserOrMember(user, registry_id):
            self.render("home.html", MSG=u"Você não tem permissão para criar termos neste glossário.", \
                        NOMEPAG=NOME_PAG_CLOSSARIO, REGISTRY_ID=registry_id)
            return

        self.render("modules/glossary/new_glossary_item-form.html", \
                    NOMEPAG=NOME_PAG_CLOSSARIO, DEFINITION=u"Digite a definição do termo. <br/>",
                    REGISTRY_ID=registry_id, MSG="")
Esempio n. 5
0
    def get(self, registry_id):
        
        user = self.get_current_user()
        links=[]
        type = self.get_argument("type","1")

        files = model.Studio.listStudioFiles(user, registry_id, int(type))
        if isUserOrMember(user, registry_id):
            links.append((u"Upload de Múltiplos Arquivos", "/static/imagens/icones/upload32.png", "/studio/upload2/"+registry_id+"?type="+type))

        tabs = []
        tabs.append(("Personagens/Objetos", "" if type=="1" else "/studio/%s?type=1"%registry_id))
        tabs.append((u"Cenários",           "" if type=="2" else "/studio/%s?type=2"%registry_id))
        tabs.append(("Storyboard",          "" if type=="3" else "/studio/%s?type=3"%registry_id))
        tabs.append(("Games",               "" if type=="4" else "/studio/%s?type=4"%registry_id))
                
        self.render("modules/studio/files-list.html", NOMEPAG=u'Estúdio', \
                    LINKS=links, REGISTRY_ID=registry_id, CRIAR=isUserOrMember(user,registry_id), \
                    TYPE=type, \
                    TABS=tabs, \
                    FILES=files, MSG="")
Esempio n. 6
0
def autocomplete_mblog (user, registry_id):
    permission = False
    autocomplete = dict()    
    if isUserOrMember(user, registry_id):
        permission = True
        
        _member = core.model.Member().retrieve(user)
        autocomplete_list = []
        autocomplete_list.extend(_member.getFriendsList()[1])
        autocomplete_list.extend(_member.getCommunitiesList())
        if isACommunity(registry_id):
            _member = core.model.Community().retrieve(registry_id)
            autocomplete_list.extend(_member.getMembersList()[1])
        
        for item in autocomplete_list:
            autocomplete[item[0].encode('iso-8859-1', 'ignore')] = item[1].encode('iso-8859-1', 'ignore')
            
    return (permission, autocomplete)
Esempio n. 7
0
def isAllowedToReadObject(user, servico, registry_id, nomeobj=""):
    perm_id = "%s/%s/%s" % (servico, registry_id, nomeobj)
    
    _perm = permission.model.Permission().retrieve(perm_id)
    if not _perm: 
        if servico in ["evaluation", "quiz"]:
            # "acesso_comunidade"  
            return (isUserOrMember(user, registry_id))
        elif servico in ["question"]:
            # "acesso_privado"  
            return (isUserOrOwner(user, registry_id))
        else:
            # "acesso_activ"            
            return (user!="" and user!=None)
            
    if _perm.escopo_R == "acesso_privado":
        return (user == _perm.owner or isUserOrOwner(user, registry_id))  
          
    if _perm.escopo_R == "acesso_grupos":
        # permite acesso ao dono do objeto e ao dono/admin da comunidade
        if (user == _perm.owner or isUserOrOwner(user, registry_id)):
            return True
        
        # permite acesso aos participantes dos grupos selecionados
        _reg = core.model.Registry().retrieve(registry_id)
        if not _reg:
            return False
        for group in _perm.grupos_R:
            if user in _reg.getGroups[group]:
                return True
        return False
     
    if _perm.escopo_R == "acesso_comunidade":
        #return (isUserOrMember(user, registry_id))
        return (isFriendOrMember(user, registry_id))
                 
    if _perm.escopo_R == "acesso_activ":
        return (user!="" and user!=None)
    
    if _perm.escopo_R == "acesso_publico":
        return True
    
    return False
Esempio n. 8
0
    def get(self, registry_id, tag):
        user = self.get_current_user()
        page = int(self.get_argument("page","1"))
        bookm_count = model.Bookmarks.countBookmarksByRegistryIdAndTag(registry_id, tag)
        #(bookmarks, tags_list) = model.Bookmarks.listBookmarks(user, registry_id, page, NUM_MAX_FAVORITOS, tag)
        bookmarks = model.Bookmarks.listBookmarks(user, registry_id, page, NUM_MAX_FAVORITOS, tag)
        tags_list = model.Bookmarks.listAllTags(registry_id, tag)

        log.model.log(user, u'acessou os favoritos de', objeto=registry_id, tipo="bookmarks", news=False)
                
        self.render("modules/bookmarks/bookmarks-list.html", NOMEPAG='favoritos', \
                    REGISTRY_ID=registry_id, CRIAR=isUserOrMember(user,registry_id), \
                    TAG=tag, LINKS=[], \
                    FOTO=False, \
                    BOOKMARKS=bookmarks, BOOKM_COUNT=bookm_count, \
                    TAGS = tags_list, \
                    PAGE=page, PAGESIZE=NUM_MAX_FAVORITOS, \
                    TITLE="Favoritos de %s com a tag %s"%(registry_id,tag), \
                    MSG="")
Esempio n. 9
0
    def get(self, registry_id, tag):
        user = self.get_current_user()
        page = int(self.get_argument("page","1"))

        glossary = model.Glossary.listGlossary(user, registry_id, page, NUM_MAX_ITENS_GLOSSARIO, tag)
        glossary_count = model.Glossary.countGlossaryByRegistryIdAndTag(registry_id, tag)
        tags_list = model.Glossary.listAllTags(registry_id, tag)

        log.model.log(user, u'acessou o glossário de', objeto=registry_id, tipo="glossary", news=False)

        self.render("modules/glossary/glossary-list.html", NOMEPAG=NOME_PAG_CLOSSARIO, \
                    REGISTRY_ID=registry_id, CRIAR=isUserOrMember(user,registry_id), \
                    TAG=tag, LINKS=[], \
                    FOTO=False, \
                    GLOSSARY=glossary, GLOSSARY_COUNT=glossary_count, \
                    TAGS_LIST = tags_list, \
                    PAGE=page, PAGESIZE=NUM_MAX_ITENS_GLOSSARIO, \
                    TITLE=u"Glossário de %s com a tag %s"%(registry_id,tag),  \
                    MSG="")
Esempio n. 10
0
 def get(self, registry_id):
     user = self.get_current_user()
     page = int(self.get_argument("page","1"))
     
     if isFriendOrMember(user, registry_id):
         self._scrap = model.Scrapbook().retrieve(registry_id)
         scrap_list = []
         scraps_count = 0
         if self._scrap!=None:
             filter = not isUserOrMember(user, registry_id)
             scrap_list = self._scrap.getScrapbookList(user, page=page, page_size=NUM_MAX_SCRAPS, \
                                                   filter=filter)
             scraps_count = self._scrap.countScraps(user, filter=filter)
             
         self.render("modules/scrapbook/scrap-list.html", REGISTRY_ID=registry_id, \
                     USER=user, NOMEPAG='recados', \
                     APAGAR=isUserOrOwner(user, registry_id), \
                     SCRAPDATA=scrap_list, SCRAPS_COUNT = scraps_count, \
                     PAGE=page, PAGESIZE=NUM_MAX_SCRAPS)
         
     else:
         raise HTTPError(403)            
Esempio n. 11
0
    def post(self, registry_id):
        user = self.get_current_user()
        if not isUserOrMember(user, registry_id):
            self.render("home.html", MSG=u"Você não tem permissão para criar termos neste glossário.", \
                        NOMEPAG=NOME_PAG_CLOSSARIO, REGISTRY_ID=registry_id)
            return
        MSG = ""
        glossary_term = self.get_argument("term","")
        if not glossary_term:
            MSG += u"Termo não pode ser vazio."
        glossary_definition = self.get_argument("definition","")
        if not glossary_definition:
                MSG += u"%sA definição do termo não pode estar vazia." % ("" if not MSG else "<br/>")
        if not MSG:
            glossary_item_id = remove_special_chars(remove_diacritics(glossary_term.replace(" ","_")))
            if model.Glossary.searchItemByRegistryIdAndItemId(user, registry_id, glossary_item_id, False):
                MSG += u"Termo já definido neste glossário."

        if MSG:
            self.render("modules/glossary/new_glossary_item-form.html", \
                        NOMEPAG=NOME_PAG_CLOSSARIO, DEFINITION=glossary_definition, REGISTRY_ID=registry_id, MSG=MSG)
            return
        else:
            self._glossary = model.Glossary()
            self._glossary.id = '/'.join([registry_id,glossary_item_id])
            self._glossary.registry_id = registry_id
            self._glossary.owner = user
            self._glossary.item_id = glossary_item_id
            self._glossary.term = self.get_argument("term","")
            self._glossary.definition = glossary_definition
            self._glossary.tags = splitTags(self.get_argument("tags",""))
            self._glossary.data_cri = self._glossary.data_alt = str(datetime.now())
            self._glossary.alterado_por = user
            self._glossary.saveGlossaryItem(glossary_item_id)
            log.model.log(user, u'criou um termo no glossário de', objeto=registry_id, tipo="glossary")

        self.redirect("/glossary/%s" % registry_id)
Esempio n. 12
0
    def post(self, registry_id):
        user = self.get_current_user()

        if self.request.files:
            
            # este split é para resolver o problema do IE, que manda o caminho completo.
            filename = self.request.files["arquivo"][0]["filename"].split("\\")[-1]
            filename = remove_diacritics(filename)
            filename = filename.replace(" ", "_")
            if "." not in filename or filename.split(".")[-1].lower() not in ["gif", "jpg", "jpeg", "png"]:
                self.render("home.html", MSG=u"Utilize somente arquivos com extensão: gif, jpg, jpeg ou png.", \
                            NOMEPAG=u'Estúdio', REGISTRY_ID=registry_id)
                return

            tipo = ""
            if registry_id in core.database.REGISTRY:
                if not isUserOrMember(user, registry_id):
                    self.render("home.html", MSG=u"Você não tem permissão para carregar arquivos aqui.", \
                                NOMEPAG=u'Estúdio', REGISTRY_ID=registry_id)
                    return
                    
                #if len(self.request.files["arquivo"][0]["body"]) + core.database.REGISTRY[registry_id]["upload_size"] > core.database.REGISTRY[registry_id]["upload_quota"]:
                #    self.render("home.html", MSG=u"Espaço para armazenamento de arquivos excedido.", \
                #                NOMEPAG=u'Estúdio', REGISTRY_ID=registry_id)
                #    return

                # A chave _id do documento no couchdb é nome/arquivo
                file_id = '/'.join([registry_id,filename])

                self._file = model.Studio().retrieve(file_id)
                if self._file:
                    self.render("home.html", MSG=u"Já existe um arquivo com este mesmo nome. Remova-o antes de subir com uma nova versão.", \
                                NOMEPAG=u'Estúdio', REGISTRY_ID=registry_id)
                    return
                else: 
                    self._file = model.Studio(file_id=file_id)
                
                if self.get_argument("type","")=="":
                    self.render("home.html", MSG=u"Escolha a fase onde a imagem deve ser armazenada.", \
                                NOMEPAG=u'Estúdio', REGISTRY_ID=registry_id)
                    return
                
                self._file.type = int(self.get_argument("type",""))
                self._file.description = self.get_argument("description","")
                self._file.url = self.get_argument("url","")
                self._file.tags = splitTags(self.get_argument("tags",""))
                self._file.owner = self._file.alterado_por = user
                self._file.registry_id = registry_id
                self._file.data_upload = self._file.data_alt = str(datetime.now())
                self._file.filename = filename
                if not self._file.saveFile(file_id, self.request.files):
                    self.render("home.html", MSG=u"Erro na leitura do arquivo de imagem.", \
                                NOMEPAG=u'Estúdio', REGISTRY_ID=registry_id)
                    return
                    
                log.model.log(user, u'criou imagem no studio de games', objeto=file_id, tipo="studio")

                self.redirect("/studio/%s" % registry_id)

            else:
               self.render("home.html", MSG=u"Usuário ou comunidade inexistentes.", \
                           NOMEPAG=u'Estúdio', REGISTRY_ID=user)

        else:
            self.render("home.html", MSG=u"Erro: Arquivo inexistente!", \
                        NOMEPAG=u'Estúdio', REGISTRY_ID=registry_id)
Esempio n. 13
0
    def post(self, registry_id):
        user = self.get_current_user()
        
        if self.request.files:
            
            # este split é para resolver o problema do IE, que manda o caminho completo.
            filename = self.request.files["arquivo"][0]["filename"].split("\\")[-1]
            #filename = remove_diacritics(filename)
            #filename = filename.replace(" ", "_")
            filename = remove_special_chars(remove_diacritics(filename.replace(" ","_")))
            
            if filename=="":
                self.write (dict(status=1, msg=u"Nome do arquivo inválido."))
                return

            if filename[0]=="_":
                self.write (dict(status=1, msg=u"Nome do arquivo não pode iniciar com sublinhado (_)."))
                return

            if "." not in filename or filename.split(".")[-1].lower() not in ["gif", "jpg", "jpeg", "png"]:
                self.write (dict(status=1, msg=u"Utilize somente arquivos com extensão: gif, jpg, jpeg ou png."))
                return
                                
           
            if registry_id in core.database.REGISTRY:
                if not isUserOrMember(user, registry_id):
                     self.write (dict(status=1, MSG=u"Você não tem permissão para carregar arquivos aqui."))
                     return

                # A chave _id do documento no couchdb é nome/arquivo
                file_id = '/'.join([registry_id,filename])

                self._file = model.Studio().retrieve(file_id)
                if self._file:
                    self.write (dict(status=1, MSG=u"Já existe um arquivo com este mesmo nome (%s). Remova-o antes de subir com uma nova versão." % file_id))
                    return
                else: 
                    self._file = model.Studio(file_id=file_id)

                
                if self.get_argument("type","")=="":
                    self.write (dict(status=1, MSG=u"Escolha a fase onde a imagem deve ser armazenada."))
                    return
                 
                self._file.type = int(self.get_argument("type",""))
                self._file.description = self.get_argument("description","")
                self._file.url = self.get_argument("url","")
                self._file.tags = splitTags(self.get_argument("tags",""))
                self._file.owner = self._file.alterado_por = user
                self._file.registry_id = registry_id
                self._file.data_upload = self._file.data_alt = str(datetime.now())
                self._file.filename = filename
                if not self._file.saveFile(file_id, self.request.files):
                    self.write (dict(status=1, MSG=u"Erro na leitura do arquivo de imagem. (%s)" %file_id))
                    return
                
                log.model.log(user, u'criou o arquivo', objeto=file_id, tipo="file")

                self.write (dict(status=0, redirect="/studio/%s" % (registry_id)))

            else:
               self.write (dict(status=1, msg=u"Usuário ou comunidade inexistentes."))
                
        else:
            self.write (dict(status=1, msg=u"Erro: Arquivo inexistente!"))