Example #1
0
def viewSlides(project_id, presentation_id):
	if not 'username' in session:
		return render_template("login.html", warning = "Please log-in to the system.")
	role = dbc.getRole(project_id, session['username'])
	if role != "Presentation Creator" and role != "Project Manager" and role != 'Slide Creator':
		return not_allowed("error")
	presentation = VCS().load_project(str(project_id)).get_presentation(presentation_id)
	path = relative_path("static/%s" % project_id)
	if not os.path.exists(path):
		os.makedirs(path)
	presentation.export_images(path, hide_confidential = True)
	printMii = presentation.slides
	return render_template("viewPresentation.html", project_id = project_id, presentation_id = presentation_id, name = presentation.name, slideList = printMii)
Example #2
0
 def __init__(self, id, watch_directory, notifier=None):
     self.id = id
     self.watch_directory = watch_directory
     self.notifier = notifier
     self.vcs = VCS(watch_directory)
     self._working = False
     logging.info("Using Action: vcs")
Example #3
0
def checkInSlide(project_id):
	if not 'username' in session:
		return render_template("login.html", warning = "Please log-in to the system.")
	if dbc.getRole(project_id, session['username']) != "Slide Creator" and dbc.getRole(project_id, session['username']) != "Project Manager" and dbc.getRole(project_id, session['username']) != "Presentation Creator":
		return not_allowed("error")
	if request.method == 'POST':
		user = session['username']
		slideObject = VCS().load_project(str(project_id)).get_slide(request.form['slide_id'])
		if slideObject.checkout_user != user:			
			return show_project(project_id, warning = "Check In %s failed.  You don't have that checked out." % slideObject.name, role = 'Slide Creator', alert = 'danger')
		stuff = request.files['slide_file']
		if stuff and isFileAllowed(stuff.filename):
			slideObject.checkin(user, stuff.read())	
			return show_project(project_id, warning = "Slide %s has been checked in." % slideObject.name, role = "Slide Creator", alert = "success")
		return show_project(project_id, warning = "Only use powerpoint files to check in please.", role = 'Slide Creator', alert = 'warning')
	return illegal_action("error")
Example #4
0
def slideCheckOut(project_id):	
	if not 'username' in session:
		return render_template("login.html", warning = "Please Log-in to the system.")
	role = dbc.getRole(project_id, session['username'])
	if role != 'Project Manager' and role != 'Presentation Creator' and role != 'Slide Creator':
		return not_allowed("error")
	if request.method == 'POST':
		project = VCS().load_project(str(project_id))
		slide = request.form['slide_ID']
		if project.get_slide(slide).confidential:
			return show_project(project_id, warning = "Slide %s checkout failed. It's protected by confidentiality." % slide, role = 'Slide Creator', alert = 'danger')
		if(project.get_slide(slide).checkout_user != None):
			return show_project(project_id, warning = "Slide %s checkout failed. It's already checked out." % slide, role = 'Slide Creator', alert = 'danger')
		project.get_slide(slide).checkout(session['username'])
		return show_project(project_id, warning = "Slide %s has been checked out." % slide, role = 'Slide Creator', alert = 'success')
	return illegal_action("error")
Example #5
0
def deauthorizeCheckOut(project_id, slide_id):
	if not 'username' in session:
		return render_template("login.html", warning = "Please log-in to the system.")
	if not slide_id:
		return illegal_action("error")
	
	slide = VCS().load_project(str(project_id)).get_slide(slide_id)
	if not slide.checkout_user:
		return illegal_action("error") 
	print slide.checkout_user
	print session['username']
	if slide.checkout_user != session['username'] and dbc.getRole(project_id, session['username']) != 'Project Manager' and dbc.getRole(project_id, session['username']) != 'Presentation Creator':
		return not_allowed("error")
	
	slide.cancel_checkout()
	flash("Slide %s checkout has been removed" % slide.name)
	return redirect(url_for("viewPresentations", project_id=project_id))
Example #6
0
def tagSlideAsConfidential(project_id):
	if not 'username' in session:		
		return render_template("login.html", warning = "Please log-in to the system.")
	role = dbc.getRole(project_id, session['username'])
	if role != "Project Manager":
		return not_allowed("error")
	if request.method == 'POST':
		slide = request.form['slide_id']
		print slide
		currentSlide = VCS().load_project(str(project_id)).get_slide(slide)
		if currentSlide.confidential:		
			return show_project(project_id, warning = "Slide is already flagged as confidential.", role = 'Slide Creator', alert = 'warning')
		if currentSlide.checkout_user != session['username'] and role == 'Slide Creator':
			return show_project(project_id, warning = "You can't mark a slide as confidential if you're a Slide Creator and haven't checked it out.", role = 'Slide Creator', alert = 'danger')
		currentSlide.cancel_checkout()
		currentSlide.confidential = True
		return show_project(project_id, warning = "Slide has been tagged as confidential.", role = 'Slide Creator', alert = 'danger')
	return illegal_action("error")
Example #7
0
    def initVCS(self, app):
        wiki = app.config.get('wiki')
        if "enable_vcs" in wiki and wiki.get("enable_vcs"):
            vcsconfig = app.config.get("vcs")
            if vcsconfig["type"] is not None:
                if vcsconfig['type'] == "git":
                    from vcs import Git as VCS
                    app.vcs = VCS(app.config)
                    if vcsconfig["postrecieve"] is not None:
                        self._triggerurl = vcsconfig["postrecieve"]

        self.githubroot = wiki.get("githubroot", None)
Example #8
0
import os.path
import shutil

from vcs import VCS

def remove_dir_if_exists(path):
	if os.path.exists(path):
		shutil.rmtree(path)

if __name__ == '__main__':
    remove_dir_if_exists("testprojects/testcreatingprojects")

    vcs = VCS()
    vcs.set_project_directory("testprojects")
    
    # Create project
    project = vcs.create_project("testcreatingprojects")
    presentation = project.current_presentation

    # Add slides
    slide1 = presentation.add_slide("Slide 1")
    slide2 = presentation.add_slide("Slide 2")

    # Update slide 1
    presentation.checkout(slide1, "testuser")
    slide1 = presentation.checkin(slide1, "testuser", "This is slide 1")

    # Update slide 2
    presentation.checkout(slide2, "testuser")
    slide2 = presentation.checkin(slide2, "testuser", "This is slide 2")
Example #9
0
class Action(object):
    def __init__(self, id, watch_directory, notifier=None):
        self.id = id
        self.watch_directory = watch_directory
        self.notifier = notifier
        self.vcs = VCS(watch_directory)
        self._working = False
        logging.info("Using Action: vcs")

    def _add_commit_push_cycle(self, event):
        status = self.vcs.status()
        if len(status) > 0:
            modes,files = zip(*status)

            file_list = ','.join(files)
            message = "syncilainen[%s]: %s: %s" % (self.id, datetime.now().isoformat(), file_list)

            logging.debug("%s: add" % event.pathname)
            result,error = self.vcs.add()
            if not result == OK:
                logging.error("%s: add" % error)
                if self.notifier:
                    self.notifier.notify(error, ERROR_LEVEL)
                return result,error

            logging.debug("%s: commit_all" % event.pathname)
            result,error = self.vcs.commit_all(message)
            if not result == OK:
                return result,error

            logging.debug("%s: push" % event.pathname)
            result,error = self.vcs.push()
            if not result == OK:
                # fetch
                logging.debug("%s: fetch" % event.pathname)
                result,error = self.vcs.fetch()

                # merge
                logging.debug("%s: merge" % event.pathname)
                result,error = self.vcs.merge()
                if not result == OK:
                    # ls_files
                    logging.debug("%s: get_unmerged" % event.pathname)
                    unmerged = self.vcs.get_unmerged()
                    logging.debug("unmerged: %s" % unmerged)

                    for u in unmerged:
                        # save theirs as <id>.<sha1>.<filename>
                        logging.debug("%s: save_theirs" % event.pathname)
                        self.vcs.save_theirs(u, id)

                        # force ours to be <filename>
                        logging.debug("%s: force_ours" % event.pathname)
                        self.vcs.force_ours(u)

                    # recurse
                    logging.debug("%s: recurse" % event.pathname)
                    return self._add_commit_push_cycle(event)

            # Everything went OK
            return result,message

        # Nothing to do
        return OK,""

    def callback(self, event):
        if self.vcs.ignore_path in event.pathname:
            #logging.debug("ignoring: %s" % event.pathname)
            return

        if self._working:
            #logging.debug("working.. ignoring: %s" % event.pathname)
            return

        self._working = True

        logging.debug("%s: _add_commit_push_cycle" % event.pathname)
        result,message = self._add_commit_push_cycle(event)
        if not result == OK:
            logging.error("%s: _add_commit_push_cycle" % error)
            if self.notifier:
                self.notifier.notify(error, ERROR_LEVEL)
        else:
            # Everything went OK
            logging.info("%s: OK: %s" % (event.pathname, message))
            self._working = False
            if self.notifier:
                self.notifier.notify(message, NORMAL_LEVEL)