Merge branch 'dvadmin-liqianglog' of https://gitee.com/liqianglog/django-vue-admin into dvadmin-dev

# Conflicts:
#	dvadmin-backend/apps/vadmin/op_drf/middleware.py
pull/12/MERGE
李强 2021-03-31 12:27:22 +08:00
commit 688de0dd8a
9 changed files with 26 additions and 19 deletions

View File

@ -4,10 +4,10 @@ from django.contrib.auth.models import UserManager, AbstractUser
from django.core.cache import cache
from django.db.models import IntegerField, ForeignKey, CharField, TextField, ManyToManyField, CASCADE
from ...op_drf.fields import CreateDateTimeField, UpdateDateTimeField
from ...op_drf.models import CoreModel
class UserProfile(AbstractUser):
class UserProfile(AbstractUser, CoreModel):
USER_TYPE_CHOICES = (
(0, "后台用户"),
(1, "前台用户"),
@ -25,9 +25,6 @@ class UserProfile(AbstractUser):
post = ManyToManyField(to='Post', verbose_name='关联岗位', db_constraint=False)
role = ManyToManyField(to='Role', verbose_name='关联角色', db_constraint=False)
dept = ForeignKey(to='Dept', verbose_name='归属部门', on_delete=CASCADE, db_constraint=False, null=True, blank=True)
dept_belong_id = CharField(max_length=64, verbose_name="数据归属部门", null=True, blank=True)
create_datetime = CreateDateTimeField()
update_datetime = UpdateDateTimeField()
@property
def get_user_interface_dict(self):
@ -52,6 +49,7 @@ class UserProfile(AbstractUser):
:return:
"""
return cache.delete(f'permission_interface_dict_{self.username}')
class Meta:
verbose_name = '用户管理'
verbose_name_plural = verbose_name

View File

@ -48,7 +48,10 @@ class GetRouters(APIView):
return dict
def get(self, request, format=None):
menus = Menu.objects.filter(role__userprofile=request.user) \
kwargs = {}
if not request.user.is_superuser:
kwargs['role__userprofile'] = request.user
menus = Menu.objects.filter(**kwargs) \
.exclude(menuType='2').values('id', 'name', 'web_path', 'visible', 'status', 'isFrame', 'component_path',
'icon', 'parentId', 'orderNum', 'isCache').distinct()
data = []
@ -359,7 +362,7 @@ class UserProfileModelViewSet(CustomModelViewSet):
:return:
"""
instance = self.queryset.get(id=request.user.id)
instance.mobile = request.data.get('newPassword', None)
instance.password = request.data.get('newPassword', None)
if not authenticate(username=request.user.username, password=request.data.get('oldPassword', None)):
return ErrorResponse(msg='旧密码不正确!')
instance.set_password(request.data.get('newPassword'))

View File

@ -33,8 +33,8 @@
-- ----------------------------
-- Records of permission_userprofile
-- ----------------------------
INSERT INTO `permission_userprofile` (id, password, last_login, is_superuser, first_name, last_name, is_staff, is_active, date_joined, username, secret, email, mobile, avatar, name, gender, remark, user_type, create_datetime, update_datetime, dept_id, dept_belong_id) VALUES (1, 'pbkdf2_sha256$150000$OjTMSXJgkzrE$jEQCjWbIbXwpN4k2z0o8Yvou1UQGuoJALyL/kGDZFd4=', '2021-02-27 06:20:28.214775', 1, '', '', 1, 1, '2021-02-27 06:20:09.188689', 'admin', '3704adf3-380f-4c27-a8da-60420e8cb4ab', 'admin@qq.com', NULL, NULL, '管理员', '2', '1', 2, '2021-02-27 06:20:09.263192', '2021-02-27 09:14:30.009998', 8, 1);
INSERT INTO `permission_userprofile` (id, password, last_login, is_superuser, first_name, last_name, is_staff, is_active, date_joined, username, secret, email, mobile, avatar, name, gender, remark, user_type, create_datetime, update_datetime, dept_id, dept_belong_id) VALUES (2, 'pbkdf2_sha256$150000$5Z9LSi7LpNms$xVguE/dOEpI4D95LjSaKm0xzG7vNSopUolANr8f/6/E=', NULL, 0, '', '', 0, 1, '2021-03-03 15:38:27.009893', 'dvadmin', 'b4c5d79a-f01c-4244-92f8-b5288eca1d50', NULL, NULL, NULL, '普通用户', '2', NULL, 0, '2021-03-03 15:38:27.010771', '2021-03-03 15:38:27.086069', 8, 1);
INSERT INTO `permission_userprofile` (id, password, last_login, is_superuser, first_name, last_name, is_staff, is_active, date_joined, username, secret, email, mobile, avatar, name, gender, remark, user_type, create_datetime, update_datetime, dept_id, dept_belong_id, creator_id) VALUES (1, 'pbkdf2_sha256$150000$OjTMSXJgkzrE$jEQCjWbIbXwpN4k2z0o8Yvou1UQGuoJALyL/kGDZFd4=', '2021-02-27 06:20:28.214775', 1, '', '', 1, 1, '2021-02-27 06:20:09.188689', 'admin', '3704adf3-380f-4c27-a8da-60420e8cb4ab', 'admin@qq.com', NULL, NULL, '管理员', '2', '1', 2, '2021-02-27 06:20:09.263192', '2021-02-27 09:14:30.009998', 1, 1, 1);
INSERT INTO `permission_userprofile` (id, password, last_login, is_superuser, first_name, last_name, is_staff, is_active, date_joined, username, secret, email, mobile, avatar, name, gender, remark, user_type, create_datetime, update_datetime, dept_id, dept_belong_id, creator_id) VALUES (2, 'pbkdf2_sha256$150000$5Z9LSi7LpNms$xVguE/dOEpI4D95LjSaKm0xzG7vNSopUolANr8f/6/E=', NULL, 0, '', '', 0, 1, '2021-03-03 15:38:27.009893', 'dvadmin', 'b4c5d79a-f01c-4244-92f8-b5288eca1d50', NULL, NULL, NULL, '普通用户', '2', NULL, 0, '2021-03-03 15:38:27.010771', '2021-03-03 15:38:27.086069', 1, 1, 1);
-- ----------------------------
-- Table structure for permission_userprofile_post
-- ----------------------------

View File

@ -200,7 +200,7 @@ class MessagePushModelViewSet(CustomModelViewSet):
serializer_class = MessagePushSerializer
create_serializer_class = MessagePushCreateUpdateSerializer
update_serializer_class = MessagePushCreateUpdateSerializer
extra_filter_backends = [DataLevelPermissionsFilter]
# extra_filter_backends = [DataLevelPermissionsFilter]
update_extra_permission_classes = (CommonPermission,)
destroy_extra_permission_classes = (CommonPermission,)
create_extra_permission_classes = (CommonPermission,)

View File

@ -12,8 +12,8 @@ from django.utils.translation import ugettext as _
from rest_framework import exceptions
from rest_framework_jwt.utils import jwt_decode_handler
from .decorators import exceptionHandler
from .jwt_util import jwt_get_session_id
from ..permission.models.users import UserProfile
logger = logging.getLogger(__name__)
User = get_user_model()
@ -38,6 +38,8 @@ class OpAuthJwtAuthentication(object):
raise exceptions.AuthenticationFailed(msg)
except jwt.InvalidTokenError:
raise exceptions.AuthenticationFailed()
except UserProfile.DoesNotExist:
raise exceptions.AuthenticationFailed()
username = payload.get('username', None)
if not username:

View File

@ -14,7 +14,7 @@
<div class="right-menu-item hover-effect">
<router-link to="/user/msg">
<i class="el-icon-message-solid badge-item-icon"></i>
<el-badge :value="count" :max="99" style="margin-left: -4px;" v-if="count">
<el-badge :value="unread_msg_count" :max="99" style="margin-left: -4px;" v-if="unread_msg_count">
</el-badge>
</router-link>
</div>
@ -81,11 +81,11 @@ export default {
},
data() {
return {
count: store.getters.unread_msg_count,
count: store.unread_msg_count,
};
},
computed: {
...mapGetters(["sidebar", "avatar", "device"]),
...mapGetters(["sidebar", "avatar", "device", "unread_msg_count"]),
setting: {
get() {
return this.$store.state.settings.showSettings;

View File

@ -7,7 +7,8 @@ const user = {
name: '',
avatar: '',
roles: [],
permissions: []
permissions: [],
unread_msg_count: 0
},
mutations: {

View File

@ -161,7 +161,7 @@
<i class="el-icon-arrow-down el-icon--right"></i>
</span>
<el-dropdown-menu slot="dropdown">
<el-dropdown-item v-for="role in scope.row.role">{{role.roleName}}</el-dropdown-item>
<el-dropdown-item v-for="(role,index) in scope.row.role" :key="index">{{role.roleName}}</el-dropdown-item>
</el-dropdown-menu>
</el-dropdown>
</template>
@ -648,6 +648,7 @@
this.$refs['form'].validate(valid => {
if (valid) {
if (this.form.id != undefined) {
this.form.creator = undefined
updateUser(this.form).then(response => {
this.msgSuccess('修改成功')
this.open = false

View File

@ -103,9 +103,11 @@
//
if (this.badgeType === "danger") {
updateIsRead(this.showingMsgItem).then(response => {
store.getters.unread_msg_count
this.open = false;
this.getList();
if(response.code === 200){
store.commit('SET_UNREAD_MSG_COUNT', store.getters.unread_msg_count - 1);
this.open = false;
this.getList();
}
});
}
}