コード例 #1
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
コード例 #2
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)
コード例 #3
0
ファイル: control.py プロジェクト: unkyulee/elastic-cms
def get(p):
    # get list of roles
    query = "site_id:{}".format(p['site']['id'])
    option = "size=10000&sort=name:asc"
    p['role_list'] = es.list(p['host'], 'core_nav', 'role', query, option)

    # selected role
    role_id = p['nav'][-1]
    p['role'] = es.get(p['host'], 'core_nav', 'role', role_id)
    if not p['role']:
        p['role'] = p['role_list'][0]

    # get permission
    permission_id = "{}_{}".format(p['role']['id'], p['navigation']['id'])
    p['permission'] = es.get(p['host'], 'core_nav', 'permission', permission_id)

    if request.method == "POST":
        doc = { "operations": [x for x in tools.get('operations', []) if x] }

        if not p['permission']:
            # create permission
            es.create(p['host'], 'core_nav', 'permission', permission_id, doc)
        else:
            # edit permission
            es.update(p['host'], 'core_nav', 'permission', permission_id, doc)
        es.flush(p['host'], 'core_nav')

        return tools.redirect(request.referrer)


    return render_template("post/permission/default.html", p=p)
コード例 #4
0
ファイル: edit.py プロジェクト: unkyulee/elastic-cms
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)
コード例 #5
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)
コード例 #6
0
ファイル: edit.py プロジェクト: unkyulee/elastic-cms
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)
コード例 #7
0
ファイル: create.py プロジェクト: unkyulee/elastic-cms
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())
コード例 #8
0
ファイル: delete.py プロジェクト: unkyulee/elastic-cms
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)
コード例 #9
0
ファイル: history.py プロジェクト: unkyulee/elastic-cms
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)
コード例 #10
0
def get(p):
    host = p['c']['host'] ; index = p['c']['index'] ;

    # get list of mappings
    mapping = es.mapping(host, index, 'post')
    properties = mapping[index]['mappings']['post']['properties']

    # get all field list
    p['field_list'] = []
    for prop in properties.keys():
        field = es.get(host, index, 'field', prop)
        if not field:
            # create field
            field = {
                "type": properties[prop].get('type'),
                "name": prop,
                "order_key": '10000'
            }
            es.create(host, index, 'field', prop, field)
            es.flush(host, index)
            field['id'] = prop

        # add to field list
        p['field_list'].append(field)

    # sort by order key
    p['field_list'] = sorted(p['field_list'],
        key=lambda field: int(field['order_key'] if field['order_key'] else 10000))

    return render_template("post/field/default.html", p=p)
コード例 #11
0
ファイル: task.py プロジェクト: unkyulee/elastic-cms
def actions(task_id):
    query = "task_id:{} AND enabled:Yes".format(task_id)
    option = "size=10000&sort=order_key:asc"
    actions = es.list(HOST, 'core_task', 'action', query, option)
    for action in actions:
        action['module'] = es.get(HOST, 'core_task', 'module',
                                  action['module_id'])

    return actions
コード例 #12
0
ファイル: view.py プロジェクト: unkyulee/elastic-cms
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)
コード例 #13
0
ファイル: edit.py プロジェクト: unkyulee/elastic-cms
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))

    if request.method == "POST":
        es.update(
            p['host'], 'core_task', 'task', task_id, {
                'navigation_id': p['navigation']['id'],
                'name': tools.get('name'),
                'runat':
                tools.get('runat') if tools.get('runat') else 'anywhere',
                'description': tools.get('description')
            })
        es.flush(p['host'], 'core_task')

        return tools.redirect(request.referrer)

    # load action list
    # when there are no records then the task fails to run
    option = ''
    if es.count(p['host'], 'core_task', 'action'):
        option = 'size=10000&sort=order_key:asc'

    query = 'task_id:{}'.format(p['task']['id'])
    p['action_list'] = es.list(p['host'], 'core_task', 'action', query, option)
    for action in p['action_list']:
        action['module'] = es.get(p['host'], 'core_task', 'module',
                                  action['module_id'])

    # load schedule list
    query = 'task_id:{}'.format(p['task']['id'])
    p['schedule_list'] = es.list(p['host'], 'core_task', 'schedule', query)

    # load task module List
    option = 'size=10000&sort=description:asc'
    p['task_module_list'] = es.list(p['host'], 'core_task', 'module', '*',
                                    option)

    return render_template("task/task/edit.html", p=p)
コード例 #14
0
ファイル: delete.py プロジェクト: unkyulee/elastic-cms
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)
コード例 #15
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)
コード例 #16
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)
コード例 #17
0
ファイル: delete.py プロジェクト: unkyulee/elastic-cms
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)
コード例 #18
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)
コード例 #19
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)
コード例 #20
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))

    # load task
    p['task'] = es.get(p['host'], 'core_task', 'task',
                       p['instance']['task_id'])

    # statistics
    query = "instance_id:{}".format(p['instance']['id'])
    p['total'] = es.count(p['host'], 'core_task', 'log', query)

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

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

    return render_template("task/status/default.html", p=p)
コード例 #21
0
ファイル: edit.py プロジェクト: unkyulee/elastic-cms
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)
コード例 #22
0
ファイル: People.py プロジェクト: unkyulee/elastic-cms
def authenticate(p, username, password):
    h = app.config.get("HOST")
    i = 'people'
    t = 'post'
    # get people
    people = es.get(h, i, t, username)
    if people:
        password = hashlib.sha512(password).hexdigest()
        # check password match
        if people['password'] == password:
            return True

    return False
コード例 #23
0
def get(p):
    # get data source list
    query = 'navigation_id:{}'.format(p['navigation']['id'])
    option = 'size=10000'
    p['ds_list'] = es.list(p['host'], 'core_data', 'datasource', query, option)

    p['ds'] = {}
    if tools.get('id'):
        p['ds'] = es.get(p['host'], 'core_data', 'datasource', tools.get('id'))
    if not p['ds'] and len(p['ds_list']):
        p['ds'] = p['ds_list'][0]

    return render_template("dataservice/default.html", p=p)
コード例 #24
0
ファイル: delete.py プロジェクト: unkyulee/elastic-cms
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)
コード例 #25
0
ファイル: log.py プロジェクト: unkyulee/elastic-cms
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)
コード例 #26
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))

    if request.method == "POST":
        es.update(
            p['host'], 'core_task', 'action', tools.get('action_id'), {
                'task_id': tools.get('task_id'),
                'module_id': tools.get('module_id'),
                'enabled': tools.get('enabled'),
                'stop': tools.get('stop'),
                'order_key': int(tools.get('order_key')),
                'name': tools.get('name'),
                'description': tools.get('description'),
                'connection': tools.get('connection'),
                'query': tools.get('query')
            })
        es.flush(p['host'], 'core_task')

        return tools.redirect(request.referrer)

    # load module
    p['action']['module'] = es.get(p['host'], 'core_task', 'module',
                                   p['action']['module_id'])

    # load task
    p['task'] = es.get(p['host'], 'core_task', 'task', tools.get('task_id'))

    # task module list
    option = 'size=10000&sort=description:asc'
    p['task_module_list'] = es.list(p['host'], 'core_task', 'module', '*',
                                    option)

    return render_template("task/action/edit.html", p=p)
コード例 #27
0
ファイル: delete.py プロジェクト: unkyulee/elastic-cms
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)
コード例 #28
0
ファイル: edit.py プロジェクト: unkyulee/elastic-cms
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)
コード例 #29
0
ファイル: edit.py プロジェクト: unkyulee/elastic-cms
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)
コード例 #30
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)