Esempio n. 1
0
def get(p):
    host = p['c']['host']
    index = p['c']['index']

    # load comment
    post_id = p['nav'][-1]
    p['post'] = es.get(host, index, 'post', post_id)
    if not p['post']:
        return tools.alert('not valid post id - {}'.format(post_id))

    # comment_id
    comment_id = tools.get("id")
    p['comment'] = next(
        (x for x in p['post']['comment'] if x['id'] == comment_id), {})
    if not p['comment']:
        return tools.alert('not valid comment_id - {}'.format(comment_id))

    # init workflow
    wf = tools.get('wf', 'comment_delete')
    p['workflow'] = workflow.init(wf, host, index)

    # remove comment
    p['post']['comment'].remove(p['comment'])

    es.update(host, index, 'post', post_id, p['post'])
    es.flush(host, index)

    return tools.redirect(request.referrer)
Esempio n. 2
0
def get(p):
    # load navigation
    navigation_id = p['nav'][-1]
    navigation = es.get(p['host'], 'core_nav', 'navigation', navigation_id)
    if not navigation:
        return tools.alert(
            'not valid navigation id - {}'.format(navigation_id))

    if not tools.get('site_id'): return tools.alert("site id missing")
    if not tools.get('module_id'): return tools.alert("module id missing")

    # edit role
    doc = {
        'site_id': tools.get('site_id'),
        'parent_id': tools.get('parent_id'),
        'module_id': tools.get('module_id'),
        'order_key': int(tools.get('order_key')),
        'is_displayed': tools.get('is_displayed'),
        'name': tools.get('name'),
        'display_name': tools.get('display_name'),
        'url': tools.get('url'),
        'new_window': tools.get('new_window'),
        'description': tools.get('description')
    }
    es.update(p['host'], 'core_nav', 'navigation', navigation_id, doc)
    es.flush(p['host'], 'core_nav')

    return tools.redirect(request.referrer)
Esempio n. 3
0
def get(p):
    host = p['c']['host']; index = p['c']['index'];

    # init workflow
    wf = tools.get("wf", 'comment_edit')
    p['workflow'] = workflow.init(wf, host, index)

    # load comment
    post_id = p['nav'][-1]
    p['post'] = es.get(host, index, 'post', post_id)
    if not p['post']:
        return tools.alert('not valid post id - {}'.format(post_id))

    # comment_id
    comment_id = tools.get("id")
    p['comment'] = next((x for x in p['post']['comment'] if x['id'] == comment_id), None)
    if not p['comment']:
        return tools.alert('not valid comment_id - {}'.format(comment_id))

    # field map
    fields = es.list(host, index, 'field')
    p['field_map'] = {}
    for field in fields:
        p['field_map'][field['name']] = field['id']

    # update comment
    p['comment']['updated'] = es.now()
    p['comment']['updated_by'] = p['login']
    p['comment']['comment'] = tools.get("comment")

    es.update(host, index, 'post', post_id, p['post'])
    es.flush(host, index)

    return tools.redirect(request.referrer)
Esempio n. 4
0
def get(p):
    index = tools.get('index')
    id = tools.get('id')
    if not index or not id:
        return tools.alert('invalid id or index')

    # find config with matching index
    configs = es.list(p['host'], 'core_nav', 'config',
        "name:'index' AND value:'{}'".format(index))
    if not len(configs) > 0:
        return tools.alert('site not found')

    # get site id
    navigation_id = configs[0]['id'].split('_')[0]
    navigation = es.get(p['host'], 'core_nav', 'navigation', navigation_id)
    site = es.get(p['host'], 'core_nav', 'site', navigation['site_id'])

    # form url
    url = '{}/{}'.format(site.get('name'), navigation.get('name'))
    url = "{}/post/view/{}".format(url, id)
    # when navigation or site is empty then it contains double slash 
    url = url.replace("//", "/")
    url = urlparse.urljoin(request.url_root, url)

    return tools.redirect(url)
Esempio n. 5
0
def get(p):
    host = p['c']['host']
    index = p['c']['index']

    # keep pagination
    p["q"] = tools.get('q', '*')
    # pagination
    p["from"] = int(tools.get('from', 0))
    p["size"] = int(tools.get('size', p['c']['page_size']))
    # sort
    p['sort_field'] = tools.get('sort_field', p['c']['sort_field'])
    p['sort_dir'] = tools.get('sort_field', p['c']['sort_dir'])

    # load post
    post_id = p['nav'][-1]
    p['post'] = es.get(host, index, 'post', post_id)
    if not p['post']:
        return tools.alert('not valid post id - {}'.format(post_id))

    # check ACL
    valid_acl = False
    if not p['post'].get('acl_readonly') and not p['post'].get('acl_edit'):
        valid_acl = True
    if p['login'] == p['post'].get('created_by'): valid_acl = True
    if p['post'].get('acl_readonly'):
        if p['login'] in p['post'].get('acl_readonly'): valid_acl = True
        if 'EVERYONE' in p['post'].get('acl_readonly'): valid_acl = True
    if p['post'].get('acl_edit'):
        if p['login'] in p['post'].get('acl_edit'): valid_acl = True
        if 'EVERYONE' in p['post'].get('acl_edit'): valid_acl = True
    if not valid_acl:
        return tools.alert('permission not granted')

    # return json format
    if tools.get("json"):
        callback = tools.get("callback")
        if not callback:
            return json.dumps(p['post'])
        else:
            return "{}({})".format(callback, json.dumps(p['post']))

    # get comment list
    query = "post_id:{}".format(post_id)
    option = "size=100&sort=created:desc"
    p['comment_list'] = es.list(host, index, 'comment', query, option)

    # increase visit count
    if not p['post'].get("viewed"): p['post']["viewed"] = 0
    p['post']["viewed"] += 1
    es.update(host, index, 'post', post_id, p['post'])

    # field_list
    p['field_list'] = es.list(host, index, 'field', "visible:view",
                              "size=1000&sort=order_key:asc")

    return render_template("post/post/view.html", p=p)
Esempio n. 6
0
def get(p):
    host = p['c']['host']
    index = p['c']['index']

    # init workflow
    wf = tools.get("wf", 'comment')
    p['workflow'] = workflow.init(wf, host, index)

    # for workflow actions
    p["post"] = es.get(host, index, 'post', tools.get("post_id"))
    if not p["post"]:
        return tools.alert('post id is not valid- {}'.format(
            tools.get("post_id")))

    ######################################################
    # check condition
    if p['workflow'] and p['workflow'].get('condition'):
        try:
            exec(p['workflow']['condition'], globals())
            ret = condition(p)
            if ret != True and ret: return ret
        except SystemExit:
            pass
        except Exception, e:
            return "{}\n{}".format(e.message, traceback.format_exc())
Esempio n. 7
0
def get(p):
    # load instance
    task_id = p['nav'][-1]
    p['task'] = es.get(p['host'], 'core_task', 'task', task_id)
    if not p['task']:
        return tools.alert('invalid task id - {}'.format(task_id))

    # instance list
    query = 'task_id:{}'.format(task_id)
    option = 'size=50'
    if es.count(p['host'], 'core_task', 'instance'):
        option += '&sort=created:desc'
    p['history_list'] = es.list(p['host'], 'core_task', 'instance', query,
                                option)

    for history in p['history_list']:
        # statistics
        query = "instance_id:{}".format(history['id'])
        history['total'] = es.count(p['host'], 'core_task', 'log', query)
        if not history['total']: history['total'] = ''

        query = "instance_id:{} AND status:SUCCESS".format(history['id'])
        history['success'] = es.count(p['host'], 'core_task', 'log', query)
        if not history['success']: history['success'] = ''

        query = "instance_id:{} AND status:ERROR".format(history['id'])
        history['error'] = es.count(p['host'], 'core_task', 'log', query)
        if not history['error']: history['error'] = ''

    return render_template("task/status/history.html", p=p)
Esempio n. 8
0
def get(p):
    host = p['c']['host']; index = p['c']['index'];

    # load post
    post_id = p['nav'][-1]
    p['post'] = es.get(host, index, 'post', post_id)
    p['original'] = es.get(host, index, 'post', post_id)
    if not p['post']:
        return tools.alert('not valid post id - {}'.format(post_id))

    # init workflow
    wf = tools.get('wf', 'edit')
    p['workflow'] = workflow.init(wf, host, index)

    # field map
    fields = es.list(host, index, 'field')
    p['field_map'] = {}
    for field in fields:
        p['field_map'][field['id']] = field

    ######################################################
    # check condition
    if p['workflow'] and p['workflow'].get('condition'):
        try:
            exec (p['workflow']['condition'], globals())
            ret = condition(p)
            if ret != True and ret: return ret
        except SystemExit: pass
        except Exception, e:
            raise
Esempio n. 9
0
def get(p):
    # check if site_id is passed
    p['site_id'] = tools.get('site_id')
    if not p['site_id']: return tools.alert('site id is missing')

    if request.method == "POST":
        # save custom navigation
        p['site'] = {'navigation': tools.get('navigation')}
        es.update(p['host'], 'core_nav', 'site', p['site_id'], p['site'])
        es.flush(p['host'], 'core_nav')

    # load site
    p['site'] = es.get(p['host'], 'core_nav', 'site', p['site_id'])
    if not p['site']: return tools.alert('site id is not valid')

    return render_template("admin/customize/default.html", p=p)
Esempio n. 10
0
def get(p):
    host = p['c']['host']
    index = p['c']['index']

    # load notification
    notification_id = p['nav'][-1]
    p['notification'] = es.get(host, index, 'notification', notification_id)
    if not p['notification']:
        return tools.alert(
            'not valid notification id - {}'.format(notification_id))

    # save notification
    if request.method == "POST":
        doc = {
            'header': tools.get('header'),
            'message': tools.get('message'),
            'recipients': tools.get('recipients'),
            'condition': tools.get('condition'),
            'workflow': tools.get('workflow')
        }
        es.update(host, index, 'notification', notification_id, doc)
        es.flush(host, index)

        return tools.redirect("{}/notification/edit/{}".format(
            p['url'], notification_id))

    return render_template("post/notification/edit.html", p=p)
Esempio n. 11
0
def get(p):
    site_id = p['nav'][-1]

    # root site can't be deleted
    if site_id == "0":
        return tools.alert("Root site can't be deleted")

    # check if site id is valid
    site = es.get(p['host'], 'core_nav', 'site', site_id)
    if not site:
        return tools.alert("not valid site id: {}".format(site_id))

    es.delete(p['host'], 'core_nav', 'site', site_id)
    es.flush(p['host'], 'core_nav')

    return tools.redirect(request.referrer)
Esempio n. 12
0
def get(p):
    # name shall exist
    if not tools.get('inc_url'): return tools.alert("incoming url is missing")
    if not tools.get('out_url'): return tools.alert("outgoing url is missing")

    # create new reverse proxy rule
    doc = {
        'inc_url': tools.get('inc_url'),
        'out_url': tools.get('out_url'),
        'auth_method': tools.get('auth_method'),
        'header': tools.get('header')
    }
    es.create(p['host'], 'core_proxy', 'rev_proxy', '', doc)
    es.flush(p['host'], 'core_proxy')

    return tools.redirect(request.referrer)
Esempio n. 13
0
def get(p):
    if not tools.get('name'): return tools.alert('name is missing')
    if not tools.get('id'): return tools.alert('id is missing')

    # save to configuration
    id = tools.get('id')
    es.update(
        p['host'], 'core_data', 'datasource', id, {
            'navigation_id': p['navigation']['id'],
            'type': tools.get('type'),
            'name': tools.get('name'),
            'description': tools.get('description'),
            'connection': tools.get('connection'),
            'query': tools.get('query')
        })
    es.flush(p['host'], 'core_data')

    return tools.redirect(request.referrer)
Esempio n. 14
0
def get(p):

    # load navigation
    navigation_id = p['nav'][-1]
    navigation = es.get(p['host'], 'core_nav', 'navigation', navigation_id)
    if not navigation:
        return tools.alert(
            'not valid navigation id - {}'.format(navigation_id))

    # root site can't be edited
    if navigation_id in ["0", "1", "2", "3"]:
        return tools.alert("can't delete system navigation")

    # delete
    es.delete(p['host'], 'core_nav', 'navigation', navigation_id)
    es.flush(p['host'], 'core_nav')

    return tools.redirect(request.referrer)
Esempio n. 15
0
def get(p):
    p['site_id'] = tools.get('site_id')
    if not p['site_id']: return tools.alert('site id is missing')

    # role list
    query = 'site_id:{}'.format(p['site_id'])
    option = 'size=1000&sort=name:asc'
    p['role_list'] = es.list(p['host'], 'core_nav', 'role', query, option)

    return render_template("admin/role/default.html", p=p)
Esempio n. 16
0
def get(p):
    # load task
    task_id = p['nav'][-1]
    p['task'] = es.get(p['host'], 'core_task', 'task', task_id)
    if not p['task']:
        return tools.alert('task not found - {}'.format(task_id))

    es.delete(p['host'], 'core_task', 'task', task_id)
    es.flush(p['host'], 'core_task')

    return tools.redirect(request.referrer)
Esempio n. 17
0
def get(p):
    # load schedule
    schedule_id = p['nav'][-1]
    schedule = es.get(p['host'], 'core_task', 'schedule', schedule_id)
    if not schedule:
        return tools.alert('schedule not found - {}'.format(schedule_id))

    es.delete(p['host'], 'core_task', 'schedule', schedule_id)
    es.flush(p['host'], 'core_task')

    return tools.redirect(request.referrer)
Esempio n. 18
0
def get(p):
    # load site
    site_id = p['nav'][-1]
    p['selected_site'] = es.get(p['host'], 'core_nav', 'site', site_id)
    if not p['selected_site']:
        return tools.alert('not valid site id - {}'.format(site_id))
    # name shall exist
    if not tools.get('name'): return tools.alert("name can't be empty")

    # create new site
    doc = {
        'site_id': p['selected_site']['id'],
        'users': tools.get('users'),
        'name': tools.get('name'),
        'description': tools.get('description')
    }
    es.create(p['host'], 'core_nav', 'role', '', doc)
    es.flush(p['host'], 'core_nav')

    return tools.redirect(request.referrer)
Esempio n. 19
0
def get(p):
    host = p['c']['host']
    index = p['c']['index']

    # load history
    history_id = p['nav'][-1]
    p['history'] = es.get(host, index, 'log', history_id)
    if not p['history']:
        return tools.alert('not valid id - {}'.format(history_id))

    return render_template("post/history/view.html", p=p)
Esempio n. 20
0
def get(p):
    # load rule
    rev_proxy_id = p['nav'][-1]
    rev_proxy = es.get(p['host'], 'core_proxy', 'rev_proxy', rev_proxy_id)
    if not rev_proxy:
        return tools.alert('not valid rev_proxy id - {}'.format(rev_proxy_id))

    # delete
    es.delete(p['host'], 'core_proxy', 'rev_proxy', rev_proxy_id)
    es.flush(p['host'], 'core_proxy')

    return tools.redirect(request.referrer)
Esempio n. 21
0
def get(p):
    # load role
    role_id = p['nav'][-1]
    p['role'] = es.get(p['host'], 'core_nav', 'role', role_id)
    if not p['role']:
        return tools.alert('not valid role id - {}'.format(role_id))

    # delete
    es.delete(p['host'], 'core_nav', 'role', role_id)
    es.flush(p['host'], 'core_nav')

    return tools.redirect(request.referrer)
Esempio n. 22
0
def get(p):
    # Load Action
    action_id = p['nav'][-1]
    p['action'] = es.get(p['host'], 'core_task', 'action', action_id)
    if not p['action']:
        return tools.alert('not valid action id - {}'.format(action_id))

    # delete
    es.delete(p['host'], 'core_task', 'action', p['action']['id'])
    es.flush(p['host'], 'core_task')

    return tools.redirect(request.referrer)
Esempio n. 23
0
def get(p):
    # url shall exist
    if not tools.get('url'): return tools.alert("url is missing")

    # create new reverse proxy rule
    doc = {
        'url': tools.get('url')
    }
    es.create(p['host'], 'core_proxy', 'public', '', doc)
    es.flush(p['host'], 'core_proxy')

    return tools.redirect(request.referrer)
Esempio n. 24
0
def get(p):
    # load public url
    public_id = p['nav'][-1]
    public = es.get(p['host'], 'core_proxy', 'public', public_id)
    if not public:
        return tools.alert('not valid public url id - {}'.format(public_id))

    # edit role
    doc = {'url': tools.get('url')}
    es.update(p['host'], 'core_proxy', 'public', public_id, doc)
    es.flush(p['host'], 'core_proxy')

    return tools.redirect(request.referrer)
Esempio n. 25
0
def get(p):
    host = p['c']['host']
    index = p['c']['index']

    # load history list
    item_id = p['nav'][-1]
    query = "id:{}".format(item_id)
    option = "size=100&sort=created:desc"
    p['history_list'] = es.list(host, index, 'log', query, option)
    if not p['history_list']:
        return tools.alert('not valid id - {}'.format(item_id))

    return render_template("post/history/list.html", p=p)
Esempio n. 26
0
def get(p):
    if not tools.get('site_id') and tools.get('site_id') != 0:
        return tools.alert("site id is missing")
    if not tools.get('module_id'): return tools.alert("module id is missing")

    # create new site
    doc = {
        'site_id': tools.get('site_id'),
        'parent_id': tools.get('parent_id'),
        'module_id': tools.get('module_id'),
        'order_key': int(tools.get('order_key', 0)),
        'is_displayed': tools.get('is_displayed'),
        'name': tools.get('name'),
        'display_name': tools.get('display_name'),
        'url': tools.get('url'),
        'new_window': tools.get('new_window'),
        'description': tools.get('description')
    }
    es.create(p['host'], 'core_nav', 'navigation', '', doc)
    es.flush(p['host'], 'core_nav')

    return tools.redirect(request.referrer)
Esempio n. 27
0
def get(p):
    # load instance
    instance_id = p['nav'][-1]
    p['instance'] = es.get(p['host'], 'core_task', 'instance', instance_id)
    if not p['instance']:
        return tools.alert('invalid instance id - {}'.format(instance_id))

    # Search Keyword
    search_keyword = tools.get("search[value]") + "*"

    # Length of the result
    length = tools.get("length")
    if not length: length = 10

    # Offset of the result
    start = tools.get("start")
    if not start: start = 0

    # draw
    draw = tools.get("draw")
    if not draw: draw = 0

    # Apply Search Keyword
    query = "instance_id:{} AND {}".format(instance_id, search_keyword)

    option = 'from={}&size={}&sort=created:desc'.format(start, length)
    # search results
    search_result = es.list(p['host'], 'core_task', 'log', query, option)

    # Get Total number of records
    total = es.count(p['host'], 'core_task', 'log')
    filter_total = es.count(p['host'], 'core_task', 'log', query)

    # Form header
    DataTableJson = {}
    DataTableJson = {
        # draw - this is handshake id which maps the request - response async maps from JS
        "draw":
        int(draw),
        "recordsTotal":
        total,
        "recordsFiltered":
        filter_total,
        "data":
        [[log['action'], log['message'], log['status'], log['created']]
         for log in search_result]
    }

    # Return in JSON format
    return json.dumps(DataTableJson)
Esempio n. 28
0
def get(p):
    # load login module
    login_module_id = p['nav'][-1]
    login_module = es.get(p['host'], 'core_nav', 'login_module',
                          login_module_id)
    if not login_module:
        return tools.alert(
            'not valid login module id - {}'.format(login_module_id))

    # deletelogin module
    es.delete(p['host'], 'core_nav', 'login_module', login_module_id)
    es.flush(p['host'], 'core_nav')

    return tools.redirect(request.referrer)
Esempio n. 29
0
def get(p):
    host = p['c']['host']
    index = p['c']['index']

    # load workflow
    workflow_id = p['nav'][-1]
    p['workflow'] = es.get(host, index, 'workflow', workflow_id)
    if not p['workflow']:
        return tools.alert('not valid workflow id - {}'.format(workflow_id))

    # delete
    es.delete(host, index, 'workflow', workflow_id)
    es.flush(host, index)

    return tools.redirect(request.referrer)
Esempio n. 30
0
def get(p):
    host = p['c']['host']
    index = p['c']['index']

    # load field
    field_id = p['nav'][-1]
    p['field'] = es.get(host, index, 'field', field_id)
    if not p['field']:
        return tools.alert('not valid field id - {}'.format(field_id))

    # save field
    if request.method == "POST":
        return post(p, host, index)

    return render_template('post/field/edit.html', p=p)