# HG changeset patch # User Nicolas DURAND # Date 1416575960 -3600 # Node ID 83d266c0c8324e6e3ac08280a0c9553995e7b2c0 # Parent 54f4e0f9d636cc18f8abd8709fb506459143c4f6 Initial commit (this time I'll push) + added checks if the authenticated user has write access to categories repo + added try except blocks around github api request diff -r 54f4e0f9d636 -r 83d266c0c832 src/catedit/persistence.py --- a/src/catedit/persistence.py Thu Nov 20 17:44:01 2014 +0100 +++ b/src/catedit/persistence.py Fri Nov 21 14:19:20 2014 +0100 @@ -80,43 +80,53 @@ except GitHubError: pass # print json.dumps(request_data) - github.request('PUT', - "repos/" - +app.config["REPOSITORY_OWNER"]+"/" - +app.config["REPOSITORY_NAME"] - +"/contents/" - +app.config["CATEGORIES_PATH"] - +kwargs["name"], - data=json.dumps(request_data)) + try: + github.request('PUT', + "repos/" + +app.config["REPOSITORY_OWNER"]+"/" + +app.config["REPOSITORY_NAME"] + +"/contents/" + +app.config["CATEGORIES_PATH"] + +kwargs["name"], + data=json.dumps(request_data)) + except GitHubError: + pass def load(self, **kwargs): - filedict = github.get("repos/" - +app.config["REPOSITORY_OWNER"]+"/" - +app.config["REPOSITORY_NAME"] - +"/contents/" - +app.config["CATEGORIES_PATH"] - +kwargs["name"]) - file_content=b64decode(filedict["content"]) + try: + filedict = github.get("repos/" + +app.config["REPOSITORY_OWNER"]+"/" + +app.config["REPOSITORY_NAME"] + +"/contents/" + +app.config["CATEGORIES_PATH"] + +kwargs["name"]) + file_content=b64decode(filedict["content"]) + except GitHubError: + pass return file_content def delete(self, **kwargs): request_data = { "message": kwargs["message"] } + try: + filedict = github.get("repos/" + +app.config["REPOSITORY_OWNER"]+"/" + +app.config["REPOSITORY_NAME"] + +"/contents/" + +app.config["CATEGORIES_PATH"] + +kwargs["name"]) + request_data["sha"] = filedict["sha"] + except GitHubError: + pass - filedict = github.get("repos/" - +app.config["REPOSITORY_OWNER"]+"/" - +app.config["REPOSITORY_NAME"] - +"/contents/" - +app.config["CATEGORIES_PATH"] - +kwargs["name"]) - request_data["sha"] = filedict["sha"] - - # print json.dumps(request_data) - github.request('DELETE', - "repos/catedit-system/" - +app.config["REPOSITORY_NAME"] - +"/contents/categories/" - +kwargs["name"], - data=json.dumps(request_data)) + try: + github.request('DELETE', + "repos/catedit-system/" + +app.config["REPOSITORY_NAME"] + +"/contents/categories/" + +kwargs["name"], + data=json.dumps(request_data)) + except GitHubError: + pass def list(self, **kwargs): filenames_list=[] @@ -131,12 +141,15 @@ pass file_content_list=[] for filename in filenames_list: - filedict = github.get("repos/" - +app.config["REPOSITORY_OWNER"]+"/" - +app.config["REPOSITORY_NAME"] - +"/contents/" - +app.config["CATEGORIES_PATH"] - +filename) - file_content_list.append(b64decode(filedict["content"])) + try: + filedict = github.get("repos/" + +app.config["REPOSITORY_OWNER"]+"/" + +app.config["REPOSITORY_NAME"] + +"/contents/" + +app.config["CATEGORIES_PATH"] + +filename) + file_content_list.append(b64decode(filedict["content"])) + except GitHubError: + pass # print file_content_list return file_content_list diff -r 54f4e0f9d636 -r 83d266c0c832 src/catedit/settings.py --- a/src/catedit/settings.py Thu Nov 20 17:44:01 2014 +0100 +++ b/src/catedit/settings.py Fri Nov 21 14:19:20 2014 +0100 @@ -18,7 +18,7 @@ # Logging config LOG_FILE_PATH = "log/log.txt" - LOGGING = True + LOGGING = False # Github repository config diff -r 54f4e0f9d636 -r 83d266c0c832 src/catedit/static/css/style.css --- a/src/catedit/static/css/style.css Thu Nov 20 17:44:01 2014 +0100 +++ b/src/catedit/static/css/style.css Fri Nov 21 14:19:20 2014 +0100 @@ -3,6 +3,10 @@ margin-bottom: 4px; } +.property-delete-button{ + margin-left: 4px; +} + .visible{ display:block; } diff -r 54f4e0f9d636 -r 83d266c0c832 src/catedit/templates/cateditor.html --- a/src/catedit/templates/cateditor.html Thu Nov 20 17:44:01 2014 +0100 +++ b/src/catedit/templates/cateditor.html Fri Nov 21 14:19:20 2014 +0100 @@ -1,4 +1,4 @@ -{% if not session.get("user_code", None) %} +{% if not session["user_logged"] or not session["user_can_edit"] %} {% set readonly="readonly" %} {% else %} {% set readonly=False %} @@ -31,14 +31,21 @@
  • Editeur de catégorie: {% if cat_id: %} Edition {% else %} Création {% endif %}
  • - {% if readonly %} + {% if session["user_logged"] and not session["user_can_edit"] %} + + {% endif %} + {% if not session["user_logged"] %}
    + {% if session["user_logged"] and not session["user_can_edit"] %} + + {% endif %}

    Liste des catégories existantes

    @@ -57,7 +69,7 @@ {% if cat_list|length == 0 %} - + {% else %} {% for cat in cat_list %} diff -r 54f4e0f9d636 -r 83d266c0c832 src/catedit/views.py --- a/src/catedit/views.py Thu Nov 20 17:44:01 2014 +0100 +++ b/src/catedit/views.py Fri Nov 21 14:19:20 2014 +0100 @@ -1,6 +1,7 @@ from app import app, github from models import Category, CategoryManager from flask import render_template, request, redirect, url_for, session +from flask.ext.github import GitHubError from flask_wtf import Form from api import CategoryAPI from wtforms import StringField, TextAreaField @@ -119,6 +120,19 @@ session["user_code"] = oauth_code session["user_logged"] = True session["user_login"] = github.get("user")["login"] + try: + repoList=[] + repoList=github.get("user/repos") + # for repo in repoList: + # print repo["name"] + session["user_can_edit"] = True + if not any (repo["name"] == app.config["REPOSITORY_NAME"] for repo in repoList): + session["user_can_edit"] = False + print session["user_can_edit"] + except GitHubError: + # print "error getting repos!" + pass + # print session["user_login"] return redirect(url_for('cat_recap')) @@ -132,4 +146,5 @@ session["user_code"] = None session["user_logged"] = None session["user_login"] = None + session["user_can_edit"] = None return redirect(url_for('cat_recap'))
    Aucune catégorie n'a été créée. Créer une catégorieAucune catégorie n'a été créée pour l'instant. {% if not readonly %}Créer une catégorie{% endif %}