Exemplo n.º 1
0
def sync_permissions():
    for name, title in Permission.PERMISSIONS:
        permission = Permission.query.filter_by(name=name).first()
        if permission is None:
            p = Permission()
            p.name = name
            p.title = title
            db.session.add(p)
            db.session.commit()
Exemplo n.º 2
0
def sync_permissions():
    for name, title in Permission.PERMISSIONS:
        permission = Permission.query.filter_by(name=name).first()
        if permission is None:
            p = Permission()
            p.name = name
            p.title = title
            db.session.add(p)
            db.session.commit()
Exemplo n.º 3
0
def permission_create():
    form = OpsPermission()
    if form.validate_on_submit():
        permission = Permission()
        for field in form:
            if field.name not in ("csrf_token", "submit"):
                permission.__setattr__(field.name, field.data)
            permission.create = datetime.today()
        return redirect(url_for(".permission_index"))
    return render_template("user_control/permission_create.html", form=form)
Exemplo n.º 4
0
def s_users_json():
    columns = list()
    columns.append(ColumnDT('id', filter=_default_value))
    columns.append(ColumnDT('full_name', filter=_default_value))
    columns.append(ColumnDT('email', filter=_default_value))
    columns.append(ColumnDT('login', filter=_default_value))
    columns.append(ColumnDT('mobile_phone', filter=_default_value))
    columns.append(ColumnDT('inner_phone', filter=_default_value))
    columns.append(ColumnDT('status', filter=_status))

    query = db.session.query(User)
    rowTable = DataTables(request, User, query, columns)
    json_result = rowTable.output_result()

    current_user = auth.service.get_user()
    disabled = ''
    if not current_user.is_admin and ('set_permissions' not in current_user.get_permissions()):
        disabled = 'disabled'

    for row in json_result['aaData']:
        row_id = row['0']
        row['1'] = "<a href='"+url_for('user.profile')+"/"+row_id+"'>"+row['1']+"</a>"
        last_col = len(columns) - 1

        # Permission
        last_col += 1
        per_columns = str(last_col)
        per_options = ""
        permissions = Permission.get_all()
        set_per = User.get_user_permissions_id(row_id)
        for per in permissions:
            sel = ''
            sel = 'selected' if per.id in set_per else ''
            per_options += "<option value='"+str(per.id)+"' "+sel+">"+per.title+"</option>"
        per_html = """
          <select onchange="change_user_per("""+row_id+""", this)" class="selectpicker" multiple data-selected-text-format="count>1" data-width="170px" """+disabled+""">
            """+per_options+"""
          </select>
          <script type="text/javascript">$('.selectpicker').selectpicker({style: 'btn-default',size: 5});</script>
          """
        row[per_columns] = per_html

        # Roles
        last_col += 1
        roles_columns = str(last_col)
        roles = Role.get_all()
        role_options = ''
        sel_role = User.get_user_role_id(row_id)
        for role in roles:
            sel = ''
            sel = 'selected' if role.id == sel_role else ''
            role_options += "<option value='"+str(role.id)+"/"+row_id+"' "+sel+">"+role.name+"</option>"
        sel = ''
        sel = 'selected' if 0 == sel_role else ''
        role_options += "<option value='0/"+row_id+"' "+sel+">admin</option>"
        role_html = """
          <select onchange="change_user_role(this.value)" class="selectpicker" data-width="110px" """+disabled+""">
            """+role_options+"""
          </select>
          <script type="text/javascript">$('.selectpicker').selectpicker({style: 'btn-default',size: 5});</script>
          """
        row[roles_columns] = role_html

        # Manage
        last_col += 1
        last_columns = str(last_col)
        manage_html = """
            <a href="javascript: user.activate({0})">
                <span class="glyphicon glyphicon-ok" aria-hidden="true"></span>
            </a>
            <a href="{1}">
                <span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>
            </a>
            <a href="javascript: user.delete({0})">
                <span class="glyphicon glyphicon-remove" aria-hidden="true"></span>
            </a>
        """.format(
            row_id,
            url_for('admin.edit_user', id=row_id)
        )
        row[last_columns] = manage_html

    return jsonify(**json_result)